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.

89 lines
3.0 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. },
  24. {
  25. 'url': 'http://my.mail.ru/corp/hitech/video/news_hi-tech_mail_ru/1263.html',
  26. 'md5': '00a91a58c3402204dcced523777b475f',
  27. 'info_dict': {
  28. 'id': '46843144_1263',
  29. 'ext': 'mp4',
  30. 'title': 'Samsung Galaxy S5 Hammer Smash Fail Battery Explosion',
  31. 'timestamp': 1397217632,
  32. 'upload_date': '20140411',
  33. 'uploader': 'hitech',
  34. 'uploader_id': 'hitech@corp.mail.ru',
  35. 'duration': 245,
  36. },
  37. },
  38. ]
  39. def _real_extract(self, url):
  40. mobj = re.match(self._VALID_URL, url)
  41. video_id = mobj.group('idv1')
  42. if not video_id:
  43. video_id = mobj.group('idv2prefix') + mobj.group('idv2suffix')
  44. video_data = self._download_json(
  45. 'http://api.video.mail.ru/videos/%s.json?new=1' % video_id, video_id, 'Downloading video JSON')
  46. author = video_data['author']
  47. uploader = author['name']
  48. uploader_id = author.get('id') or author.get('email')
  49. view_count = video_data.get('views_count')
  50. meta_data = video_data['meta']
  51. content_id = '%s_%s' % (
  52. meta_data.get('accId', ''), meta_data['itemId'])
  53. title = meta_data['title']
  54. if title.endswith('.mp4'):
  55. title = title[:-4]
  56. thumbnail = meta_data['poster']
  57. duration = meta_data['duration']
  58. timestamp = meta_data['timestamp']
  59. formats = [
  60. {
  61. 'url': video['url'],
  62. 'format_id': video['key'],
  63. 'height': int(video['key'].rstrip('p'))
  64. } for video in video_data['videos']
  65. ]
  66. self._sort_formats(formats)
  67. return {
  68. 'id': content_id,
  69. 'title': title,
  70. 'thumbnail': thumbnail,
  71. 'timestamp': timestamp,
  72. 'uploader': uploader,
  73. 'uploader_id': uploader_id,
  74. 'duration': duration,
  75. 'view_count': view_count,
  76. 'formats': formats,
  77. }