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.

138 lines
5.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. remove_end,
  8. )
  9. class MailRuIE(InfoExtractor):
  10. IE_NAME = 'mailru'
  11. IE_DESC = 'Видео@Mail.Ru'
  12. _VALID_URL = r'https?://(?:(?:www|m)\.)?my\.mail\.ru/(?:video/.*#video=/?(?P<idv1>(?:[^/]+/){3}\d+)|(?:(?P<idv2prefix>(?:[^/]+/){2})video/(?P<idv2suffix>[^/]+/\d+))\.html)'
  13. _TESTS = [
  14. {
  15. 'url': 'http://my.mail.ru/video/top#video=/mail/sonypicturesrus/75/76',
  16. 'md5': 'dea205f03120046894db4ebb6159879a',
  17. 'info_dict': {
  18. 'id': '46301138_76',
  19. 'ext': 'mp4',
  20. 'title': 'Новый Человек-Паук. Высокое напряжение. Восстание Электро',
  21. 'timestamp': 1393232740,
  22. 'upload_date': '20140224',
  23. 'uploader': 'sonypicturesrus',
  24. 'uploader_id': 'sonypicturesrus@mail.ru',
  25. 'duration': 184,
  26. },
  27. 'skip': 'Not accessible from Travis CI server',
  28. },
  29. {
  30. 'url': 'http://my.mail.ru/corp/hitech/video/news_hi-tech_mail_ru/1263.html',
  31. 'md5': '00a91a58c3402204dcced523777b475f',
  32. 'info_dict': {
  33. 'id': '46843144_1263',
  34. 'ext': 'mp4',
  35. 'title': 'Samsung Galaxy S5 Hammer Smash Fail Battery Explosion',
  36. 'timestamp': 1397039888,
  37. 'upload_date': '20140409',
  38. 'uploader': 'hitech@corp.mail.ru',
  39. 'uploader_id': 'hitech@corp.mail.ru',
  40. 'duration': 245,
  41. },
  42. 'skip': 'Not accessible from Travis CI server',
  43. },
  44. {
  45. # only available via metaUrl API
  46. 'url': 'http://my.mail.ru/mail/720pizle/video/_myvideo/502.html',
  47. 'md5': '3b26d2491c6949d031a32b96bd97c096',
  48. 'info_dict': {
  49. 'id': '56664382_502',
  50. 'ext': 'mp4',
  51. 'title': ':8336',
  52. 'timestamp': 1449094163,
  53. 'upload_date': '20151202',
  54. 'uploader': '720pizle@mail.ru',
  55. 'uploader_id': '720pizle@mail.ru',
  56. 'duration': 6001,
  57. },
  58. 'skip': 'Not accessible from Travis CI server',
  59. },
  60. {
  61. 'url': 'http://m.my.mail.ru/mail/3sktvtr/video/_myvideo/138.html',
  62. 'only_matching': True,
  63. }
  64. ]
  65. def _real_extract(self, url):
  66. mobj = re.match(self._VALID_URL, url)
  67. video_id = mobj.group('idv1')
  68. if not video_id:
  69. video_id = mobj.group('idv2prefix') + mobj.group('idv2suffix')
  70. webpage = self._download_webpage(url, video_id)
  71. video_data = None
  72. page_config = self._parse_json(self._search_regex(
  73. r'(?s)<script[^>]+class="sp-video__page-config"[^>]*>(.+?)</script>',
  74. webpage, 'page config', default='{}'), video_id, fatal=False)
  75. if page_config:
  76. meta_url = page_config.get('metaUrl') or page_config.get('video', {}).get('metaUrl')
  77. if meta_url:
  78. video_data = self._download_json(
  79. meta_url, video_id, 'Downloading video meta JSON', fatal=False)
  80. # Fallback old approach
  81. if not video_data:
  82. video_data = self._download_json(
  83. 'http://api.video.mail.ru/videos/%s.json?new=1' % video_id,
  84. video_id, 'Downloading video JSON')
  85. formats = []
  86. for f in video_data['videos']:
  87. video_url = f.get('url')
  88. if not video_url:
  89. continue
  90. format_id = f.get('key')
  91. height = int_or_none(self._search_regex(
  92. r'^(\d+)[pP]$', format_id, 'height', default=None)) if format_id else None
  93. formats.append({
  94. 'url': video_url,
  95. 'format_id': format_id,
  96. 'height': height,
  97. })
  98. self._sort_formats(formats)
  99. meta_data = video_data['meta']
  100. title = remove_end(meta_data['title'], '.mp4')
  101. author = video_data.get('author')
  102. uploader = author.get('name')
  103. uploader_id = author.get('id') or author.get('email')
  104. view_count = int_or_none(video_data.get('viewsCount') or video_data.get('views_count'))
  105. acc_id = meta_data.get('accId')
  106. item_id = meta_data.get('itemId')
  107. content_id = '%s_%s' % (acc_id, item_id) if acc_id and item_id else video_id
  108. thumbnail = meta_data.get('poster')
  109. duration = int_or_none(meta_data.get('duration'))
  110. timestamp = int_or_none(meta_data.get('timestamp'))
  111. return {
  112. 'id': content_id,
  113. 'title': title,
  114. 'thumbnail': thumbnail,
  115. 'timestamp': timestamp,
  116. 'uploader': uploader,
  117. 'uploader_id': uploader_id,
  118. 'duration': duration,
  119. 'view_count': view_count,
  120. 'formats': formats,
  121. }