logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

pladform.py (4244B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urlparse
  6. from ..utils import (
  7. determine_ext,
  8. ExtractorError,
  9. int_or_none,
  10. xpath_text,
  11. qualities,
  12. )
  13. class PladformIE(InfoExtractor):
  14. _VALID_URL = r'''(?x)
  15. https?://
  16. (?:
  17. (?:
  18. out\.pladform\.ru/player|
  19. static\.pladform\.ru/player\.swf
  20. )
  21. \?.*\bvideoid=|
  22. video\.pladform\.ru/catalog/video/videoid/
  23. )
  24. (?P<id>\d+)
  25. '''
  26. _TESTS = [{
  27. 'url': 'https://out.pladform.ru/player?pl=64471&videoid=3777899&vk_puid15=0&vk_puid34=0',
  28. 'md5': '53362fac3a27352da20fa2803cc5cd6f',
  29. 'info_dict': {
  30. 'id': '3777899',
  31. 'ext': 'mp4',
  32. 'title': 'СТУДИЯ СОЮЗ • Шоу Студия Союз, 24 выпуск (01.02.2018) Нурлан Сабуров и Слава Комиссаренко',
  33. 'description': 'md5:05140e8bf1b7e2d46e7ba140be57fd95',
  34. 'thumbnail': r're:^https?://.*\.jpg$',
  35. 'duration': 3190,
  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\?.+?)\1', webpage)
  48. if mobj:
  49. return mobj.group('url')
  50. def _real_extract(self, url):
  51. video_id = self._match_id(url)
  52. qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
  53. pl = qs.get('pl', ['1'])[0]
  54. video = self._download_xml(
  55. 'http://out.pladform.ru/getVideo', video_id, query={
  56. 'pl': pl,
  57. 'videoid': video_id,
  58. })
  59. def fail(text):
  60. raise ExtractorError(
  61. '%s returned error: %s' % (self.IE_NAME, text),
  62. expected=True)
  63. if video.tag == 'error':
  64. fail(video.text)
  65. quality = qualities(('ld', 'sd', 'hd'))
  66. formats = []
  67. for src in video.findall('./src'):
  68. if src is None:
  69. continue
  70. format_url = src.text
  71. if not format_url:
  72. continue
  73. if src.get('type') == 'hls' or determine_ext(format_url) == 'm3u8':
  74. formats.extend(self._extract_m3u8_formats(
  75. format_url, video_id, 'mp4', entry_protocol='m3u8_native',
  76. m3u8_id='hls', fatal=False))
  77. else:
  78. formats.append({
  79. 'url': src.text,
  80. 'format_id': src.get('quality'),
  81. 'quality': quality(src.get('quality')),
  82. })
  83. if not formats:
  84. error = xpath_text(video, './cap', 'error', default=None)
  85. if error:
  86. fail(error)
  87. self._sort_formats(formats)
  88. webpage = self._download_webpage(
  89. 'http://video.pladform.ru/catalog/video/videoid/%s' % video_id,
  90. video_id)
  91. title = self._og_search_title(webpage, fatal=False) or xpath_text(
  92. video, './/title', 'title', fatal=True)
  93. description = self._search_regex(
  94. r'</h3>\s*<p>([^<]+)</p>', webpage, 'description', fatal=False)
  95. thumbnail = self._og_search_thumbnail(webpage) or xpath_text(
  96. video, './/cover', 'cover')
  97. duration = int_or_none(xpath_text(video, './/time', 'duration'))
  98. age_limit = int_or_none(xpath_text(video, './/age18', 'age limit'))
  99. return {
  100. 'id': video_id,
  101. 'title': title,
  102. 'description': description,
  103. 'thumbnail': thumbnail,
  104. 'duration': duration,
  105. 'age_limit': age_limit,
  106. 'formats': formats,
  107. }