【问题标题】:Retrieve all videos added to all playlists by YouTube user检索 YouTube 用户添加到所有播放列表的所有视频
【发布时间】:2012-01-30 02:09:14
【问题描述】:

我想使用 YouTube 数据 API 的方式碰壁了。我有一个用户帐户试图充当“聚合器”,根据类别将来自其他各种频道的视频添加到大约 15 个播放列表之一中。我的问题是,我无法将所有这些视频放到一个提要中,因为它们属于不同的 YouTube 用户。我想将它们全部放入一个列表中,这样我就可以按最新和最流行的方式对该主列表进行排序,以填充我的网络应用程序中的不同视图。

如何获取用户添加到其播放列表中的所有视频的列表?

YouTube 必须跟踪此类内容,因为如果您进入 `http://www.youtube.com/' 上任何用户页面的“Feed”部分,它会为您提供一个活动流,其中包括添加到播放列表。

明确地说,我不想获取仅由该用户上传的视频列表,因此 http://gdata.../<user>/uploads 将不起作用。由于有许多不同的播放列表,http://gdata.../<user>/playlists 也不起作用,因为我每次要检查新视频时都需要发出大约 15 个请求。

似乎无法检索用户添加到其所有播放列表中的所有视频的列表。有人能想出一种我可能忽略的方法吗?

【问题讨论】:

    标签: api android-activity youtube feed playlists


    【解决方案1】:

    类似这样的东西,用于从播放列表中检索 youtube 链接。它仍然需要改进。

    import urllib2
    import xml.etree.ElementTree as et
    import re
    import os
    
    more = 1
    id_playlist = raw_input("Enter youtube playlist id: ")
    number_of_iteration  = input("How much video links: ")
    number = number_of_iteration / 50
    number2 = number_of_iteration % 50
    if (number2 != 0):
         number3 = number + 1
    else:
         number3 = number
    start_index = 1
    
    while more <= number3:
         #reading youtube playlist page
         if (more != 1):
              start_index+=50
    
         str_start_index = str(start_index)
         req = urllib2.Request('http://gdata.youtube.com/feeds/api/playlists/'+ id_playlist     + '?v=2&&start-index=' + str_start_index + '&max-results=50')
         response = urllib2.urlopen(req)
         the_page = response.read()
    
         #writing page in .xml
         dat = open("web_content.xml","w")
         dat.write(the_page)
         dat.close()
    
         #searching page for links
         tree = et.parse('web_content.xml')
         all_links = tree.findall('*/{http://www.w3.org/2005/Atom}link[@rel="alternate"]')
    
         #writing links + attributes to .txt
         if (more == 1):
              till_links = 50
         else:
              till_links = start_index + 50
    
         str_till_links = str(till_links)
         dat2 = open ("links-"+ str_start_index +"to"+ str_till_links +".txt","w")
         for links in all_links:
              str1 = (str(links.attrib) + "\n")
              dat2.write(str1)     
         dat2.close()
    
         #getting only links
         f = open ("links-"+ str_start_index +"to"+ str_till_links +".txt","r")
         link_all = f.read()
         new_string = link_all.replace("{'href': '","")
         new_string2 = new_string.replace("', 'type': 'text/html', 'rel': 'alternate'}","")
         f.close()
    
         #writing links to .txt
         f = open ("links-"+ str_start_index +"to"+ str_till_links +".txt","w")
         f.write(new_string2)
         f.close()
    
         more+=1
    
    os.remove('web_content.xml')
    print "Finished!"
    

    【讨论】:

      猜你喜欢
      • 2013-09-19
      • 1970-01-01
      • 2013-03-18
      • 1970-01-01
      • 2016-11-19
      • 1970-01-01
      • 2019-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多