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.

134 lines
4.8 KiB

  1. # encoding: 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'http://(?:www\.)?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. def _real_extract(self, url):
  62. mobj = re.match(self._VALID_URL, url)
  63. video_id = mobj.group('idv1')
  64. if not video_id:
  65. video_id = mobj.group('idv2prefix') + mobj.group('idv2suffix')
  66. webpage = self._download_webpage(url, video_id)
  67. video_data = None
  68. page_config = self._parse_json(self._search_regex(
  69. r'(?s)<script[^>]+class="sp-video__page-config"[^>]*>(.+?)</script>',
  70. webpage, 'page config', default='{}'), video_id, fatal=False)
  71. if page_config:
  72. meta_url = page_config.get('metaUrl') or page_config.get('video', {}).get('metaUrl')
  73. if meta_url:
  74. video_data = self._download_json(
  75. meta_url, video_id, 'Downloading video meta JSON', fatal=False)
  76. # Fallback old approach
  77. if not video_data:
  78. video_data = self._download_json(
  79. 'http://api.video.mail.ru/videos/%s.json?new=1' % video_id,
  80. video_id, 'Downloading video JSON')
  81. formats = []
  82. for f in video_data['videos']:
  83. video_url = f.get('url')
  84. if not video_url:
  85. continue
  86. format_id = f.get('key')
  87. height = int_or_none(self._search_regex(
  88. r'^(\d+)[pP]$', format_id, 'height', default=None)) if format_id else None
  89. formats.append({
  90. 'url': video_url,
  91. 'format_id': format_id,
  92. 'height': height,
  93. })
  94. self._sort_formats(formats)
  95. meta_data = video_data['meta']
  96. title = remove_end(meta_data['title'], '.mp4')
  97. author = video_data.get('author')
  98. uploader = author.get('name')
  99. uploader_id = author.get('id') or author.get('email')
  100. view_count = int_or_none(video_data.get('viewsCount') or video_data.get('views_count'))
  101. acc_id = meta_data.get('accId')
  102. item_id = meta_data.get('itemId')
  103. content_id = '%s_%s' % (acc_id, item_id) if acc_id and item_id else video_id
  104. thumbnail = meta_data.get('poster')
  105. duration = int_or_none(meta_data.get('duration'))
  106. timestamp = int_or_none(meta_data.get('timestamp'))
  107. return {
  108. 'id': content_id,
  109. 'title': title,
  110. 'thumbnail': thumbnail,
  111. 'timestamp': timestamp,
  112. 'uploader': uploader,
  113. 'uploader_id': uploader_id,
  114. 'duration': duration,
  115. 'view_count': view_count,
  116. 'formats': formats,
  117. }