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