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