logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

duoplay.py (5437B)


  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. parse_qs,
  9. str_or_none,
  10. try_call,
  11. unified_timestamp,
  12. )
  13. from ..utils.traversal import traverse_obj, value
  14. class DuoplayIE(InfoExtractor):
  15. _VALID_URL = r'https?://duoplay\.ee/(?P<id>\d+)(?:[/?#]|$)'
  16. _TESTS = [{
  17. 'note': 'Siberi võmm S02E12',
  18. 'url': 'https://duoplay.ee/4312/siberi-vomm?ep=24',
  19. 'md5': '1ff59d535310ac9c5cf5f287d8f91b2d',
  20. 'info_dict': {
  21. 'id': '4312_24',
  22. 'ext': 'mp4',
  23. 'title': 'Operatsioon "Öö"',
  24. 'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
  25. 'description': 'md5:8ef98f38569d6b8b78f3d350ccc6ade8',
  26. 'upload_date': '20170523',
  27. 'timestamp': 1495567800,
  28. 'series': 'Siberi võmm',
  29. 'series_id': '4312',
  30. 'season': 'Season 2',
  31. 'season_number': 2,
  32. 'episode': 'Operatsioon "Öö"',
  33. 'episode_number': 12,
  34. 'episode_id': '24',
  35. },
  36. 'skip': 'No video found',
  37. }, {
  38. 'note': 'Empty title',
  39. 'url': 'https://duoplay.ee/17/uhikarotid?ep=14',
  40. 'md5': 'cba9f5dabf2582b224d80ac44fb80e47',
  41. 'info_dict': {
  42. 'id': '17_14',
  43. 'ext': 'mp4',
  44. 'title': 'Episode 14',
  45. 'thumbnail': r're:https?://.+\.jpg',
  46. 'description': 'md5:4719b418e058c209def41d48b601276e',
  47. 'upload_date': '20100916',
  48. 'timestamp': 1284661800,
  49. 'series': 'Ühikarotid',
  50. 'series_id': '17',
  51. 'season': 'Season 2',
  52. 'season_number': 2,
  53. 'episode_id': '14',
  54. 'release_year': 2010,
  55. 'episode': 'Episode 14',
  56. 'episode_number': 14,
  57. },
  58. }, {
  59. 'note': 'Movie without expiry',
  60. 'url': 'https://duoplay.ee/5501/pilvede-all.-neljas-ode',
  61. 'md5': '7abf63d773a49ef7c39f2c127842b8fd',
  62. 'info_dict': {
  63. 'id': '5501',
  64. 'ext': 'mp4',
  65. 'title': 'Pilvede all. Neljas õde',
  66. 'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
  67. 'description': 'md5:d86a70f8f31e82c369d4d4f4c79b1279',
  68. 'cast': 'count:9',
  69. 'upload_date': '20221214',
  70. 'timestamp': 1671054000,
  71. 'release_year': 2018,
  72. },
  73. 'skip': 'No video found',
  74. }, {
  75. 'note': 'Episode url without show name',
  76. 'url': 'https://duoplay.ee/9644?ep=185',
  77. 'md5': '63f324b4fe2dbd8194dca16a6d52184a',
  78. 'info_dict': {
  79. 'id': '9644_185',
  80. 'ext': 'mp4',
  81. 'title': 'Episode 185',
  82. 'thumbnail': r're:https?://.+\.jpg',
  83. 'description': 'md5:ed25ba4e9e5d54bc291a4a0cdd241467',
  84. 'upload_date': '20241120',
  85. 'timestamp': 1732077000,
  86. 'episode': 'Episode 63',
  87. 'episode_id': '185',
  88. 'episode_number': 63,
  89. 'season': 'Season 2',
  90. 'season_number': 2,
  91. 'series': 'Telehommik',
  92. 'series_id': '9644',
  93. },
  94. }]
  95. def _real_extract(self, url):
  96. telecast_id = self._match_id(url)
  97. episode = traverse_obj(parse_qs(url), ('ep', 0, {int_or_none}, {str_or_none}))
  98. video_id = join_nonempty(telecast_id, episode, delim='_')
  99. webpage = self._download_webpage(url, video_id)
  100. video_player = try_call(lambda: extract_attributes(
  101. get_element_text_and_html_by_tag('video-player', webpage)[1]))
  102. if not video_player or not video_player.get('manifest-url'):
  103. raise ExtractorError('No video found', expected=True)
  104. manifest_url = video_player['manifest-url']
  105. session_token = self._download_json(
  106. 'https://sts.postimees.ee/session/register', video_id, 'Registering session',
  107. 'Unable to register session', headers={
  108. 'Accept': 'application/json',
  109. 'X-Original-URI': manifest_url,
  110. })['session']
  111. episode_attr = self._parse_json(video_player.get(':episode') or '', video_id, fatal=False) or {}
  112. return {
  113. 'id': video_id,
  114. 'formats': self._extract_m3u8_formats(manifest_url, video_id, 'mp4', query={'s': session_token}),
  115. **traverse_obj(episode_attr, {
  116. 'title': ('title', {str}),
  117. 'description': ('synopsis', {str}),
  118. 'thumbnail': ('images', 'original'),
  119. 'timestamp': ('airtime', {lambda x: unified_timestamp(x + ' +0200')}),
  120. 'cast': ('cast', filter, {lambda x: x.split(', ')}),
  121. 'release_year': ('year', {int_or_none}),
  122. }),
  123. **(traverse_obj(episode_attr, {
  124. 'title': (None, (('subtitle', {str}, filter), {value(f'Episode {episode}' if episode else None)})),
  125. 'series': ('title', {str}),
  126. 'series_id': ('telecast_id', {str_or_none}),
  127. 'season_number': ('season_id', {int_or_none}),
  128. 'episode': ('subtitle', {str}, filter),
  129. 'episode_number': ('episode_nr', {int_or_none}),
  130. 'episode_id': ('episode_id', {str_or_none}),
  131. }, get_all=False) if episode_attr.get('category') != 'movies' else {}),
  132. }