2 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..utils import str_to_int
9 class PressTVIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?presstv\.ir/[^/]+/(?P<y>[0-9]+)/(?P<m>[0-9]+)/(?P<d>[0-9]+)/(?P<id>[0-9]+)/'
13 'url': 'http://www.presstv.ir/Detail/2016/04/09/459911/Australian-sewerage-treatment-facility-/',
14 'md5': '5d7e3195a447cb13e9267e931d8dd5a5',
18 'title': 'Organic mattresses used to clean waste water',
19 'upload_date': '20160409',
20 'thumbnail': 'http://media.presstv.com/photo/20160409/41719129-76fa-4372-a09d-bf348278eb5d.jpg',
21 'description': ('A trial program at an Australian sewerage treatment facility hopes to change '
22 'the way waste water is treated by using plant mattresses to reduce chemical '
23 'and electricity use.')
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
29 webpage = self._download_webpage(url, video_id)
31 # extract video URL from webpage
32 video_url = self._html_search_regex(r'<input type="hidden" id="inpPlayback" value="([^"]+)" />', webpage,
35 # build list of available formats
36 # specified in http://www.presstv.ir/Scripts/playback.js
37 base_url = 'http://192.99.219.222:82/presstv'
40 'url': base_url + video_url,
41 'format': '1080p mp4',
44 'url': base_url + video_url.replace(".mp4", "_low800.mp4"),
48 'url': base_url + video_url.replace(".mp4", "_low400.mp4"),
52 'url': base_url + video_url.replace(".mp4", "_low200.mp4"),
59 # extract video metadata
60 title = self._html_search_meta('title', webpage, 'Title', True)
61 title = title.partition('-')[2].strip()
63 thumbnail = self._html_search_meta('og:image', webpage, 'Thumbnail', True)
64 description = self._html_search_meta('og:description', webpage, 'Description', True)
66 year = str_to_int(self._search_regex(PressTVIE._VALID_URL, url, 'Upload year', group='y'))
67 month = str_to_int(self._search_regex(PressTVIE._VALID_URL, url, 'Upload month', group='m'))
68 day = str_to_int(self._search_regex(PressTVIE._VALID_URL, url, 'Upload day', group='d'))
69 upload_date = '%04d%02d%02d' % (year, month, day)
75 'thumbnail': thumbnail,
76 'upload_date': upload_date,
77 'description': description