]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/presstv.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / presstv.py
1 from .common import InfoExtractor
2 from ..utils import remove_start
3
4
5 class PressTVIE(InfoExtractor):
6 _VALID_URL = r'https?://(?:www\.)?presstv\.ir/[^/]+/(?P<y>\d+)/(?P<m>\d+)/(?P<d>\d+)/(?P<id>\d+)/(?P<display_id>[^/]+)?'
7
8 _TEST = {
9 'url': 'http://www.presstv.ir/Detail/2016/04/09/459911/Australian-sewerage-treatment-facility-/',
10 'md5': '5d7e3195a447cb13e9267e931d8dd5a5',
11 'info_dict': {
12 'id': '459911',
13 'display_id': 'Australian-sewerage-treatment-facility-',
14 'ext': 'mp4',
15 'title': 'Organic mattresses used to clean waste water',
16 'upload_date': '20160409',
17 'thumbnail': r're:^https?://.*\.jpg',
18 'description': 'md5:20002e654bbafb6908395a5c0cfcd125',
19 },
20 }
21
22 def _real_extract(self, url):
23 mobj = self._match_valid_url(url)
24 video_id = mobj.group('id')
25 display_id = mobj.group('display_id') or video_id
26
27 webpage = self._download_webpage(url, display_id)
28
29 # extract video URL from webpage
30 video_url = self._hidden_inputs(webpage)['inpPlayback']
31
32 # build list of available formats
33 # specified in http://www.presstv.ir/Scripts/playback.js
34 base_url = 'http://192.99.219.222:82/presstv'
35 _formats = [
36 (180, '_low200.mp4'),
37 (360, '_low400.mp4'),
38 (720, '_low800.mp4'),
39 (1080, '.mp4'),
40 ]
41
42 formats = [{
43 'url': base_url + video_url[:-4] + extension,
44 'format_id': f'{height}p',
45 'height': height,
46 } for height, extension in _formats]
47
48 # extract video metadata
49 title = remove_start(
50 self._html_search_meta('title', webpage, fatal=True), 'PressTV-')
51
52 thumbnail = self._og_search_thumbnail(webpage)
53 description = self._og_search_description(webpage)
54
55 upload_date = '%04d%02d%02d' % (
56 int(mobj.group('y')),
57 int(mobj.group('m')),
58 int(mobj.group('d')),
59 )
60
61 return {
62 'id': video_id,
63 'display_id': display_id,
64 'title': title,
65 'formats': formats,
66 'thumbnail': thumbnail,
67 'upload_date': upload_date,
68 'description': description,
69 }