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

bibeltv.py (6795B)


  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. clean_html,
  5. determine_ext,
  6. format_field,
  7. int_or_none,
  8. js_to_json,
  9. orderedSet,
  10. parse_iso8601,
  11. traverse_obj,
  12. url_or_none,
  13. )
  14. class BibelTVBaseIE(InfoExtractor):
  15. _GEO_COUNTRIES = ['AT', 'CH', 'DE']
  16. _GEO_BYPASS = False
  17. API_URL = 'https://www.bibeltv.de/mediathek/api'
  18. AUTH_TOKEN = 'j88bRXY8DsEqJ9xmTdWhrByVi5Hm'
  19. def _extract_formats_and_subtitles(self, data, crn_id, *, is_live=False):
  20. formats = []
  21. subtitles = {}
  22. for media_url in traverse_obj(data, (..., 'src', {url_or_none})):
  23. media_ext = determine_ext(media_url)
  24. if media_ext == 'm3u8':
  25. m3u8_formats, m3u8_subs = self._extract_m3u8_formats_and_subtitles(
  26. media_url, crn_id, live=is_live)
  27. formats.extend(m3u8_formats)
  28. subtitles.update(m3u8_subs)
  29. elif media_ext == 'mpd':
  30. mpd_formats, mpd_subs = self._extract_mpd_formats_and_subtitles(media_url, crn_id)
  31. formats.extend(mpd_formats)
  32. subtitles.update(mpd_subs)
  33. elif media_ext == 'mp4':
  34. formats.append({'url': media_url})
  35. else:
  36. self.report_warning(f'Unknown format {media_ext!r}')
  37. return formats, subtitles
  38. @staticmethod
  39. def _extract_base_info(data):
  40. return {
  41. 'id': data['crn'],
  42. **traverse_obj(data, {
  43. 'title': 'title',
  44. 'description': 'description',
  45. 'duration': ('duration', {int_or_none(scale=1000)}),
  46. 'timestamp': ('schedulingStart', {parse_iso8601}),
  47. 'season_number': 'seasonNumber',
  48. 'episode_number': 'episodeNumber',
  49. 'view_count': 'viewCount',
  50. 'like_count': 'likeCount',
  51. }),
  52. 'thumbnails': orderedSet(traverse_obj(data, ('images', ..., {
  53. 'url': ('url', {url_or_none}),
  54. }))),
  55. }
  56. def _extract_url_info(self, data):
  57. return {
  58. '_type': 'url',
  59. 'url': format_field(data, 'slug', 'https://www.bibeltv.de/mediathek/videos/%s'),
  60. **self._extract_base_info(data),
  61. }
  62. def _extract_video_info(self, data):
  63. crn_id = data['crn']
  64. if data.get('drm'):
  65. self.report_drm(crn_id)
  66. json_data = self._download_json(
  67. format_field(data, 'id', f'{self.API_URL}/video/%s'), crn_id,
  68. headers={'Authorization': self.AUTH_TOKEN}, fatal=False,
  69. errnote='No formats available') or {}
  70. formats, subtitles = self._extract_formats_and_subtitles(
  71. traverse_obj(json_data, ('video', 'videoUrls', ...)), crn_id)
  72. return {
  73. '_type': 'video',
  74. **self._extract_base_info(data),
  75. 'formats': formats,
  76. 'subtitles': subtitles,
  77. }
  78. class BibelTVVideoIE(BibelTVBaseIE):
  79. IE_DESC = 'BibelTV single video'
  80. _VALID_URL = r'https?://(?:www\.)?bibeltv\.de/mediathek/videos/(?P<id>\d+)[\w-]+'
  81. IE_NAME = 'bibeltv:video'
  82. _TESTS = [{
  83. 'url': 'https://www.bibeltv.de/mediathek/videos/344436-alte-wege',
  84. 'md5': 'ec1c07efe54353780512e8a4103b612e',
  85. 'info_dict': {
  86. 'id': '344436',
  87. 'ext': 'mp4',
  88. 'title': 'Alte Wege',
  89. 'description': 'md5:2f4eb7294c9797a47b8fd13cccca22e9',
  90. 'timestamp': 1677877071,
  91. 'duration': 150.0,
  92. 'upload_date': '20230303',
  93. 'thumbnail': r're:https://bibeltv\.imgix\.net/[\w-]+\.jpg',
  94. 'episode': 'Episode 1',
  95. 'episode_number': 1,
  96. 'view_count': int,
  97. 'like_count': int,
  98. },
  99. 'params': {
  100. 'format': '6',
  101. },
  102. }]
  103. def _real_extract(self, url):
  104. crn_id = self._match_id(url)
  105. video_data = traverse_obj(
  106. self._search_nextjs_data(self._download_webpage(url, crn_id), crn_id),
  107. ('props', 'pageProps', 'videoPageData', 'videos', 0, {dict}))
  108. if not video_data:
  109. raise ExtractorError('Missing video data.')
  110. return self._extract_video_info(video_data)
  111. class BibelTVSeriesIE(BibelTVBaseIE):
  112. IE_DESC = 'BibelTV series playlist'
  113. _VALID_URL = r'https?://(?:www\.)?bibeltv\.de/mediathek/serien/(?P<id>\d+)[\w-]+'
  114. IE_NAME = 'bibeltv:series'
  115. _TESTS = [{
  116. 'url': 'https://www.bibeltv.de/mediathek/serien/333485-ein-wunder-fuer-jeden-tag',
  117. 'playlist_mincount': 400,
  118. 'info_dict': {
  119. 'id': '333485',
  120. 'title': 'Ein Wunder für jeden Tag',
  121. 'description': 'Tägliche Kurzandacht mit Déborah Rosenkranz.',
  122. },
  123. }]
  124. def _real_extract(self, url):
  125. crn_id = self._match_id(url)
  126. webpage = self._download_webpage(url, crn_id)
  127. nextjs_data = self._search_nextjs_data(webpage, crn_id)
  128. series_data = traverse_obj(nextjs_data, ('props', 'pageProps', 'seriePageData', {dict}))
  129. if not series_data:
  130. raise ExtractorError('Missing series data.')
  131. return self.playlist_result(
  132. traverse_obj(series_data, ('videos', ..., {dict}, {self._extract_url_info})),
  133. crn_id, series_data.get('title'), clean_html(series_data.get('description')))
  134. class BibelTVLiveIE(BibelTVBaseIE):
  135. IE_DESC = 'BibelTV live program'
  136. _VALID_URL = r'https?://(?:www\.)?bibeltv\.de/livestreams/(?P<id>[\w-]+)'
  137. IE_NAME = 'bibeltv:live'
  138. _TESTS = [{
  139. 'url': 'https://www.bibeltv.de/livestreams/bibeltv/',
  140. 'info_dict': {
  141. 'id': 'bibeltv',
  142. 'ext': 'mp4',
  143. 'title': 're:Bibel TV',
  144. 'live_status': 'is_live',
  145. 'thumbnail': 'https://streampreview.bibeltv.de/bibeltv.webp',
  146. },
  147. 'params': {'skip_download': 'm3u8'},
  148. }, {
  149. 'url': 'https://www.bibeltv.de/livestreams/impuls/',
  150. 'only_matching': True,
  151. }]
  152. def _real_extract(self, url):
  153. stream_id = self._match_id(url)
  154. webpage = self._download_webpage(url, stream_id)
  155. stream_data = self._search_json(
  156. r'\\"video\\":', webpage, 'bibeltvData', stream_id,
  157. transform_source=lambda jstring: js_to_json(jstring.replace('\\"', '"')))
  158. formats, subtitles = self._extract_formats_and_subtitles(
  159. traverse_obj(stream_data, ('src', ...)), stream_id, is_live=True)
  160. return {
  161. 'id': stream_id,
  162. 'title': stream_data.get('title'),
  163. 'thumbnail': stream_data.get('poster'),
  164. 'is_live': True,
  165. 'formats': formats,
  166. 'subtitles': subtitles,
  167. }