]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tunepk.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / tunepk.py
1 from .common import InfoExtractor
2 from ..compat import compat_str
3 from ..utils import (
4 int_or_none,
5 try_get,
6 unified_timestamp,
7 )
8
9
10 class TunePkIE(InfoExtractor):
11 _VALID_URL = r'''(?x)
12 https?://
13 (?:
14 (?:www\.)?tune\.pk/(?:video/|player/embed_player.php?.*?\bvid=)|
15 embed\.tune\.pk/play/
16 )
17 (?P<id>\d+)
18 '''
19 _TESTS = [{
20 'url': 'https://tune.pk/video/6919541/maudie-2017-international-trailer-1-ft-ethan-hawke-sally-hawkins',
21 'md5': '0c537163b7f6f97da3c5dd1e3ef6dd55',
22 'info_dict': {
23 'id': '6919541',
24 'ext': 'mp4',
25 'title': 'Maudie (2017) | International Trailer # 1 ft Ethan Hawke, Sally Hawkins',
26 'description': 'md5:eb5a04114fafef5cec90799a93a2d09c',
27 'thumbnail': r're:^https?://.*\.jpg$',
28 'timestamp': 1487327564,
29 'upload_date': '20170217',
30 'uploader': 'Movie Trailers',
31 'duration': 107,
32 'view_count': int,
33 }
34 }, {
35 'url': 'https://tune.pk/player/embed_player.php?vid=6919541&folder=2017/02/17/&width=600&height=350&autoplay=no',
36 'only_matching': True,
37 }, {
38 'url': 'https://embed.tune.pk/play/6919541?autoplay=no&ssl=yes&inline=true',
39 'only_matching': True,
40 }]
41
42 def _real_extract(self, url):
43 video_id = self._match_id(url)
44
45 webpage = self._download_webpage(
46 'https://tune.pk/video/%s' % video_id, video_id)
47
48 details = self._parse_json(
49 self._search_regex(
50 r'new\s+TunePlayer\(({.+?})\)\s*;\s*\n', webpage, 'tune player'),
51 video_id)['details']
52
53 video = details['video']
54 title = video.get('title') or self._og_search_title(
55 webpage, default=None) or self._html_search_meta(
56 'title', webpage, 'title', fatal=True)
57
58 formats = self._parse_jwplayer_formats(
59 details['player']['sources'], video_id)
60
61 description = self._og_search_description(
62 webpage, default=None) or self._html_search_meta(
63 'description', webpage, 'description')
64
65 thumbnail = video.get('thumb') or self._og_search_thumbnail(
66 webpage, default=None) or self._html_search_meta(
67 'thumbnail', webpage, 'thumbnail')
68
69 timestamp = unified_timestamp(video.get('date_added'))
70 uploader = try_get(
71 video, lambda x: x['uploader']['name'],
72 compat_str) or self._html_search_meta('author', webpage, 'author')
73
74 duration = int_or_none(video.get('duration'))
75 view_count = int_or_none(video.get('views'))
76
77 return {
78 'id': video_id,
79 'title': title,
80 'description': description,
81 'thumbnail': thumbnail,
82 'timestamp': timestamp,
83 'uploader': uploader,
84 'duration': duration,
85 'view_count': view_count,
86 'formats': formats,
87 }