[gameone] Add new extractor gameone
[youtube-dl] / youtube_dl / extractor / gameone.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import xpath_with_ns
8
9 NAMESPACE_MAP = {
10     'media': 'http://search.yahoo.com/mrss/',
11 }
12
13 RAW_MP4_URL = 'http://cdn.riptide-mtvn.com/'
14
15 class GameOneIE(InfoExtractor):
16     _VALID_URL = r'https?://(?:www\.)?gameone\.de/tv/(?P<id>\d+)'
17     _TESTS = {
18         'url': 'http://www.gameone.de/tv/288',
19         'md5': '136656b7fb4c9cb4a8e2d500651c499b',
20         'info_dict': {
21             'id': '288',
22             'ext': 'mp4',
23             'title': 'Game One - Folge 288',
24             'duration': 1238,
25             'thumbnail': 'http://s3.gameone.de/gameone/assets/video_metas/teaser_images/000/643/636/big/640x360.jpg',
26         }
27     }
28
29     def _real_extract(self, url):
30         mobj = re.match(self._VALID_URL, url)
31         video_id = mobj.group('id')
32
33         webpage = self._download_webpage(url, video_id)
34         og_video = self._og_search_video_url(webpage, secure=False)
35         mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
36
37         mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
38         title = mrss.find('.//item/title').text
39         thumbnail = mrss.find('.//item/image').get('url')
40         content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
41         content_url = content.get('url')
42
43         content = self._download_xml(content_url, video_id, 'Downloading media:content')
44         rendition_items = content.findall('.//rendition')
45         duration = int(rendition_items[0].get('duration'))
46         formats = [
47                 {
48                     'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
49                     'width': int(r.get('width')),
50                     'height': int(r.get('height')),
51                     'tbr': int(r.get('bitrate')),
52                 }
53             for r in rendition_items
54         ]
55
56         return {
57             'id': video_id,
58             'title': title,
59             'thumbnail': thumbnail,
60             'duration': duration,
61             'formats': formats,
62         }