duoplay.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. extract_attributes,
  5. get_element_text_and_html_by_tag,
  6. int_or_none,
  7. join_nonempty,
  8. str_or_none,
  9. try_call,
  10. unified_timestamp,
  11. )
  12. from ..utils.traversal import traverse_obj
  13. class DuoplayIE(InfoExtractor):
  14. _VALID_URL = r'https?://duoplay\.ee/(?P<id>\d+)/[\w-]+/?(?:\?(?:[^#]+&)?ep=(?P<ep>\d+))?'
  15. _TESTS = [{
  16. 'note': 'Siberi võmm S02E12',
  17. 'url': 'https://duoplay.ee/4312/siberi-vomm?ep=24',
  18. 'md5': '1ff59d535310ac9c5cf5f287d8f91b2d',
  19. 'info_dict': {
  20. 'id': '4312_24',
  21. 'ext': 'mp4',
  22. 'title': 'Operatsioon "Öö"',
  23. 'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
  24. 'description': 'md5:8ef98f38569d6b8b78f3d350ccc6ade8',
  25. 'upload_date': '20170523',
  26. 'timestamp': 1495567800,
  27. 'series': 'Siberi võmm',
  28. 'series_id': '4312',
  29. 'season': 'Season 2',
  30. 'season_number': 2,
  31. 'episode': 'Operatsioon "Öö"',
  32. 'episode_number': 12,
  33. 'episode_id': '24',
  34. },
  35. }, {
  36. 'note': 'Empty title',
  37. 'url': 'https://duoplay.ee/17/uhikarotid?ep=14',
  38. 'md5': '6aca68be71112314738dd17cced7f8bf',
  39. 'info_dict': {
  40. 'id': '17_14',
  41. 'ext': 'mp4',
  42. 'title': 'Ühikarotid',
  43. 'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
  44. 'description': 'md5:4719b418e058c209def41d48b601276e',
  45. 'upload_date': '20100916',
  46. 'timestamp': 1284661800,
  47. 'series': 'Ühikarotid',
  48. 'series_id': '17',
  49. 'season': 'Season 2',
  50. 'season_number': 2,
  51. 'episode_id': '14',
  52. 'release_year': 2010,
  53. },
  54. }, {
  55. 'note': 'Movie without expiry',
  56. 'url': 'https://duoplay.ee/5501/pilvede-all.-neljas-ode',
  57. 'md5': '7abf63d773a49ef7c39f2c127842b8fd',
  58. 'info_dict': {
  59. 'id': '5501',
  60. 'ext': 'mp4',
  61. 'title': 'Pilvede all. Neljas õde',
  62. 'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
  63. 'description': 'md5:d86a70f8f31e82c369d4d4f4c79b1279',
  64. 'cast': 'count:9',
  65. 'upload_date': '20221214',
  66. 'timestamp': 1671054000,
  67. 'release_year': 2018,
  68. },
  69. }]
  70. def _real_extract(self, url):
  71. telecast_id, episode = self._match_valid_url(url).group('id', 'ep')
  72. video_id = join_nonempty(telecast_id, episode, delim='_')
  73. webpage = self._download_webpage(url, video_id)
  74. video_player = try_call(lambda: extract_attributes(
  75. get_element_text_and_html_by_tag('video-player', webpage)[1]))
  76. if not video_player or not video_player.get('manifest-url'):
  77. raise ExtractorError('No video found', expected=True)
  78. episode_attr = self._parse_json(video_player.get(':episode') or '', video_id, fatal=False) or {}
  79. return {
  80. 'id': video_id,
  81. 'formats': self._extract_m3u8_formats(video_player['manifest-url'], video_id, 'mp4'),
  82. **traverse_obj(episode_attr, {
  83. 'title': 'title',
  84. 'description': 'synopsis',
  85. 'thumbnail': ('images', 'original'),
  86. 'timestamp': ('airtime', {lambda x: unified_timestamp(x + ' +0200')}),
  87. 'cast': ('cast', {lambda x: x.split(', ')}),
  88. 'release_year': ('year', {int_or_none}),
  89. }),
  90. **(traverse_obj(episode_attr, {
  91. 'title': (None, ('subtitle', ('episode_nr', {lambda x: f'Episode {x}' if x else None}))),
  92. 'series': 'title',
  93. 'series_id': ('telecast_id', {str_or_none}),
  94. 'season_number': ('season_id', {int_or_none}),
  95. 'episode': 'subtitle',
  96. 'episode_number': ('episode_nr', {int_or_none}),
  97. 'episode_id': ('episode_id', {str_or_none}),
  98. }, get_all=False) if episode_attr.get('category') != 'movies' else {}),
  99. }