kinopoisk.py 2.0 KB

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