]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/giga.py
[cleanup] Upgrade syntax
[yt-dlp.git] / yt_dlp / extractor / giga.py
CommitLineData
0df2dea7
S
1import itertools
2
3from .common import InfoExtractor
4from ..utils import (
5 qualities,
6 compat_str,
7 parse_duration,
8 parse_iso8601,
9 str_to_int,
10)
11
12
13class GigaIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?giga\.de/(?:[^/]+/)*(?P<id>[^/]+)'
15 _TESTS = [{
16 'url': 'http://www.giga.de/filme/anime-awesome/trailer/anime-awesome-chihiros-reise-ins-zauberland-das-beste-kommt-zum-schluss/',
17 'md5': '6bc5535e945e724640664632055a584f',
18 'info_dict': {
19 'id': '2622086',
20 'display_id': 'anime-awesome-chihiros-reise-ins-zauberland-das-beste-kommt-zum-schluss',
21 'ext': 'mp4',
22 'title': 'Anime Awesome: Chihiros Reise ins Zauberland – Das Beste kommt zum Schluss',
23 'description': 'md5:afdf5862241aded4718a30dff6a57baf',
ec85ded8 24 'thumbnail': r're:^https?://.*\.jpg$',
0df2dea7
S
25 'duration': 578,
26 'timestamp': 1414749706,
27 'upload_date': '20141031',
28 'uploader': 'Robin Schweiger',
29 'view_count': int,
30 },
31 }, {
32 'url': 'http://www.giga.de/games/channel/giga-top-montag/giga-topmontag-die-besten-serien-2014/',
33 'only_matching': True,
34 }, {
35 'url': 'http://www.giga.de/extra/netzkultur/videos/giga-games-tom-mats-robin-werden-eigene-wege-gehen-eine-ankuendigung/',
36 'only_matching': True,
37 }, {
38 'url': 'http://www.giga.de/tv/jonas-liest-spieletitel-eingedeutscht-episode-2/',
39 'only_matching': True,
40 }]
41
42 def _real_extract(self, url):
43 display_id = self._match_id(url)
44
45 webpage = self._download_webpage(url, display_id)
46
47 video_id = self._search_regex(
48 [r'data-video-id="(\d+)"', r'/api/video/jwplayer/#v=(\d+)'],
49 webpage, 'video id')
50
51 playlist = self._download_json(
52 'http://www.giga.de/api/syndication/video/video_id/%s/playlist.json?content=syndication/key/368b5f151da4ae05ced7fa296bdff65a/'
53 % video_id, video_id)[0]
54
55 quality = qualities(['normal', 'hd720'])
56
57 formats = []
58 for format_id in itertools.count(0):
59 fmt = playlist.get(compat_str(format_id))
60 if not fmt:
61 break
62 formats.append({
63 'url': fmt['src'],
64 'format_id': '%s-%s' % (fmt['quality'], fmt['type'].split('/')[-1]),
65 'quality': quality(fmt['quality']),
66 })
67 self._sort_formats(formats)
68
69 title = self._html_search_meta(
70 'title', webpage, 'title', fatal=True)
71 description = self._html_search_meta(
72 'description', webpage, 'description')
73 thumbnail = self._og_search_thumbnail(webpage)
74
75 duration = parse_duration(self._search_regex(
76 r'(?s)(?:data-video-id="{0}"|data-video="[^"]*/api/video/jwplayer/#v={0}[^"]*")[^>]*>.+?<span class="duration">([^<]+)</span>'.format(video_id),
77 webpage, 'duration', fatal=False))
78
79 timestamp = parse_iso8601(self._search_regex(
80 r'datetime="([^"]+)"', webpage, 'upload date', fatal=False))
81 uploader = self._search_regex(
82 r'class="author">([^<]+)</a>', webpage, 'uploader', fatal=False)
83
84 view_count = str_to_int(self._search_regex(
6a8f9cd2
S
85 r'<span class="views"><strong>([\d.,]+)</strong>',
86 webpage, 'view count', fatal=False))
0df2dea7
S
87
88 return {
89 'id': video_id,
90 'display_id': display_id,
91 'title': title,
92 'description': description,
93 'thumbnail': thumbnail,
94 'duration': duration,
95 'timestamp': timestamp,
96 'uploader': uploader,
97 'view_count': view_count,
98 'formats': formats,
99 }