]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/gameone.py
debian/changelog: Annotate bugs being closed.
[youtubedl] / 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 (
8 xpath_with_ns,
9 parse_iso8601
10 )
11
12 NAMESPACE_MAP = {
13 'media': 'http://search.yahoo.com/mrss/',
14 }
15
16 # URL prefix to download the mp4 files directly instead of streaming via rtmp
17 # Credits go to XBox-Maniac
18 # http://board.jdownloader.org/showpost.php?p=185835&postcount=31
19 RAW_MP4_URL = 'http://cdn.riptide-mtvn.com/'
20
21
22 class GameOneIE(InfoExtractor):
23 _VALID_URL = r'https?://(?:www\.)?gameone\.de/tv/(?P<id>\d+)'
24 _TEST = {
25 'url': 'http://www.gameone.de/tv/288',
26 'md5': '136656b7fb4c9cb4a8e2d500651c499b',
27 'info_dict': {
28 'id': '288',
29 'ext': 'mp4',
30 'title': 'Game One - Folge 288',
31 'duration': 1238,
32 'thumbnail': 'http://s3.gameone.de/gameone/assets/video_metas/teaser_images/000/643/636/big/640x360.jpg',
33 'description': 'FIFA-Pressepokal 2014, Star Citizen, Kingdom Come: Deliverance, Project Cars, Schöner Trants Nerdquiz Folge 2 Runde 1',
34 'age_limit': 16,
35 'upload_date': '20140513',
36 'timestamp': 1399980122,
37 }
38 }
39
40 def _real_extract(self, url):
41 mobj = re.match(self._VALID_URL, url)
42 video_id = mobj.group('id')
43
44 webpage = self._download_webpage(url, video_id)
45 og_video = self._og_search_video_url(webpage, secure=False)
46 description = self._html_search_meta('description', webpage)
47 age_limit = int(
48 self._search_regex(
49 r'age=(\d+)',
50 self._html_search_meta(
51 'age-de-meta-label',
52 webpage),
53 'age_limit',
54 '0'))
55 mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
56
57 mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
58 title = mrss.find('.//item/title').text
59 thumbnail = mrss.find('.//item/image').get('url')
60 timestamp = parse_iso8601(mrss.find('.//pubDate').text, delimiter=' ')
61 content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
62 content_url = content.get('url')
63
64 content = self._download_xml(
65 content_url,
66 video_id,
67 'Downloading media:content')
68 rendition_items = content.findall('.//rendition')
69 duration = int(rendition_items[0].get('duration'))
70 formats = [
71 {
72 'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
73 'width': int(r.get('width')),
74 'height': int(r.get('height')),
75 'tbr': int(r.get('bitrate')),
76 }
77 for r in rendition_items
78 ]
79 self._sort_formats(formats)
80
81 return {
82 'id': video_id,
83 'title': title,
84 'thumbnail': thumbnail,
85 'duration': duration,
86 'formats': formats,
87 'description': description,
88 'age_limit': age_limit,
89 'timestamp': timestamp,
90 }
91
92
93 class GameOnePlaylistIE(InfoExtractor):
94 _VALID_URL = r'https?://(?:www\.)?gameone\.de(?:/tv)?/?$'
95 IE_NAME = 'gameone:playlist'
96 _TEST = {
97 'url': 'http://www.gameone.de/tv',
98 'info_dict': {
99 'title': 'GameOne',
100 },
101 'playlist_mincount': 294,
102 }
103
104 def _real_extract(self, url):
105 webpage = self._download_webpage('http://www.gameone.de/tv', 'TV')
106 max_id = max(map(int, re.findall(r'<a href="/tv/(\d+)"', webpage)))
107 entries = [
108 self.url_result('http://www.gameone.de/tv/%d' % video_id, 'GameOne')
109 for video_id in range(max_id, 0, -1)]
110
111 return {
112 '_type': 'playlist',
113 'title': 'GameOne',
114 'entries': entries,
115 }