[gameone] Added explanation for usage of http://cdn.riptide-mtvn.com/
[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 # URL prefix to download the mp4 files directly instead of streaming via rtmp
14 # Credits go to XBox-Maniac http://board.jdownloader.org/showpost.php?p=185835&postcount=31 
15 RAW_MP4_URL = 'http://cdn.riptide-mtvn.com/'
16
17 class GameOneIE(InfoExtractor):
18     _VALID_URL = r'https?://(?:www\.)?gameone\.de/tv/(?P<id>\d+)'
19     _TESTS = {
20         'url': 'http://www.gameone.de/tv/288',
21         'md5': '136656b7fb4c9cb4a8e2d500651c499b',
22         'info_dict': {
23             'id': '288',
24             'ext': 'mp4',
25             'title': 'Game One - Folge 288',
26             'duration': 1238,
27             'thumbnail': 'http://s3.gameone.de/gameone/assets/video_metas/teaser_images/000/643/636/big/640x360.jpg',
28         }
29     }
30
31     def _real_extract(self, url):
32         mobj = re.match(self._VALID_URL, url)
33         video_id = mobj.group('id')
34
35         webpage = self._download_webpage(url, video_id)
36         og_video = self._og_search_video_url(webpage, secure=False)
37         mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
38
39         mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
40         title = mrss.find('.//item/title').text
41         thumbnail = mrss.find('.//item/image').get('url')
42         content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
43         content_url = content.get('url')
44
45         content = self._download_xml(content_url, video_id, 'Downloading media:content')
46         rendition_items = content.findall('.//rendition')
47         duration = int(rendition_items[0].get('duration'))
48         formats = [
49                 {
50                     'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
51                     'width': int(r.get('width')),
52                     'height': int(r.get('height')),
53                     'tbr': int(r.get('bitrate')),
54                 }
55             for r in rendition_items
56         ]
57
58         return {
59             'id': video_id,
60             'title': title,
61             'thumbnail': thumbnail,
62             'duration': duration,
63             'formats': formats,
64         }