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.

112 lines
3.5 KiB

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