add ox.web.youtube.subtitles
This commit is contained in:
parent
d63118827b
commit
adf777ce7c
1 changed files with 10 additions and 4 deletions
|
@ -104,14 +104,20 @@ def info(id, timeout=cache_timeout):
|
|||
info['license'] = match[0].strip()
|
||||
info['license'] = re.sub('<.+?>', '', info['license']).strip()
|
||||
|
||||
subs = subtitles(id, timeout)
|
||||
if subs:
|
||||
info['subtitles'] = subs
|
||||
return info
|
||||
|
||||
def subtitles(id, timeout=cache_timeout):
|
||||
url = "http://www.youtube.com/api/timedtext?hl=en&type=list&tlangs=1&v=%s&asrs=1" % id
|
||||
data = read_url(url, timeout=timeout)
|
||||
xml = parseString(data)
|
||||
languages = [t.getAttribute('lang_code') for t in xml.getElementsByTagName('track')]
|
||||
subtitles = {}
|
||||
if languages:
|
||||
info['subtitles'] = {}
|
||||
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, timeout=timeout)
|
||||
xml = parseString(data)
|
||||
subs = []
|
||||
|
@ -128,8 +134,8 @@ def info(id, timeout=cache_timeout):
|
|||
'out': end,
|
||||
'value': ox.decode_html(text),
|
||||
})
|
||||
info['subtitles'][language] = subs
|
||||
return info
|
||||
subtitles[language] = subs
|
||||
return subtitles
|
||||
|
||||
def videos(id, format=''):
|
||||
stream_type = {
|
||||
|
|
Loading…
Reference in a new issue