use gdata atom feeds

This commit is contained in:
j 2008-10-07 23:07:49 +02:00
parent b02bac2926
commit d523862c9d
3 changed files with 20 additions and 24 deletions

2
README
View file

@ -5,7 +5,7 @@ Depends:
python-oxutils
python-beautifulsoup (http://www.crummy.com/software/BeautifulSoup/)
python-feedparser (http://www.feedparser.org/)
(there seam to be some issues if not using the one from ubuntu/debian)
Test:
nosetests --with-doctest oxweb

View file

@ -25,13 +25,6 @@ def getVideoKey(youtubeId):
else:
return False
def getVideoKeyLegacyAPI(videoId):
url = 'http://www.youtube.com/api2_rest?method=youtube.videos.get_video_token&video_id=' + youtubeId
data = getUrl(url)
xml = ET.fromstring(data)
youtubeKey = xml.find('t').text
return youtubeKey
def getVideoUrl(youtubeId, format='mp4'):
youtubeKey = getVideoKey(youtubeId)
if format == 'mp4':
@ -41,47 +34,50 @@ def getVideoUrl(youtubeId, format='mp4'):
url = "http://youtube.com/get_video.php?video_id=%s&t=%s" % (youtubeId, youtubeKey)
return url
'''
def getMovieInfo(youtubeId):
url = "http://gdata.youtube.com/feeds/api/videos/%s " % youtubeId
def getMovieInfo(youtubeId, video_url_base=None):
url = "http://gdata.youtube.com/feeds/api/videos/%s" % youtubeId
data = getUrl(url)
fd = feedparser.parse(data)
return getInfoFromAtom(fd.entries[0])
return getInfoFromAtom(fd.entries[0], video_url_base)
def getInfoFromAtom(entry):
def getInfoFromAtom(entry, video_url_base=None):
info = dict()
info['title'] = entry['title']
info['description'] = entry['description']
info['author'] = entry['author']
info['published'] = entry['published_parsed']
#info['published'] = entry['published_parsed']
info['keywords'] = entry['media_keywords'].split(', ')
info['url'] = entry['links'][0]['href']
info['id'] = findString(info['url'], "/watch?v=")
info['thumbnail'] = "http://img.youtube.com/vi/%s/0.jpg" % info['id']
if video_url_base:
info['flv'] = "%s/%s.%s" % (video_url_base, info['id'], 'flv')
info['mp4'] = "%s/%s.%s" % (video_url_base, info['id'], 'mp4')
else:
info['flv'] = getVideoUrl(info['id'], 'flv')
info['mp4'] = getVideoUrl(info['id'], 'mp4')
info['embed'] = '<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/%s&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/%s&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>' % (info['id'], info['id'])
return info
def find(query, max_results=10, offset=1, orderBy='relevance'):
def find(query, max_results=10, offset=1, orderBy='relevance', video_url_base=None):
query = quote(query)
url = "http://gdata.youtube.com/feeds/api/videos?vq=%s&orderby=%s&start-index=%s&max-results=%s"%(query, orderBy, offset, max_results)
data = getUrl(url)
url = "http://gdata.youtube.com/feeds/api/videos?vq=%s&orderby=%s&start-index=%s&max-results=%s" % (query, orderBy, offset, max_results)
data = getUrlUnicode(url)
fd = feedparser.parse(data)
videos = []
for entry in fd.entries:
v = getInfoFromAtom(entry)
v = getInfoFromAtom(entry, video_url_base)
videos.append(v)
if len(videos) >= max_results:
return videos
return videos
'''
'''
def find(query, max_results=10, offset=1, orderBy='relevance', video_url_base=None):
url = "http://youtube.com/results?search_query=%s&search=Search" % quote(query)
data = getUrlUnicode(url)
regx = re.compile(''' <a href="/watch.v=(.*?)" title="(.*?)" ''')
regx = re.compile('''<a href="/watch\?v=(\w*?)" ><img src="(.*?)" class="vimg120" title="(.*?)" alt="video">''')
regx = re.compile(' <a href="/watch.v=(.*?)" title="(.*?)" ')
regx = re.compile('<a href="/watch\?v=(\w*?)" ><img src="(.*?)" class="vimg120" title="(.*?)" alt="video">')
id_title = regx.findall(data)
data_flat = data.replace('\n', ' ')
videos = {}
@ -102,4 +98,5 @@ def find(query, max_results=10, offset=1, orderBy='relevance', video_url_base=No
if len(videos) >= max_results:
return videos.values()
return videos.values()
'''

View file

@ -18,7 +18,6 @@ setup(
zip_safe=False,
install_requires=[
'oxlib',
'feedparser',
'beautifulsoup',
],
keywords = [