add timeout argument to ox.web.youtube.info
This commit is contained in:
parent
cdc56bc63f
commit
d2a6511a95
1 changed files with 5 additions and 5 deletions
|
@ -59,14 +59,14 @@ def find(query, max_results=10, offset=1, orderBy='relevance'):
|
||||||
return videos
|
return videos
|
||||||
return videos
|
return videos
|
||||||
|
|
||||||
def info(id):
|
def info(id, timeout=cache_timeout):
|
||||||
info = {}
|
info = {}
|
||||||
if id.startswith('http'):
|
if id.startswith('http'):
|
||||||
id = get_id(id)
|
id = get_id(id)
|
||||||
if not id:
|
if not id:
|
||||||
return info
|
return info
|
||||||
url = "http://gdata.youtube.com/feeds/api/videos/%s?v=2" % id
|
url = "http://gdata.youtube.com/feeds/api/videos/%s?v=2" % id
|
||||||
data = read_url(url)
|
data = read_url(url, timeout=timeout)
|
||||||
xml = parseString(data)
|
xml = parseString(data)
|
||||||
info['id'] = id
|
info['id'] = id
|
||||||
info['url'] = get_url(id)
|
info['url'] = get_url(id)
|
||||||
|
@ -82,21 +82,21 @@ def info(id):
|
||||||
k = xml.getElementsByTagName('media:keywords')[0].firstChild
|
k = xml.getElementsByTagName('media:keywords')[0].firstChild
|
||||||
if k:
|
if k:
|
||||||
info['keywords'] = k.data.split(', ')
|
info['keywords'] = k.data.split(', ')
|
||||||
data = read_url(info['url'])
|
data = read_url(info['url'], timeout=timeout)
|
||||||
match = re.compile('<h4>License:</h4>(.*?)</p>', re.DOTALL).findall(data)
|
match = re.compile('<h4>License:</h4>(.*?)</p>', re.DOTALL).findall(data)
|
||||||
if match:
|
if match:
|
||||||
info['license'] = match[0].strip()
|
info['license'] = match[0].strip()
|
||||||
info['license'] = re.sub('<.+?>', '', info['license']).strip()
|
info['license'] = re.sub('<.+?>', '', info['license']).strip()
|
||||||
|
|
||||||
url = "http://www.youtube.com/api/timedtext?hl=en&type=list&tlangs=1&v=%s&asrs=1" % id
|
url = "http://www.youtube.com/api/timedtext?hl=en&type=list&tlangs=1&v=%s&asrs=1" % id
|
||||||
data = read_url(url)
|
data = read_url(url, timeout=timeout)
|
||||||
xml = parseString(data)
|
xml = parseString(data)
|
||||||
languages = [t.getAttribute('lang_code') for t in xml.getElementsByTagName('track')]
|
languages = [t.getAttribute('lang_code') for t in xml.getElementsByTagName('track')]
|
||||||
if languages:
|
if languages:
|
||||||
info['subtitles'] = {}
|
info['subtitles'] = {}
|
||||||
for language in languages:
|
for language in languages:
|
||||||
url = "http://www.youtube.com/api/timedtext?hl=en&v=%s&type=track&lang=%s&name&kind"%(id, language)
|
url = "http://www.youtube.com/api/timedtext?hl=en&v=%s&type=track&lang=%s&name&kind"%(id, language)
|
||||||
data = read_url(url)
|
data = read_url(url, timeout=timeout)
|
||||||
xml = parseString(data)
|
xml = parseString(data)
|
||||||
subs = []
|
subs = []
|
||||||
for t in xml.getElementsByTagName('text'):
|
for t in xml.getElementsByTagName('text'):
|
||||||
|
|
Loading…
Reference in a new issue