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.

111 lines
3.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from .vimple import SprutoBaseIE
  6. class MyviIE(SprutoBaseIE):
  7. _VALID_URL = r'''(?x)
  8. (?:
  9. https?://
  10. (?:www\.)?
  11. myvi\.
  12. (?:
  13. (?:ru/player|tv)/
  14. (?:
  15. (?:
  16. embed/html|
  17. flash|
  18. api/Video/Get
  19. )/|
  20. content/preloader\.swf\?.*\bid=
  21. )|
  22. ru/watch/
  23. )|
  24. myvi:
  25. )
  26. (?P<id>[\da-zA-Z_-]+)
  27. '''
  28. _TESTS = [{
  29. 'url': 'http://myvi.ru/player/embed/html/oOy4euHA6LVwNNAjhD9_Jq5Ha2Qf0rtVMVFMAZav8wObeRTZaCATzucDQIDph8hQU0',
  30. 'md5': '571bbdfba9f9ed229dc6d34cc0f335bf',
  31. 'info_dict': {
  32. 'id': 'f16b2bbd-cde8-481c-a981-7cd48605df43',
  33. 'ext': 'mp4',
  34. 'title': 'хозяин жизни',
  35. 'thumbnail': r're:^https?://.*\.jpg$',
  36. 'duration': 25,
  37. },
  38. }, {
  39. 'url': 'http://myvi.ru/player/content/preloader.swf?id=oOy4euHA6LVwNNAjhD9_Jq5Ha2Qf0rtVMVFMAZav8wOYf1WFpPfc_bWTKGVf_Zafr0',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'http://myvi.ru/player/api/Video/Get/oOy4euHA6LVwNNAjhD9_Jq5Ha2Qf0rtVMVFMAZav8wObeRTZaCATzucDQIDph8hQU0',
  43. 'only_matching': True,
  44. }, {
  45. 'url': 'http://myvi.tv/embed/html/oTGTNWdyz4Zwy_u1nraolwZ1odenTd9WkTnRfIL9y8VOgHYqOHApE575x4_xxS9Vn0?ap=0',
  46. 'only_matching': True,
  47. }, {
  48. 'url': 'http://myvi.ru/player/flash/ocp2qZrHI-eZnHKQBK4cZV60hslH8LALnk0uBfKsB-Q4WnY26SeGoYPi8HWHxu0O30',
  49. 'only_matching': True,
  50. }, {
  51. 'url': 'https://www.myvi.ru/watch/YwbqszQynUaHPn_s82sx0Q2',
  52. 'only_matching': True,
  53. }, {
  54. 'url': 'myvi:YwbqszQynUaHPn_s82sx0Q2',
  55. 'only_matching': True,
  56. }]
  57. @classmethod
  58. def _extract_url(cls, webpage):
  59. mobj = re.search(
  60. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//myvi\.(?:ru/player|tv)/(?:embed/html|flash)/[^"]+)\1', webpage)
  61. if mobj:
  62. return mobj.group('url')
  63. def _real_extract(self, url):
  64. video_id = self._match_id(url)
  65. spruto = self._download_json(
  66. 'http://myvi.ru/player/api/Video/Get/%s?sig' % video_id, video_id)['sprutoData']
  67. return self._extract_spruto(spruto, video_id)
  68. class MyviEmbedIE(InfoExtractor):
  69. _VALID_URL = r'https?://(?:www\.)?myvi\.tv/(?:[^?]+\?.*?\bv=|embed/)(?P<id>[\da-z]+)'
  70. _TESTS = [{
  71. 'url': 'https://www.myvi.tv/embed/ccdqic3wgkqwpb36x9sxg43t4r',
  72. 'info_dict': {
  73. 'id': 'b3ea0663-3234-469d-873e-7fecf36b31d1',
  74. 'ext': 'mp4',
  75. 'title': 'Твоя (original song).mp4',
  76. 'thumbnail': r're:^https?://.*\.jpg$',
  77. 'duration': 277,
  78. },
  79. 'params': {
  80. 'skip_download': True,
  81. },
  82. }, {
  83. 'url': 'https://www.myvi.tv/idmi6o?v=ccdqic3wgkqwpb36x9sxg43t4r#watch',
  84. 'only_matching': True,
  85. }]
  86. @classmethod
  87. def suitable(cls, url):
  88. return False if MyviIE.suitable(url) else super(MyviEmbedIE, cls).suitable(url)
  89. def _real_extract(self, url):
  90. video_id = self._match_id(url)
  91. webpage = self._download_webpage(
  92. 'https://www.myvi.tv/embed/%s' % video_id, video_id)
  93. myvi_id = self._search_regex(
  94. r'CreatePlayer\s*\(\s*["\'].*?\bv=([\da-zA-Z_]+)',
  95. webpage, 'video id')
  96. return self.url_result('myvi:%s' % myvi_id, ie=MyviIE.ie_key())