2015-10-09 18:38:11 +02:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import str_to_int
|
|
|
|
|
|
|
|
|
|
|
|
class PressTVIE(InfoExtractor):
|
2016-04-09 16:14:05 +02:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?presstv\.ir/[^/]+/(?P<y>[0-9]+)/(?P<m>[0-9]+)/(?P<d>[0-9]+)/(?P<id>[0-9]+)/'
|
2015-10-09 18:38:11 +02:00
|
|
|
|
|
|
|
_TEST = {
|
2016-04-09 16:14:05 +02:00
|
|
|
'url': 'http://www.presstv.ir/Detail/2016/04/09/459911/Australian-sewerage-treatment-facility-/',
|
|
|
|
'md5': '5d7e3195a447cb13e9267e931d8dd5a5',
|
2015-10-09 18:38:11 +02:00
|
|
|
'info_dict': {
|
2016-04-09 16:14:05 +02:00
|
|
|
'id': '459911',
|
2015-10-09 18:38:11 +02:00
|
|
|
'ext': 'mp4',
|
2016-04-09 16:14:05 +02:00
|
|
|
'title': 'Organic mattresses used to clean waste water',
|
|
|
|
'upload_date': '20160409',
|
2016-04-10 16:36:44 +02:00
|
|
|
'thumbnail': 're:^https?://.*\.jpg',
|
|
|
|
'description': 'md5:20002e654bbafb6908395a5c0cfcd125'
|
2015-10-09 18:38:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
|
|
|
# extract video URL from webpage
|
|
|
|
video_url = self._html_search_regex(r'<input type="hidden" id="inpPlayback" value="([^"]+)" />', webpage,
|
|
|
|
'Video URL')
|
|
|
|
|
|
|
|
# build list of available formats
|
|
|
|
# specified in http://www.presstv.ir/Scripts/playback.js
|
|
|
|
base_url = 'http://192.99.219.222:82/presstv'
|
2016-04-10 16:36:44 +02:00
|
|
|
_formats = [
|
|
|
|
("180p", "_low200.mp4"),
|
|
|
|
("360p", "_low400.mp4"),
|
|
|
|
("720p", "_low800.mp4"),
|
|
|
|
("1080p", ".mp4")
|
2015-10-09 18:38:11 +02:00
|
|
|
]
|
2016-04-10 16:36:44 +02:00
|
|
|
|
|
|
|
formats = []
|
|
|
|
for fmt in _formats:
|
|
|
|
format_id, extension = fmt
|
|
|
|
formats.append({
|
|
|
|
'url': base_url + video_url[:-4] + extension,
|
|
|
|
'format_id': format_id
|
|
|
|
})
|
2015-10-09 18:38:11 +02:00
|
|
|
|
|
|
|
# extract video metadata
|
|
|
|
title = self._html_search_meta('title', webpage, 'Title', True)
|
2016-04-09 16:14:05 +02:00
|
|
|
title = title.partition('-')[2].strip()
|
2015-10-09 18:38:11 +02:00
|
|
|
|
2016-04-10 16:36:44 +02:00
|
|
|
thumbnail = self._og_search_thumbnail(webpage)
|
|
|
|
description = self._og_search_description(webpage)
|
2015-10-09 18:38:11 +02:00
|
|
|
|
2016-04-10 16:36:44 +02:00
|
|
|
match = re.match(PressTVIE._VALID_URL, url)
|
|
|
|
upload_date = '%04d%02d%02d' % (
|
|
|
|
str_to_int(match.group('y')),
|
|
|
|
str_to_int(match.group('m')),
|
|
|
|
str_to_int(match.group('d'))
|
|
|
|
)
|
2015-10-09 18:38:11 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
|
|
|
'formats': formats,
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
'upload_date': upload_date,
|
|
|
|
'description': description
|
|
|
|
}
|