add timeout

This commit is contained in:
j 2010-10-19 16:08:21 +02:00
parent 2da500d26e
commit 2b5c0b7108

View file

@ -7,14 +7,14 @@ import re
from urlparse import parse_qs from urlparse import parse_qs
import feedparser import feedparser
from ox.cache import readUrl, readUrlUnicode from ox.cache import readUrl, readUrlUnicode, cache_timeout
from ox import findString, findRe from ox import findString, findRe
def getVideoKey(youtubeId): def getVideoKey(youtubeId, timeout=cache_timeout):
for el_type in ['&el=embedded', '&el=detailpage', '&el=vevo', '']: for el_type in ['&el=embedded', '&el=detailpage', '&el=vevo', '']:
video_info_url = 'http://www.youtube.com/get_video_info?&video_id=%s%s&ps=default&eurl=&gl=US&hl=en' % (youtubeId, el_type) video_info_url = 'http://www.youtube.com/get_video_info?&video_id=%s%s&ps=default&eurl=&gl=US&hl=en' % (youtubeId, el_type)
try: try:
data = readUrl(video_info_url) data = readUrl(video_info_url, timeout=timeout)
video_info = parse_qs(data) video_info = parse_qs(data)
if 'token' in video_info: if 'token' in video_info:
return video_info['token'][0] return video_info['token'][0]
@ -22,8 +22,8 @@ def getVideoKey(youtubeId):
return return
return False return False
def getVideoUrl(youtubeId, format='mp4'): def getVideoUrl(youtubeId, format='mp4', timeout=cache_timeout):
youtubeKey = getVideoKey(youtubeId) youtubeKey = getVideoKey(youtubeId, timeout=timeout)
fmt = None fmt = None
if format == 'webm': if format == 'webm':