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.

65 lines
2.0 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import datetime
  5. from .common import InfoExtractor
  6. class MailRuIE(InfoExtractor):
  7. IE_NAME = 'mailru'
  8. IE_DESC = 'Видео@Mail.Ru'
  9. _VALID_URL = r'http://(?:www\.)?my\.mail\.ru/video/.*#video=/?(?P<id>[^/]+/[^/]+/[^/]+/\d+)'
  10. _TEST = {
  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. '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. upload_date = datetime.datetime.fromtimestamp(video_data['timestamp']).strftime('%Y%m%d')
  37. view_count = video_data['views_count']
  38. formats = [
  39. {
  40. 'url': video['url'],
  41. 'format_id': video['name'],
  42. } for video in video_data['videos']
  43. ]
  44. return {
  45. 'id': content_id,
  46. 'title': title,
  47. 'thumbnail': thumbnail,
  48. 'upload_date': upload_date,
  49. 'uploader': uploader,
  50. 'uploader_id': uploader_id,
  51. 'duration': duration,
  52. 'view_count': view_count,
  53. 'formats': formats,
  54. }