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