X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=youtube_dl%2Fextractor%2Fmlb.py;h=109eecefd9afffb719486256354bfe8b2fc8c6e7;hb=d1feb308116f57ceae3888db5e1b93394300f564;hp=37c72bc5357e3766819b0f86d5bc379fdf7406c4;hpb=11f75cac3db14681b306633a496e9aaae2cfc0a7;p=youtube-dl diff --git a/youtube_dl/extractor/mlb.py b/youtube_dl/extractor/mlb.py index 37c72bc53..109eecefd 100644 --- a/youtube_dl/extractor/mlb.py +++ b/youtube_dl/extractor/mlb.py @@ -6,12 +6,25 @@ from .common import InfoExtractor from ..utils import ( parse_duration, parse_iso8601, - find_xpath_attr, ) class MLBIE(InfoExtractor): - _VALID_URL = r'https?://m\.mlb\.com/(?:.*?/)?video/(?:topic/[\da-z_-]+/)?v(?Pn?\d+)' + _VALID_URL = r'''(?x) + https?:// + m(?:lb)?\.(?:[\da-z_-]+\.)?mlb\.com/ + (?: + (?: + (?:.*?/)?video/(?:topic/[\da-z_-]+/)?v| + (?: + shared/video/embed/(?:embed|m-internal-embed)\.html| + [^/]+/video/play\.jsp + )\?.*?\bcontent_id= + ) + (?Pn?\d+)| + (?P.+?) + ) + ''' _TESTS = [ { 'url': 'http://m.mlb.com/sea/video/topic/51231442/v34698933/nymsea-ackley-robs-a-home-run-with-an-amazing-catch/?c_id=sea', @@ -69,12 +82,39 @@ class MLBIE(InfoExtractor): 'thumbnail': 're:^https?://.*\.jpg$', }, }, + { + 'url': 'http://m.mlb.com/shared/video/embed/embed.html?content_id=35692085&topic_id=6479266&width=400&height=224&property=mlb', + 'only_matching': True, + }, + { + 'url': 'http://mlb.mlb.com/shared/video/embed/embed.html?content_id=36599553', + 'only_matching': True, + }, + { + 'url': 'http://mlb.mlb.com/es/video/play.jsp?content_id=36599553', + 'only_matching': True, + }, + { + 'url': 'http://m.cardinals.mlb.com/stl/video/v51175783/atlstl-piscotty-makes-great-sliding-catch-on-line/?partnerId=as_mlb_20150321_42500876&adbid=579409712979910656&adbpl=tw&adbpr=52847728', + 'only_matching': True, + }, + { + # From http://m.mlb.com/news/article/118550098/blue-jays-kevin-pillar-goes-spidey-up-the-wall-to-rob-tim-beckham-of-a-homer + 'url': 'http://mlb.mlb.com/shared/video/embed/m-internal-embed.html?content_id=75609783&property=mlb&autoplay=true&hashmode=false&siteSection=mlb/multimedia/article_118550098/article_embed&club=mlb', + 'only_matching': True, + } ] def _real_extract(self, url): mobj = re.match(self._VALID_URL, url) video_id = mobj.group('id') + if not video_id: + video_path = mobj.group('path') + webpage = self._download_webpage(url, video_path) + video_id = self._search_regex( + r'data-videoid="(\d+)"', webpage, 'video id') + detail = self._download_xml( 'http://m.mlb.com/gen/multimedia/detail/%s/%s/%s/%s.xml' % (video_id[-3], video_id[-2], video_id[-1], video_id), video_id) @@ -84,8 +124,9 @@ class MLBIE(InfoExtractor): duration = parse_duration(detail.find('./duration').text) timestamp = parse_iso8601(detail.attrib['date'][:-5]) - thumbnail = find_xpath_attr( - detail, './thumbnailScenarios/thumbnailScenario', 'type', '45').text + thumbnails = [{ + 'url': thumbnail.text, + } for thumbnail in detail.findall('./thumbnailScenarios/thumbnailScenario')] formats = [] for media_url in detail.findall('./url'): @@ -112,5 +153,5 @@ class MLBIE(InfoExtractor): 'duration': duration, 'timestamp': timestamp, 'formats': formats, - 'thumbnail': thumbnail, + 'thumbnails': thumbnails, }