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.

91 lines
3.1 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class MailRuIE(InfoExtractor):
  6. IE_NAME = 'mailru'
  7. IE_DESC = 'Видео@Mail.Ru'
  8. _VALID_URL = r'http://(?:www\.)?my\.mail\.ru/(?:video/.*#video=/?(?P<idv1>(?:[^/]+/){3}\d+)|(?:(?P<idv2prefix>(?:[^/]+/){2})video/(?P<idv2suffix>[^/]+/\d+))\.html)'
  9. _TESTS = [
  10. {
  11. 'url': 'http://my.mail.ru/video/top#video=/mail/sonypicturesrus/75/76',
  12. 'md5': 'dea205f03120046894db4ebb6159879a',
  13. 'info_dict': {
  14. 'id': '46301138_76',
  15. 'ext': 'mp4',
  16. 'title': 'Новый Человек-Паук. Высокое напряжение. Восстание Электро',
  17. 'timestamp': 1393232740,
  18. 'upload_date': '20140224',
  19. 'uploader': 'sonypicturesrus',
  20. 'uploader_id': 'sonypicturesrus@mail.ru',
  21. 'duration': 184,
  22. },
  23. 'skip': 'Not accessible from Travis CI server',
  24. },
  25. {
  26. 'url': 'http://my.mail.ru/corp/hitech/video/news_hi-tech_mail_ru/1263.html',
  27. 'md5': '00a91a58c3402204dcced523777b475f',
  28. 'info_dict': {
  29. 'id': '46843144_1263',
  30. 'ext': 'mp4',
  31. 'title': 'Samsung Galaxy S5 Hammer Smash Fail Battery Explosion',
  32. 'timestamp': 1397217632,
  33. 'upload_date': '20140411',
  34. 'uploader': 'hitech',
  35. 'uploader_id': 'hitech@corp.mail.ru',
  36. 'duration': 245,
  37. },
  38. 'skip': 'Not accessible from Travis CI server',
  39. },
  40. ]
  41. def _real_extract(self, url):
  42. mobj = re.match(self._VALID_URL, url)
  43. video_id = mobj.group('idv1')
  44. if not video_id:
  45. video_id = mobj.group('idv2prefix') + mobj.group('idv2suffix')
  46. video_data = self._download_json(
  47. 'http://api.video.mail.ru/videos/%s.json?new=1' % video_id, video_id, 'Downloading video JSON')
  48. author = video_data['author']
  49. uploader = author['name']
  50. uploader_id = author.get('id') or author.get('email')
  51. view_count = video_data.get('views_count')
  52. meta_data = video_data['meta']
  53. content_id = '%s_%s' % (
  54. meta_data.get('accId', ''), meta_data['itemId'])
  55. title = meta_data['title']
  56. if title.endswith('.mp4'):
  57. title = title[:-4]
  58. thumbnail = meta_data['poster']
  59. duration = meta_data['duration']
  60. timestamp = meta_data['timestamp']
  61. formats = [
  62. {
  63. 'url': video['url'],
  64. 'format_id': video['key'],
  65. 'height': int(video['key'].rstrip('p'))
  66. } for video in video_data['videos']
  67. ]
  68. self._sort_formats(formats)
  69. return {
  70. 'id': content_id,
  71. 'title': title,
  72. 'thumbnail': thumbnail,
  73. 'timestamp': timestamp,
  74. 'uploader': uploader,
  75. 'uploader_id': uploader_id,
  76. 'duration': duration,
  77. 'view_count': view_count,
  78. 'formats': formats,
  79. }