[gameone] Simplified extraction of description
[youtube-dl] / youtube_dl / extractor / gameone.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import xml.etree.ElementTree as ET
6
7 from .common import InfoExtractor
8 from ..utils import xpath_with_ns
9
10 NAMESPACE_MAP = {
11     'media': 'http://search.yahoo.com/mrss/',
12 }
13
14 # URL prefix to download the mp4 files directly instead of streaming via rtmp
15 # Credits go to XBox-Maniac http://board.jdownloader.org/showpost.php?p=185835&postcount=31 
16 RAW_MP4_URL = 'http://cdn.riptide-mtvn.com/'
17
18 class GameOneIE(InfoExtractor):
19     _VALID_URL = r'https?://(?:www\.)?gameone\.de/tv/(?P<id>\d+)'
20     _TEST = {
21         'url': 'http://www.gameone.de/tv/288',
22         'md5': '136656b7fb4c9cb4a8e2d500651c499b',
23         'info_dict': {
24             'id': '288',
25             'ext': 'mp4',
26             'title': 'Game One - Folge 288',
27             'duration': 1238,
28             'thumbnail': 'http://s3.gameone.de/gameone/assets/video_metas/teaser_images/000/643/636/big/640x360.jpg',
29             'description': 'FIFA-Pressepokal 2014, Star Citizen, Kingdom Come: Deliverance, Project Cars, Schöner Trants Nerdquiz Folge 2 Runde 1',
30         }
31     }
32
33     def _real_extract(self, url):
34         mobj = re.match(self._VALID_URL, url)
35         video_id = mobj.group('id')
36
37         webpage = self._download_webpage(url, video_id)
38         og_video = self._og_search_video_url(webpage, secure=False)
39         description = self._html_search_meta('description', webpage)
40         mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
41
42         mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
43         title = mrss.find('.//item/title').text
44         thumbnail = mrss.find('.//item/image').get('url')
45         content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
46         content_url = content.get('url')
47
48         content = self._download_xml(content_url, video_id, 'Downloading media:content')
49         rendition_items = content.findall('.//rendition')
50         duration = int(rendition_items[0].get('duration'))
51         formats = [
52                 {
53                     'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
54                     'width': int(r.get('width')),
55                     'height': int(r.get('height')),
56                     'tbr': int(r.get('bitrate')),
57                 }
58             for r in rendition_items
59         ]
60
61         return {
62             'id': video_id,
63             'title': title,
64             'thumbnail': thumbnail,
65             'duration': duration,
66             'formats': formats,
67             'description': description,
68         }