gronkh.py 3.9 KB

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