You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3 KiB

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