]>
Commit | Line | Data |
---|---|---|
5dd37634 S |
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 | self._sort_formats(formats) | |
61 | ||
62 | description = self._og_search_description( | |
63 | webpage, default=None) or self._html_search_meta( | |
64 | 'description', webpage, 'description') | |
65 | ||
66 | thumbnail = video.get('thumb') or self._og_search_thumbnail( | |
67 | webpage, default=None) or self._html_search_meta( | |
68 | 'thumbnail', webpage, 'thumbnail') | |
69 | ||
70 | timestamp = unified_timestamp(video.get('date_added')) | |
71 | uploader = try_get( | |
72 | video, lambda x: x['uploader']['name'], | |
73 | compat_str) or self._html_search_meta('author', webpage, 'author') | |
74 | ||
75 | duration = int_or_none(video.get('duration')) | |
76 | view_count = int_or_none(video.get('views')) | |
77 | ||
78 | return { | |
79 | 'id': video_id, | |
80 | 'title': title, | |
81 | 'description': description, | |
82 | 'thumbnail': thumbnail, | |
83 | 'timestamp': timestamp, | |
84 | 'uploader': uploader, | |
85 | 'duration': duration, | |
86 | 'view_count': view_count, | |
87 | 'formats': formats, | |
88 | } |