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.

86 lines
2.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. unified_strdate,
  6. int_or_none,
  7. qualities,
  8. unescapeHTML,
  9. )
  10. class OdnoklassnikiIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:odnoklassniki|ok)\.ru/(?:video|web-api/video/moviePlayer)/(?P<id>\d+)'
  12. _TESTS = [{
  13. 'url': 'http://ok.ru/video/20079905452',
  14. 'md5': '8e24ad2da6f387948e7a7d44eb8668fe',
  15. 'info_dict': {
  16. 'id': '20079905452',
  17. 'ext': 'mp4',
  18. 'title': 'Культура меняет нас (прекрасный ролик!))',
  19. 'duration': 100,
  20. 'upload_date': '20141207',
  21. 'uploader_id': '330537914540',
  22. 'uploader': 'Виталий Добровольский',
  23. 'like_count': int,
  24. 'age_limit': 0,
  25. },
  26. }, {
  27. 'url': 'http://ok.ru/web-api/video/moviePlayer/20079905452',
  28. 'only_matching': True,
  29. }]
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(url, video_id)
  33. player = self._parse_json(
  34. unescapeHTML(self._search_regex(
  35. r'data-attributes="([^"]+)"', webpage, 'player')),
  36. video_id)
  37. metadata = self._parse_json(player['flashvars']['metadata'], video_id)
  38. movie = metadata['movie']
  39. title = movie['title']
  40. thumbnail = movie.get('poster')
  41. duration = int_or_none(movie.get('duration'))
  42. author = metadata.get('author', {})
  43. uploader_id = author.get('id')
  44. uploader = author.get('name')
  45. upload_date = unified_strdate(self._html_search_meta(
  46. 'ya:ovs:upload_date', webpage, 'upload date'))
  47. age_limit = None
  48. adult = self._html_search_meta(
  49. 'ya:ovs:adult', webpage, 'age limit')
  50. if adult:
  51. age_limit = 18 if adult == 'true' else 0
  52. like_count = int_or_none(metadata.get('likeCount'))
  53. quality = qualities(('mobile', 'lowest', 'low', 'sd', 'hd'))
  54. formats = [{
  55. 'url': f['url'],
  56. 'ext': 'mp4',
  57. 'format_id': f['name'],
  58. 'quality': quality(f['name']),
  59. } for f in metadata['videos']]
  60. return {
  61. 'id': video_id,
  62. 'title': title,
  63. 'thumbnail': thumbnail,
  64. 'duration': duration,
  65. 'upload_date': upload_date,
  66. 'uploader': uploader,
  67. 'uploader_id': uploader_id,
  68. 'like_count': like_count,
  69. 'age_limit': age_limit,
  70. 'formats': formats,
  71. }