Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robin Nicholl 137 posts 277 karma points
    Jan 19, 2012 @ 13:23
    Robin Nicholl
    0

    YouTube feed

    I'm trying to list the videos in a client's YouTube page. I got this code elsewhere in this forum:

    <xsl:variable name="youTubeFeed" select="umbraco.library:GetXmlDocumentByUrl('https://gdata.youtube.com/feeds/api/users/[userpage]/uploads', number($cacheRate))" />
    <xsl:template match="/">
      
          <xsl:for-each select="$youTubeFeed/*[local-name()='feed']/*[local-name()='entry']">
              <div style="margin-bottom: 10px;">
                  <h4><xsl:value-of select="*[local-name()='title']" disable-output-escaping="yes" /></h4>
                  <p>Result: <xsl:value-of select="*[local-name()='media:group']/*['media:description']" disable-output-escaping="yes" /></p>
              </div>
          </xsl:for-each>
      
      </xsl:template>

    This lists all the titles, but gives me no results for media:group/media:description. If I change that part to:

    <xsl:value-of select="*[local-name()='group']/*['description']" disable-output-escaping="yes" />

    ... it gives me the word 'Music' which is the content of the first node under media:group – media:category. What I actually want to get is the url attribute of media:group/media:player.

    Anyone know how to do this?

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 14:00
    Rodion Novoselov
    0

    Hi. Could you write here how the incoming feed xml fragment looks like?

  • Robin Nicholl 137 posts 277 karma points
    Jan 19, 2012 @ 14:08
    Robin Nicholl
    0

    It looks like this (there is obviously more than one <<entry> node):

    <?xml version='1.0' encoding='UTF-8'?>
    <feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'>
        <id>http://gdata.youtube.com/feeds/api/users/thestationsessions/uploads</id>;
        <updated>2012-01-16T20:56:33.815Z</updated>
        <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
        <title type='text'>Uploads by thestationsessions</title>
        <logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo>;
        <link rel='related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/thestationsessions'/>
        <link rel='alternate' type='text/html' href='https://www.youtube.com/profile?user=thestationsessions#p/u'/>
        <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/thestationsessions/uploads'/>
        <link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/thestationsessions/uploads/batch'/>
        <link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/thestationsessions/uploads?start-index=1&amp;max-results=25'/>
        <link rel='next' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/thestationsessions/uploads?start-index=26&amp;max-results=25'/>
        <author>
            <name>thestationsessions</name>
            <uri>https://gdata.youtube.com/feeds/api/users/thestationsessions</uri>;
        </author>
        <generator version='2.1' uri='http://gdata.youtube.com'>YouTube data API</generator>
        <openSearch:totalResults>138</openSearch:totalResults>
        <openSearch:startIndex>1</openSearch:startIndex>
        <openSearch:itemsPerPage>25</openSearch:itemsPerPage>
        <entry>
            <id>http://gdata.youtube.com/feeds/api/videos/uNIsz0gdcJA</id>;
            <published>2011-12-18T03:25:07.000Z</published>
            <updated>2012-01-14T03:00:48.000Z</updated>
            <category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
            <category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Music' label='Music'/>
            <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Iman'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Acoustic'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Live'/>     
            <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Music'/>
            <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Station Sessions'/>
            <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Guitar'/>
            <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='St. Pancras'/>
            <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Train'/>
            <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Station'/>
            <category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='Train Station'/>
            <title type='text'>Iman - All I Am Thinking Of</title>
            <content type='text'>Iman performing  'All I Am Thinking Of' live at The Station Sessions.  
    
                As part of the special #SecretSeason supporting Shelter, Iman gave us a fantastic performance of her latest track All I Am Thinking Of.
    
                For more information please visit:
    
                www.stationsessions.com
                www.facebook.com/stationsessions
                www.twitter.com/stationsessions
                www.youtube.com/thestationsessions
    
                Station Sessions is a Syllabus Production
            </content>
            <link rel='alternate' type='text/html' href='https://www.youtube.com/watch?v=uNIsz0gdcJA&amp;feature=youtube_gdata'/>
            <link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/uNIsz0gdcJA/responses'/>
            <link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/videos/uNIsz0gdcJA/related'/>
            <link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='https://m.youtube.com/details?v=uNIsz0gdcJA'/>
            <link rel='self' type='application/atom+xml' href='https://gdata.youtube.com/feeds/api/users/thestationsessions/uploads/uNIsz0gdcJA'/>
            <author>
                <name>TheStationSessions</name>
                <uri>https://gdata.youtube.com/feeds/api/users/thestationsessions</uri>;
            </author>
            <gd:comments>
                <gd:feedLink rel='http://gdata.youtube.com/schemas/2007#comments' href='https://gdata.youtube.com/feeds/api/videos/uNIsz0gdcJA/comments' countHint='0'/>
            </gd:comments>
            <yt:hd/>
            <media:group>
                <media:category label='Music' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Music</media:category>
                <media:content url='https://www.youtube.com/v/uNIsz0gdcJA?version=3&amp;f=user_uploads&amp;app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='211' yt:format='5'/>
                <media:content url='rtsp://v4.cache5.c.youtube.com/CigLENy73wIaHwmQcB1IzyzSuBMYDSANFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='211' yt:format='1'/>
                <media:content url='rtsp://v6.cache6.c.youtube.com/CigLENy73wIaHwmQcB1IzyzSuBMYESARFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='211' yt:format='6'/>
                <media:description type='plain'>Iman performing  'All I Am Thinking Of' live at The Station Sessions.  
    
                    As part of the special #SecretSeason supporting Shelter, Iman gave us a fantastic performance of her latest track All I Am Thinking Of.
    
                    For more information please visit:
    
                    www.stationsessions.com
                    www.facebook.com/stationsessions
                    www.twitter.com/stationsessions
                    www.youtube.com/thestationsessions
    
                    Station Sessions is a Syllabus Production
                </media:description>
                <media:keywords>Iman, Acoustic, Live, Music, Station Sessions, Guitar, St. Pancras, Train, Station, Train Station</media:keywords>
                <media:player url='https://www.youtube.com/watch?v=uNIsz0gdcJA&amp;feature=youtube_gdata_player'/>
                <media:thumbnail url='http://i.ytimg.com/vi/uNIsz0gdcJA/0.jpg' height='360' width='480' time='00:01:45.500'/>
                <media:thumbnail url='http://i.ytimg.com/vi/uNIsz0gdcJA/1.jpg' height='90' width='120' time='00:00:52.750'/>
                <media:thumbnail url='http://i.ytimg.com/vi/uNIsz0gdcJA/2.jpg' height='90' width='120' time='00:01:45.500'/>
                <media:thumbnail url='http://i.ytimg.com/vi/uNIsz0gdcJA/3.jpg' height='90' width='120' time='00:02:38.250'/>
                <media:title type='plain'>Iman - All I Am Thinking Of</media:title><yt:duration seconds='211'/>
            </media:group>
            <gd:rating average='3.6666667' max='5' min='1' numRaters='6' rel='http://schemas.google.com/g/2005#overall'/>
            <yt:statistics favoriteCount='1' viewCount='302'/>
        </entry>
    </feed>

    The bits I'm actually interested in are media:group/media:player (the url attribute) and one of the media:group/media:thumbnail url attributes (although Idon't know how to pluck jus one from the 4 that are present).

    Thanks

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 14:14
    Rodion Novoselov
    0

    Well. You just need to write it as:

    ..bla-bla..   *[local-name()='group']/*[local-name() = 'description'] ..bla-bla..
  • Robin Nicholl 137 posts 277 karma points
    Jan 19, 2012 @ 14:20
    Robin Nicholl
    0

    Thanks (I'd missed the second local-name()= !) – but do you know how I get the attribute of media:player?

    <media:player url='https://www.youtube.com/watch?v=uNIsz0gdcJA&amp;feature=youtube_gdata_player'/>
  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 14:27
    Rodion Novoselov
    0

    The same way. For example:

    <xsl:variable name="url" select="*[local-name='group']/*[local-name() = 'player']/@url"/>

    local-name() just gets the name of an element without the namespace part.

  • Robin Nicholl 137 posts 277 karma points
    Jan 19, 2012 @ 14:55
    Robin Nicholl
    0

    That works, thanks!

    Any idea how I'd get just the second of the media:thumbnail nodes?

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 15:57
    Rodion Novoselov
    0

    The second one can be selected with the XPath position() function:

    <xsl:variable name="thumbs" select="*[local-name()='group']/*[local-name()='thumbnail']"/>
    <xsl:variable name="thumb2" select="$thumbs[position() = 2]"/>
  • Robin Nicholl 137 posts 277 karma points
    Jan 19, 2012 @ 16:40
    Robin Nicholl
    0

    Thanks, extremely helpful!

Please Sign in or register to post replies

Write your reply to:

Draft