]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/gamestar.py
Fix "invalid escape sequences" error on Python 3.6
[yt-dlp.git] / youtube_dl / extractor / gamestar.py
CommitLineData
8646eb79
S
1# coding: utf-8
2from __future__ import unicode_literals
3
8646eb79 4from .common import InfoExtractor
895ba7d1
PH
5from ..utils import (
6 int_or_none,
84b91dd4 7 remove_end,
895ba7d1
PH
8)
9
8646eb79
S
10
11class GameStarIE(InfoExtractor):
92519402 12 _VALID_URL = r'https?://(?:www\.)?gamestar\.de/videos/.*,(?P<id>[0-9]+)\.html'
8646eb79
S
13 _TEST = {
14 'url': 'http://www.gamestar.de/videos/trailer,3/hobbit-3-die-schlacht-der-fuenf-heere,76110.html',
15 'md5': '96974ecbb7fd8d0d20fca5a00810cea7',
16 'info_dict': {
17 'id': '76110',
18 'ext': 'mp4',
19 'title': 'Hobbit 3: Die Schlacht der Fünf Heere - Teaser-Trailer zum dritten Teil',
84b91dd4 20 '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...',
ec85ded8 21 'thumbnail': r're:^https?://.*\.jpg$',
84b91dd4 22 'timestamp': 1406542020,
8646eb79
S
23 'upload_date': '20140728',
24 'duration': 17
25 }
26 }
27
28 def _real_extract(self, url):
08ff6ab0 29 video_id = self._match_id(url)
8646eb79
S
30 webpage = self._download_webpage(url, video_id)
31
8646eb79
S
32 url = 'http://gamestar.de/_misc/videos/portal/getVideoUrl.cfm?premium=0&videoId=' + video_id
33
84b91dd4
YCH
34 # TODO: there are multiple ld+json objects in the webpage,
35 # while _search_json_ld finds only the first one
36 json_ld = self._parse_json(self._search_regex(
37 r'(?s)<script[^>]+type=(["\'])application/ld\+json\1[^>]*>(?P<json_ld>[^<]+VideoObject[^<]+)</script>',
38 webpage, 'JSON-LD', group='json_ld'), video_id)
39 info_dict = self._json_ld(json_ld, video_id)
40 info_dict['title'] = remove_end(info_dict['title'], ' - GameStar')
8646eb79 41
84b91dd4 42 view_count = json_ld.get('interactionCount')
895ba7d1 43 comment_count = int_or_none(self._html_search_regex(
84b91dd4 44 r'([0-9]+) Kommentare</span>', webpage, 'comment_count',
895ba7d1 45 fatal=False))
8646eb79 46
84b91dd4 47 info_dict.update({
8646eb79 48 'id': video_id,
8646eb79
S
49 'url': url,
50 'ext': 'mp4',
8646eb79
S
51 'view_count': view_count,
52 'comment_count': comment_count
84b91dd4
YCH
53 })
54
55 return info_dict