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

banbye.py (8969B)


  1. import math
  2. import urllib.parse
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. InAdvancePagedList,
  6. determine_ext,
  7. format_field,
  8. int_or_none,
  9. join_nonempty,
  10. traverse_obj,
  11. unified_timestamp,
  12. url_or_none,
  13. )
  14. class BanByeBaseIE(InfoExtractor):
  15. _API_BASE = 'https://api.banbye.com'
  16. _CDN_BASE = 'https://cdn.banbye.com'
  17. _VIDEO_BASE = 'https://banbye.com/watch'
  18. @staticmethod
  19. def _extract_playlist_id(url, param='playlist'):
  20. return urllib.parse.parse_qs(
  21. urllib.parse.urlparse(url).query).get(param, [None])[0]
  22. def _extract_playlist(self, playlist_id):
  23. data = self._download_json(f'{self._API_BASE}/playlists/{playlist_id}', playlist_id)
  24. return self.playlist_result([
  25. self.url_result(f'{self._VIDEO_BASE}/{video_id}', BanByeIE)
  26. for video_id in data['videoIds']], playlist_id, data.get('name'))
  27. class BanByeIE(BanByeBaseIE):
  28. _VALID_URL = r'https?://(?:www\.)?banbye\.com/(?:en/)?watch/(?P<id>[\w-]+)'
  29. _TESTS = [{
  30. # ['src']['mp4']['levels'] direct mp4 urls only
  31. 'url': 'https://banbye.com/watch/v_ytfmvkVYLE8T',
  32. 'md5': '2f4ea15c5ca259a73d909b2cfd558eb5',
  33. 'info_dict': {
  34. 'id': 'v_ytfmvkVYLE8T',
  35. 'ext': 'mp4',
  36. 'title': 'md5:5ec098f88a0d796f987648de6322ba0f',
  37. 'description': 'md5:4d94836e73396bc18ef1fa0f43e5a63a',
  38. 'uploader': 'wRealu24',
  39. 'channel_id': 'ch_wrealu24',
  40. 'channel_url': 'https://banbye.com/channel/ch_wrealu24',
  41. 'timestamp': 1647604800,
  42. 'upload_date': '20220318',
  43. 'duration': 1931,
  44. 'thumbnail': r're:https?://.*\.webp',
  45. 'tags': 'count:5',
  46. 'like_count': int,
  47. 'dislike_count': int,
  48. 'view_count': int,
  49. 'comment_count': int,
  50. },
  51. }, {
  52. 'url': 'https://banbye.com/watch/v_2JjQtqjKUE_F?playlistId=p_Ld82N6gBw_OJ',
  53. 'info_dict': {
  54. 'title': 'Krzysztof Karoń',
  55. 'id': 'p_Ld82N6gBw_OJ',
  56. },
  57. 'playlist_mincount': 9,
  58. }, {
  59. # ['src']['mp4']['levels'] direct mp4 urls only
  60. 'url': 'https://banbye.com/watch/v_kb6_o1Kyq-CD',
  61. 'info_dict': {
  62. 'id': 'v_kb6_o1Kyq-CD',
  63. 'ext': 'mp4',
  64. 'title': 'Co tak naprawdę dzieje się we Francji?! Czy Warszawa a potem cała Polska będzie drugim Paryżem?!🤔🇵🇱',
  65. 'description': 'md5:82be4c0e13eae8ea1ca8b9f2e07226a8',
  66. 'uploader': 'Marcin Rola - MOIM ZDANIEM!🇵🇱',
  67. 'channel_id': 'ch_QgWnHvDG2fo5',
  68. 'channel_url': 'https://banbye.com/channel/ch_QgWnHvDG2fo5',
  69. 'duration': 597,
  70. 'timestamp': 1688642656,
  71. 'upload_date': '20230706',
  72. 'thumbnail': 'https://cdn.banbye.com/video/v_kb6_o1Kyq-CD/96.webp',
  73. 'tags': ['Paryż', 'Francja', 'Polska', 'Imigranci', 'Morawiecki', 'Tusk'],
  74. 'like_count': int,
  75. 'dislike_count': int,
  76. 'view_count': int,
  77. 'comment_count': int,
  78. },
  79. }, {
  80. # ['src']['hls']['levels'] variant m3u8 urls only; master m3u8 is 404
  81. 'url': 'https://banbye.com/watch/v_a_gPFuC9LoW5',
  82. 'info_dict': {
  83. 'id': 'v_a_gPFuC9LoW5',
  84. 'ext': 'mp4',
  85. 'title': 'md5:183524056bebdfa245fd6d214f63c0fe',
  86. 'description': 'md5:943ac87287ca98d28d8b8797719827c6',
  87. 'uploader': 'wRealu24',
  88. 'channel_id': 'ch_wrealu24',
  89. 'channel_url': 'https://banbye.com/channel/ch_wrealu24',
  90. 'upload_date': '20231113',
  91. 'timestamp': 1699874062,
  92. 'view_count': int,
  93. 'like_count': int,
  94. 'dislike_count': int,
  95. 'comment_count': int,
  96. 'thumbnail': 'https://cdn.banbye.com/video/v_a_gPFuC9LoW5/96.webp',
  97. 'tags': ['jaszczur', 'sejm', 'lewica', 'polska', 'ukrainizacja', 'pierwszeposiedzeniesejmu'],
  98. },
  99. 'expected_warnings': ['Failed to download m3u8'],
  100. }, {
  101. # ['src']['hls']['masterPlaylist'] m3u8 only
  102. 'url': 'https://banbye.com/watch/v_B0rsKWsr-aaa',
  103. 'info_dict': {
  104. 'id': 'v_B0rsKWsr-aaa',
  105. 'ext': 'mp4',
  106. 'title': 'md5:00b254164b82101b3f9e5326037447ed',
  107. 'description': 'md5:3fd8b48aa81954ba024bc60f5de6e167',
  108. 'uploader': 'PSTV Piotr Szlachtowicz ',
  109. 'channel_id': 'ch_KV9EVObkB9wB',
  110. 'channel_url': 'https://banbye.com/channel/ch_KV9EVObkB9wB',
  111. 'upload_date': '20240629',
  112. 'timestamp': 1719646816,
  113. 'duration': 2377,
  114. 'view_count': int,
  115. 'like_count': int,
  116. 'dislike_count': int,
  117. 'comment_count': int,
  118. 'thumbnail': 'https://cdn.banbye.com/video/v_B0rsKWsr-aaa/96.webp',
  119. 'tags': ['Biden', 'Trump', 'Wybory', 'USA'],
  120. },
  121. }]
  122. def _real_extract(self, url):
  123. video_id = self._match_id(url)
  124. playlist_id = self._extract_playlist_id(url, 'playlistId')
  125. if self._yes_playlist(playlist_id, video_id):
  126. return self._extract_playlist(playlist_id)
  127. data = self._download_json(f'{self._API_BASE}/videos/{video_id}', video_id)
  128. thumbnails = [{
  129. 'id': f'{quality}p',
  130. 'url': f'{self._CDN_BASE}/video/{video_id}/{quality}.webp',
  131. } for quality in [48, 96, 144, 240, 512, 1080]]
  132. formats = []
  133. url_data = self._download_json(f'{self._API_BASE}/videos/{video_id}/url', video_id, data=b'')
  134. if master_url := traverse_obj(url_data, ('src', 'hls', 'masterPlaylist', {url_or_none})):
  135. formats = self._extract_m3u8_formats(master_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
  136. for format_id, format_url in traverse_obj(url_data, (
  137. 'src', ('mp4', 'hls'), 'levels', {dict.items}, lambda _, v: url_or_none(v[1]))):
  138. ext = determine_ext(format_url)
  139. is_hls = ext == 'm3u8'
  140. formats.append({
  141. 'url': format_url,
  142. 'ext': 'mp4' if is_hls else ext,
  143. 'format_id': join_nonempty(is_hls and 'hls', format_id),
  144. 'protocol': 'm3u8_native' if is_hls else 'https',
  145. 'height': int_or_none(format_id),
  146. })
  147. self._remove_duplicate_formats(formats)
  148. return {
  149. 'id': video_id,
  150. 'title': data.get('title'),
  151. 'description': data.get('desc'),
  152. 'uploader': traverse_obj(data, ('channel', 'name')),
  153. 'channel_id': data.get('channelId'),
  154. 'channel_url': format_field(data, 'channelId', 'https://banbye.com/channel/%s'),
  155. 'timestamp': unified_timestamp(data.get('publishedAt')),
  156. 'duration': data.get('duration'),
  157. 'tags': data.get('tags'),
  158. 'formats': formats,
  159. 'thumbnails': thumbnails,
  160. 'like_count': data.get('likes'),
  161. 'dislike_count': data.get('dislikes'),
  162. 'view_count': data.get('views'),
  163. 'comment_count': data.get('commentCount'),
  164. }
  165. class BanByeChannelIE(BanByeBaseIE):
  166. _VALID_URL = r'https?://(?:www\.)?banbye\.com/(?:en/)?channel/(?P<id>\w+)'
  167. _TESTS = [{
  168. 'url': 'https://banbye.com/channel/ch_wrealu24',
  169. 'info_dict': {
  170. 'title': 'wRealu24',
  171. 'id': 'ch_wrealu24',
  172. 'description': 'md5:da54e48416b74dfdde20a04867c0c2f6',
  173. },
  174. 'playlist_mincount': 791,
  175. }, {
  176. 'url': 'https://banbye.com/channel/ch_wrealu24?playlist=p_Ld82N6gBw_OJ',
  177. 'info_dict': {
  178. 'title': 'Krzysztof Karoń',
  179. 'id': 'p_Ld82N6gBw_OJ',
  180. },
  181. 'playlist_count': 9,
  182. }]
  183. _PAGE_SIZE = 100
  184. def _real_extract(self, url):
  185. channel_id = self._match_id(url)
  186. playlist_id = self._extract_playlist_id(url)
  187. if playlist_id:
  188. return self._extract_playlist(playlist_id)
  189. def page_func(page_num):
  190. data = self._download_json(f'{self._API_BASE}/videos', channel_id, query={
  191. 'channelId': channel_id,
  192. 'sort': 'new',
  193. 'limit': self._PAGE_SIZE,
  194. 'offset': page_num * self._PAGE_SIZE,
  195. }, note=f'Downloading page {page_num + 1}')
  196. return [
  197. self.url_result(f"{self._VIDEO_BASE}/{video['_id']}", BanByeIE)
  198. for video in data['items']
  199. ]
  200. channel_data = self._download_json(f'{self._API_BASE}/channels/{channel_id}', channel_id)
  201. entries = InAdvancePagedList(
  202. page_func,
  203. math.ceil(channel_data['videoCount'] / self._PAGE_SIZE),
  204. self._PAGE_SIZE)
  205. return self.playlist_result(
  206. entries, channel_id, channel_data.get('name'), channel_data.get('description'))