myvi.py 3.7 KB

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