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.

99 lines
3.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. xpath_text,
  9. qualities,
  10. )
  11. class PladformIE(InfoExtractor):
  12. _VALID_URL = r'''(?x)
  13. https?://
  14. (?:
  15. (?:
  16. out\.pladform\.ru/player|
  17. static\.pladform\.ru/player\.swf
  18. )
  19. \?.*\bvideoid=|
  20. video\.pladform\.ru/catalog/video/videoid/
  21. )
  22. (?P<id>\d+)
  23. '''
  24. _TESTS = [{
  25. # http://muz-tv.ru/kinozal/view/7400/
  26. 'url': 'http://out.pladform.ru/player?pl=24822&videoid=100183293',
  27. 'md5': '61f37b575dd27f1bb2e1854777fe31f4',
  28. 'info_dict': {
  29. 'id': '100183293',
  30. 'ext': 'mp4',
  31. 'title': 'Тайны перевала Дятлова • 1 серия 2 часть',
  32. 'description': 'Документальный сериал-расследование одной из самых жутких тайн ХХ века',
  33. 'thumbnail': 're:^https?://.*\.jpg$',
  34. 'duration': 694,
  35. 'age_limit': 0,
  36. },
  37. }, {
  38. 'url': 'http://static.pladform.ru/player.swf?pl=21469&videoid=100183293&vkcid=0',
  39. 'only_matching': True,
  40. }, {
  41. 'url': 'http://video.pladform.ru/catalog/video/videoid/100183293/vkcid/0',
  42. 'only_matching': True,
  43. }]
  44. @staticmethod
  45. def _extract_url(webpage):
  46. mobj = re.search(
  47. r'<iframe[^>]+src="(?P<url>(?:https?:)?//out\.pladform\.ru/player\?.+?)"', webpage)
  48. if mobj:
  49. return mobj.group('url')
  50. def _real_extract(self, url):
  51. video_id = self._match_id(url)
  52. video = self._download_xml(
  53. 'http://out.pladform.ru/getVideo?pl=1&videoid=%s' % video_id,
  54. video_id)
  55. if video.tag == 'error':
  56. raise ExtractorError(
  57. '%s returned error: %s' % (self.IE_NAME, video.text),
  58. expected=True)
  59. quality = qualities(('ld', 'sd', 'hd'))
  60. formats = [{
  61. 'url': src.text,
  62. 'format_id': src.get('quality'),
  63. 'quality': quality(src.get('quality')),
  64. } for src in video.findall('./src')]
  65. self._sort_formats(formats)
  66. webpage = self._download_webpage(
  67. 'http://video.pladform.ru/catalog/video/videoid/%s' % video_id,
  68. video_id)
  69. title = self._og_search_title(webpage, fatal=False) or xpath_text(
  70. video, './/title', 'title', fatal=True)
  71. description = self._search_regex(
  72. r'</h3>\s*<p>([^<]+)</p>', webpage, 'description', fatal=False)
  73. thumbnail = self._og_search_thumbnail(webpage) or xpath_text(
  74. video, './/cover', 'cover')
  75. duration = int_or_none(xpath_text(video, './/time', 'duration'))
  76. age_limit = int_or_none(xpath_text(video, './/age18', 'age limit'))
  77. return {
  78. 'id': video_id,
  79. 'title': title,
  80. 'description': description,
  81. 'thumbnail': thumbnail,
  82. 'duration': duration,
  83. 'age_limit': age_limit,
  84. 'formats': formats,
  85. }