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