]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/gamestar.py
[test/download] Fallback test to `bv`
[yt-dlp.git] / yt_dlp / extractor / gamestar.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .common import InfoExtractor
6 from ..utils import (
7 int_or_none,
8 remove_end,
9 )
10
11
12 class GameStarIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?game(?P<site>pro|star)\.de/videos/.*,(?P<id>[0-9]+)\.html'
14 _TESTS = [{
15 'url': 'http://www.gamestar.de/videos/trailer,3/hobbit-3-die-schlacht-der-fuenf-heere,76110.html',
16 'md5': 'ee782f1f8050448c95c5cacd63bc851c',
17 'info_dict': {
18 'id': '76110',
19 'ext': 'mp4',
20 'title': 'Hobbit 3: Die Schlacht der Fünf Heere - Teaser-Trailer zum dritten Teil',
21 'description': 'Der Teaser-Trailer zu Hobbit 3: Die Schlacht der Fünf Heere zeigt einige Szenen aus dem dritten Teil der Saga und kündigt den...',
22 'thumbnail': r're:^https?://.*\.jpg$',
23 'timestamp': 1406542380,
24 'upload_date': '20140728',
25 'duration': 17,
26 }
27 }, {
28 'url': 'http://www.gamepro.de/videos/top-10-indie-spiele-fuer-nintendo-switch-video-tolle-nindies-games-zum-download,95316.html',
29 'only_matching': True,
30 }, {
31 'url': 'http://www.gamestar.de/videos/top-10-indie-spiele-fuer-nintendo-switch-video-tolle-nindies-games-zum-download,95316.html',
32 'only_matching': True,
33 }]
34
35 def _real_extract(self, url):
36 mobj = self._match_valid_url(url)
37 site = mobj.group('site')
38 video_id = mobj.group('id')
39
40 webpage = self._download_webpage(url, video_id)
41
42 # TODO: there are multiple ld+json objects in the webpage,
43 # while _search_json_ld finds only the first one
44 json_ld = self._parse_json(self._search_regex(
45 r'(?s)<script[^>]+type=(["\'])application/ld\+json\1[^>]*>(?P<json_ld>[^<]+VideoObject[^<]+)</script>',
46 webpage, 'JSON-LD', group='json_ld'), video_id)
47 info_dict = self._json_ld(json_ld, video_id)
48 info_dict['title'] = remove_end(
49 info_dict['title'], ' - Game%s' % site.title())
50
51 view_count = int_or_none(json_ld.get('interactionCount'))
52 comment_count = int_or_none(self._html_search_regex(
53 r'<span>Kommentare</span>\s*<span[^>]+class=["\']count[^>]+>\s*\(\s*([0-9]+)',
54 webpage, 'comment count', fatal=False))
55
56 info_dict.update({
57 'id': video_id,
58 'url': 'http://gamestar.de/_misc/videos/portal/getVideoUrl.cfm?premium=0&videoId=' + video_id,
59 'ext': 'mp4',
60 'view_count': view_count,
61 'comment_count': comment_count
62 })
63
64 return info_dict