gronkh.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import functools
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. OnDemandPagedList,
  5. float_or_none,
  6. traverse_obj,
  7. unified_strdate,
  8. )
  9. class GronkhIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?gronkh\.tv/(?:watch/)?streams?/(?P<id>\d+)'
  11. _TESTS = [{
  12. 'url': 'https://gronkh.tv/streams/657',
  13. 'info_dict': {
  14. 'id': '657',
  15. 'ext': 'mp4',
  16. 'title': 'H.O.R.D.E. - DAS ZWEiTE ZEiTALTER 🎲 Session 1',
  17. 'view_count': int,
  18. 'thumbnail': 'https://01.cdn.vod.farm/preview/9e2555d3a23bf4e5c5b7c6b3b70a9d84.jpg',
  19. 'upload_date': '20221111',
  20. 'chapters': 'count:3',
  21. 'duration': 31463,
  22. },
  23. 'params': {'skip_download': True},
  24. }, {
  25. 'url': 'https://gronkh.tv/stream/536',
  26. 'info_dict': {
  27. 'id': '536',
  28. 'ext': 'mp4',
  29. 'title': 'GTV0536, 2021-10-01 - MARTHA IS DEAD #FREiAB1830 !FF7 !horde !archiv',
  30. 'view_count': int,
  31. 'thumbnail': 'https://01.cdn.vod.farm/preview/6436746cce14e25f751260a692872b9b.jpg',
  32. 'upload_date': '20211001',
  33. 'duration': 32058,
  34. },
  35. 'params': {'skip_download': True},
  36. }, {
  37. 'url': 'https://gronkh.tv/watch/stream/546',
  38. 'only_matching': True,
  39. }]
  40. def _real_extract(self, url):
  41. video_id = self._match_id(url)
  42. data_json = self._download_json(f'https://api.gronkh.tv/v1/video/info?episode={video_id}', video_id)
  43. m3u8_url = self._download_json(f'https://api.gronkh.tv/v1/video/playlist?episode={video_id}', video_id)['playlist_url']
  44. formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id)
  45. if data_json.get('vtt_url'):
  46. subtitles.setdefault('en', []).append({
  47. 'url': data_json['vtt_url'],
  48. 'ext': 'vtt',
  49. })
  50. return {
  51. 'id': video_id,
  52. 'title': data_json.get('title'),
  53. 'view_count': data_json.get('views'),
  54. 'thumbnail': data_json.get('preview_url'),
  55. 'upload_date': unified_strdate(data_json.get('created_at')),
  56. 'formats': formats,
  57. 'subtitles': subtitles,
  58. 'duration': float_or_none(data_json.get('source_length')),
  59. 'chapters': traverse_obj(data_json, (
  60. 'chapters', lambda _, v: float_or_none(v['offset']) is not None, {
  61. 'title': 'title',
  62. 'start_time': ('offset', {float_or_none}),
  63. })) or None,
  64. }
  65. class GronkhFeedIE(InfoExtractor):
  66. _VALID_URL = r'https?://(?:www\.)?gronkh\.tv(?:/feed)?/?(?:#|$)'
  67. IE_NAME = 'gronkh:feed'
  68. _TESTS = [{
  69. 'url': 'https://gronkh.tv/feed',
  70. 'info_dict': {
  71. 'id': 'feed',
  72. },
  73. 'playlist_count': 16,
  74. }, {
  75. 'url': 'https://gronkh.tv',
  76. 'only_matching': True,
  77. }]
  78. def _entries(self):
  79. for type_ in ('recent', 'views'):
  80. info = self._download_json(
  81. f'https://api.gronkh.tv/v1/video/discovery/{type_}', 'feed', note=f'Downloading {type_} API JSON')
  82. for item in traverse_obj(info, ('discovery', ...)) or []:
  83. yield self.url_result(f'https://gronkh.tv/watch/stream/{item["episode"]}', GronkhIE, item.get('title'))
  84. def _real_extract(self, url):
  85. return self.playlist_result(self._entries(), 'feed')
  86. class GronkhVodsIE(InfoExtractor):
  87. _VALID_URL = r'https?://(?:www\.)?gronkh\.tv/vods/streams/?(?:#|$)'
  88. IE_NAME = 'gronkh:vods'
  89. _TESTS = [{
  90. 'url': 'https://gronkh.tv/vods/streams',
  91. 'info_dict': {
  92. 'id': 'vods',
  93. },
  94. 'playlist_mincount': 150,
  95. }]
  96. _PER_PAGE = 25
  97. def _fetch_page(self, page):
  98. items = traverse_obj(self._download_json(
  99. 'https://api.gronkh.tv/v1/search', 'vods', query={'offset': self._PER_PAGE * page, 'first': self._PER_PAGE},
  100. note=f'Downloading stream video page {page + 1}'), ('results', 'videos', ...))
  101. for item in items or []:
  102. yield self.url_result(f'https://gronkh.tv/watch/stream/{item["episode"]}', GronkhIE, item['episode'], item.get('title'))
  103. def _real_extract(self, url):
  104. entries = OnDemandPagedList(functools.partial(self._fetch_page), self._PER_PAGE)
  105. return self.playlist_result(entries, 'vods')