]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/gameone.py
[/__init__] Add another cute search example
[yt-dlp.git] / youtube_dl / extractor / gameone.py
CommitLineData
412f356e
TB
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
305d0683
TB
7from ..utils import (
8 xpath_with_ns,
39ac7c94
S
9 parse_iso8601,
10 float_or_none,
11 int_or_none,
305d0683 12)
412f356e
TB
13
14NAMESPACE_MAP = {
15 'media': 'http://search.yahoo.com/mrss/',
16}
17
10d5c7aa 18# URL prefix to download the mp4 files directly instead of streaming via rtmp
e5c3a4b5
TB
19# Credits go to XBox-Maniac
20# http://board.jdownloader.org/showpost.php?p=185835&postcount=31
412f356e
TB
21RAW_MP4_URL = 'http://cdn.riptide-mtvn.com/'
22
305d0683 23
412f356e
TB
24class GameOneIE(InfoExtractor):
25 _VALID_URL = r'https?://(?:www\.)?gameone\.de/tv/(?P<id>\d+)'
55f0cab3
TB
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',
39ac7c94 52 'duration': 896.62,
55f0cab3
TB
53 'age_limit': 16,
54 }
412f356e 55 }
55f0cab3
TB
56
57 ]
412f356e
TB
58
59 def _real_extract(self, url):
60 mobj = re.match(self._VALID_URL, url)
61 video_id = mobj.group('id')
62
63 webpage = self._download_webpage(url, video_id)
64 og_video = self._og_search_video_url(webpage, secure=False)
a84d20fc 65 description = self._html_search_meta('description', webpage)
e5c3a4b5
TB
66 age_limit = int(
67 self._search_regex(
68 r'age=(\d+)',
69 self._html_search_meta(
70 'age-de-meta-label',
71 webpage),
72 'age_limit',
73 '0'))
412f356e
TB
74 mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
75
76 mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
77 title = mrss.find('.//item/title').text
78 thumbnail = mrss.find('.//item/image').get('url')
305d0683 79 timestamp = parse_iso8601(mrss.find('.//pubDate').text, delimiter=' ')
412f356e
TB
80 content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
81 content_url = content.get('url')
82
e5c3a4b5
TB
83 content = self._download_xml(
84 content_url,
85 video_id,
86 'Downloading media:content')
412f356e 87 rendition_items = content.findall('.//rendition')
39ac7c94 88 duration = float_or_none(rendition_items[0].get('duration'))
412f356e 89 formats = [
e5c3a4b5
TB
90 {
91 'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
39ac7c94
S
92 'width': int_or_none(r.get('width')),
93 'height': int_or_none(r.get('height')),
94 'tbr': int_or_none(r.get('bitrate')),
e5c3a4b5 95 }
412f356e
TB
96 for r in rendition_items
97 ]
d96b9d40 98 self._sort_formats(formats)
412f356e
TB
99
100 return {
101 'id': video_id,
102 'title': title,
103 'thumbnail': thumbnail,
104 'duration': duration,
105 'formats': formats,
9e300923 106 'description': description,
a231ce87 107 'age_limit': age_limit,
305d0683 108 'timestamp': timestamp,
412f356e 109 }
c065fd35 110
28028629 111
c065fd35
OE
112class GameOnePlaylistIE(InfoExtractor):
113 _VALID_URL = r'https?://(?:www\.)?gameone\.de(?:/tv)?/?$'
28028629
PH
114 IE_NAME = 'gameone:playlist'
115 _TEST = {
116 'url': 'http://www.gameone.de/tv',
117 'info_dict': {
118 'title': 'GameOne',
119 },
120 'playlist_mincount': 294,
121 }
c065fd35
OE
122
123 def _real_extract(self, url):
8c778adc 124 webpage = self._download_webpage('http://www.gameone.de/tv', 'TV')
c065fd35 125 max_id = max(map(int, re.findall(r'<a href="/tv/(\d+)"', webpage)))
28028629 126 entries = [
55f0cab3
TB
127 self.url_result('http://www.gameone.de/tv/%d' %
128 video_id, 'GameOne')
28028629 129 for video_id in range(max_id, 0, -1)]
c065fd35
OE
130
131 return {
132 '_type': 'playlist',
133 'title': 'GameOne',
134 'entries': entries,
135 }