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