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.

70 lines
2.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. dict_get,
  6. int_or_none,
  7. )
  8. class KinoPoiskIE(InfoExtractor):
  9. _GEO_COUNTRIES = ['RU']
  10. _VALID_URL = r'https?://(?:www\.)?kinopoisk\.ru/film/(?P<id>\d+)'
  11. _TESTS = [{
  12. 'url': 'https://www.kinopoisk.ru/film/81041/watch/',
  13. 'md5': '4f71c80baea10dfa54a837a46111d326',
  14. 'info_dict': {
  15. 'id': '81041',
  16. 'ext': 'mp4',
  17. 'title': 'Алеша попович и тугарин змей',
  18. 'description': 'md5:43787e673d68b805d0aa1df5a5aea701',
  19. 'thumbnail': r're:^https?://.*',
  20. 'duration': 4533,
  21. 'age_limit': 12,
  22. },
  23. 'params': {
  24. 'format': 'bestvideo',
  25. },
  26. }, {
  27. 'url': 'https://www.kinopoisk.ru/film/81041',
  28. 'only_matching': True,
  29. }]
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(
  33. 'https://ott-widget.kinopoisk.ru/v1/kp/', video_id,
  34. query={'kpId': video_id})
  35. data = self._parse_json(
  36. self._search_regex(
  37. r'(?s)<script[^>]+\btype=["\']application/json[^>]+>(.+?)<',
  38. webpage, 'data'),
  39. video_id)['models']
  40. film = data['filmStatus']
  41. title = film.get('title') or film['originalTitle']
  42. formats = self._extract_m3u8_formats(
  43. data['playlistEntity']['uri'], video_id, 'mp4',
  44. entry_protocol='m3u8_native', m3u8_id='hls')
  45. self._sort_formats(formats)
  46. description = dict_get(
  47. film, ('descriptscription', 'description',
  48. 'shortDescriptscription', 'shortDescription'))
  49. thumbnail = film.get('coverUrl') or film.get('posterUrl')
  50. duration = int_or_none(film.get('duration'))
  51. age_limit = int_or_none(film.get('restrictionAge'))
  52. return {
  53. 'id': video_id,
  54. 'title': title,
  55. 'description': description,
  56. 'thumbnail': thumbnail,
  57. 'duration': duration,
  58. 'age_limit': age_limit,
  59. 'formats': formats,
  60. }