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