mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-05 00:51:29 +00:00
GametrailersIE: support multipart videos
Use xml.etree.ElementTree instead of re when possible
This commit is contained in:
parent
45ff2d51d0
commit
41897817cc
1 changed files with 30 additions and 35 deletions
|
@ -1,4 +1,5 @@
|
||||||
import re
|
import re
|
||||||
|
import xml.etree.ElementTree
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
@ -11,7 +12,7 @@ class GametrailersIE(InfoExtractor):
|
||||||
_VALID_URL = r'http://www.gametrailers.com/(?P<type>videos|reviews|full-episodes)/(?P<id>.*?)/(?P<title>.*)'
|
_VALID_URL = r'http://www.gametrailers.com/(?P<type>videos|reviews|full-episodes)/(?P<id>.*?)/(?P<title>.*)'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
u'url': u'http://www.gametrailers.com/videos/zbvr8i/mirror-s-edge-2-e3-2013--debut-trailer',
|
u'url': u'http://www.gametrailers.com/videos/zbvr8i/mirror-s-edge-2-e3-2013--debut-trailer',
|
||||||
u'file': u'zbvr8i.flv',
|
u'file': u'70e9a5d7-cf25-4a10-9104-6f3e7342ae0d.flv',
|
||||||
u'md5': u'c3edbc995ab4081976e16779bd96a878',
|
u'md5': u'c3edbc995ab4081976e16779bd96a878',
|
||||||
u'info_dict': {
|
u'info_dict': {
|
||||||
u"title": u"E3 2013: Debut Trailer"
|
u"title": u"E3 2013: Debut Trailer"
|
||||||
|
@ -24,45 +25,39 @@ class GametrailersIE(InfoExtractor):
|
||||||
if mobj is None:
|
if mobj is None:
|
||||||
raise ExtractorError(u'Invalid URL: %s' % url)
|
raise ExtractorError(u'Invalid URL: %s' % url)
|
||||||
video_id = mobj.group('id')
|
video_id = mobj.group('id')
|
||||||
video_type = mobj.group('type')
|
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
if video_type == 'full-episodes':
|
mgid = self._search_regex([r'data-video="(?P<mgid>mgid:.*?)"',
|
||||||
mgid_re = r'data-video="(?P<mgid>mgid:.*?)"'
|
r'data-contentId=\'(?P<mgid>mgid:.*?)\''],
|
||||||
else:
|
webpage, u'mgid')
|
||||||
mgid_re = r'data-contentId=\'(?P<mgid>mgid:.*?)\''
|
|
||||||
mgid = self._search_regex(mgid_re, webpage, u'mgid')
|
|
||||||
data = compat_urllib_parse.urlencode({'uri': mgid, 'acceptMethods': 'fms'})
|
|
||||||
|
|
||||||
|
data = compat_urllib_parse.urlencode({'uri': mgid, 'acceptMethods': 'fms'})
|
||||||
info_page = self._download_webpage('http://www.gametrailers.com/feeds/mrss?' + data,
|
info_page = self._download_webpage('http://www.gametrailers.com/feeds/mrss?' + data,
|
||||||
video_id, u'Downloading video info')
|
video_id, u'Downloading video info')
|
||||||
links_webpage = self._download_webpage('http://www.gametrailers.com/feeds/mediagen/?' + data,
|
doc = xml.etree.ElementTree.fromstring(info_page.encode('utf-8'))
|
||||||
|
default_thumb = doc.find('./channel/image/url').text
|
||||||
|
|
||||||
|
media_namespace = {'media': 'http://search.yahoo.com/mrss/'}
|
||||||
|
parts = [{
|
||||||
|
'title': video_doc.find('title').text,
|
||||||
|
'ext': 'flv',
|
||||||
|
'id': video_doc.find('guid').text.rpartition(':')[2],
|
||||||
|
# Videos are actually flv not mp4
|
||||||
|
'url': self._get_video_url(video_doc.find('media:group/media:content', media_namespace).attrib['url'], video_id),
|
||||||
|
# The thumbnail may not be defined, it would be ''
|
||||||
|
'thumbnail': video_doc.find('media:group/media:thumbnail', media_namespace).attrib['url'] or default_thumb,
|
||||||
|
'description': video_doc.find('description').text,
|
||||||
|
} for video_doc in doc.findall('./channel/item')]
|
||||||
|
return parts
|
||||||
|
|
||||||
|
def _get_video_url(self, mediagen_url, video_id):
|
||||||
|
if 'acceptMethods' not in mediagen_url:
|
||||||
|
mediagen_url += '&acceptMethods=fms'
|
||||||
|
links_webpage = self._download_webpage(mediagen_url,
|
||||||
video_id, u'Downloading video urls info')
|
video_id, u'Downloading video urls info')
|
||||||
|
doc = xml.etree.ElementTree.fromstring(links_webpage)
|
||||||
self.report_extraction(video_id)
|
urls = list(doc.iter('src'))
|
||||||
info_re = r'''<title><!\[CDATA\[(?P<title>.*?)\]\]></title>.*
|
if len(urls) == 0:
|
||||||
<description><!\[CDATA\[(?P<description>.*?)\]\]></description>.*
|
|
||||||
<image>.*
|
|
||||||
<url>(?P<thumb>.*?)</url>.*
|
|
||||||
</image>'''
|
|
||||||
|
|
||||||
m_info = re.search(info_re, info_page, re.VERBOSE|re.DOTALL)
|
|
||||||
if m_info is None:
|
|
||||||
raise ExtractorError(u'Unable to extract video info')
|
|
||||||
video_title = m_info.group('title')
|
|
||||||
video_description = m_info.group('description')
|
|
||||||
video_thumb = m_info.group('thumb')
|
|
||||||
|
|
||||||
m_urls = list(re.finditer(r'<src>(?P<url>.*)</src>', links_webpage))
|
|
||||||
if m_urls is None or len(m_urls) == 0:
|
|
||||||
raise ExtractorError(u'Unable to extract video url')
|
raise ExtractorError(u'Unable to extract video url')
|
||||||
# They are sorted from worst to best quality
|
# They are sorted from worst to best quality
|
||||||
video_url = m_urls[-1].group('url')
|
return urls[-1].text
|
||||||
|
|
||||||
return {'url': video_url,
|
|
||||||
'id': video_id,
|
|
||||||
'title': video_title,
|
|
||||||
# Videos are actually flv not mp4
|
|
||||||
'ext': 'flv',
|
|
||||||
'thumbnail': video_thumb,
|
|
||||||
'description': video_description,
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue