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.

85 lines
2.8 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',
  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',
  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['id']
  49. movie = video_data['movie']
  50. content_id = str(movie['contentId'])
  51. title = movie['title']
  52. if title.endswith('.mp4'):
  53. title = title[:-4]
  54. thumbnail = movie['poster']
  55. duration = movie['duration']
  56. view_count = video_data['views_count']
  57. formats = [
  58. {
  59. 'url': video['url'],
  60. 'format_id': video['name'],
  61. } for video in video_data['videos']
  62. ]
  63. return {
  64. 'id': content_id,
  65. 'title': title,
  66. 'thumbnail': thumbnail,
  67. 'timestamp': video_data['timestamp'],
  68. 'uploader': uploader,
  69. 'uploader_id': uploader_id,
  70. 'duration': duration,
  71. 'view_count': view_count,
  72. 'formats': formats,
  73. }