presstv.py 2.3 KB

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