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