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.

64 lines
2.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<id>[^/]+/[^/]+/[^/]+/\d+)'
  9. _TEST = {
  10. 'url': 'http://my.mail.ru/video/top#video=/mail/sonypicturesrus/75/76',
  11. 'md5': 'dea205f03120046894db4ebb6159879a',
  12. 'info_dict': {
  13. 'id': '46301138',
  14. 'ext': 'mp4',
  15. 'title': 'Новый Человек-Паук. Высокое напряжение. Восстание Электро',
  16. 'timestamp': 1393232740,
  17. 'upload_date': '20140224',
  18. 'uploader': 'sonypicturesrus',
  19. 'uploader_id': 'sonypicturesrus@mail.ru',
  20. 'duration': 184,
  21. }
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. video_data = self._download_json(
  27. 'http://videoapi.my.mail.ru/videos/%s.json?new=1' % video_id, video_id, 'Downloading video JSON')
  28. author = video_data['author']
  29. uploader = author['name']
  30. uploader_id = author['id']
  31. movie = video_data['movie']
  32. content_id = str(movie['contentId'])
  33. title = movie['title']
  34. thumbnail = movie['poster']
  35. duration = movie['duration']
  36. view_count = video_data['views_count']
  37. formats = [
  38. {
  39. 'url': video['url'],
  40. 'format_id': video['name'],
  41. } for video in video_data['videos']
  42. ]
  43. return {
  44. 'id': content_id,
  45. 'title': title,
  46. 'thumbnail': thumbnail,
  47. 'timestamp': video_data['timestamp'],
  48. 'uploader': uploader,
  49. 'uploader_id': uploader_id,
  50. 'duration': duration,
  51. 'view_count': view_count,
  52. 'formats': formats,
  53. }