pladform.py 3.0 KB

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