4 from .common
import InfoExtractor
17 class BanByeBaseIE(InfoExtractor
):
18 _API_BASE
= 'https://api.banbye.com'
19 _CDN_BASE
= 'https://cdn.banbye.com'
20 _VIDEO_BASE
= 'https://banbye.com/watch'
23 def _extract_playlist_id(url
, param
='playlist'):
24 return urllib
.parse
.parse_qs(
25 urllib
.parse
.urlparse(url
).query
).get(param
, [None])[0]
27 def _extract_playlist(self
, playlist_id
):
28 data
= self
._download
_json
(f
'{self._API_BASE}/playlists/{playlist_id}', playlist_id
)
29 return self
.playlist_result([
30 self
.url_result(f
'{self._VIDEO_BASE}/{video_id}', BanByeIE
)
31 for video_id
in data
['videoIds']], playlist_id
, data
.get('name'))
34 class BanByeIE(BanByeBaseIE
):
35 _VALID_URL
= r
'https?://(?:www\.)?banbye\.com/(?:en/)?watch/(?P<id>[\w-]+)'
37 # ['src']['mp4']['levels'] direct mp4 urls only
38 'url': 'https://banbye.com/watch/v_ytfmvkVYLE8T',
39 'md5': '2f4ea15c5ca259a73d909b2cfd558eb5',
41 'id': 'v_ytfmvkVYLE8T',
43 'title': 'md5:5ec098f88a0d796f987648de6322ba0f',
44 'description': 'md5:4d94836e73396bc18ef1fa0f43e5a63a',
45 'uploader': 'wRealu24',
46 'channel_id': 'ch_wrealu24',
47 'channel_url': 'https://banbye.com/channel/ch_wrealu24',
48 'timestamp': 1647604800,
49 'upload_date': '20220318',
51 'thumbnail': r
're:https?://.*\.webp',
59 'url': 'https://banbye.com/watch/v_2JjQtqjKUE_F?playlistId=p_Ld82N6gBw_OJ',
61 'title': 'Krzysztof Karoń',
62 'id': 'p_Ld82N6gBw_OJ',
64 'playlist_mincount': 9,
66 # ['src']['mp4']['levels'] direct mp4 urls only
67 'url': 'https://banbye.com/watch/v_kb6_o1Kyq-CD',
69 'id': 'v_kb6_o1Kyq-CD',
71 'title': 'Co tak naprawdę dzieje się we Francji?! Czy Warszawa a potem cała Polska będzie drugim Paryżem?!🤔🇵🇱',
72 'description': 'md5:82be4c0e13eae8ea1ca8b9f2e07226a8',
73 'uploader': 'Marcin Rola - MOIM ZDANIEM!🇵🇱',
74 'channel_id': 'ch_QgWnHvDG2fo5',
75 'channel_url': 'https://banbye.com/channel/ch_QgWnHvDG2fo5',
77 'timestamp': 1688642656,
78 'upload_date': '20230706',
79 'thumbnail': 'https://cdn.banbye.com/video/v_kb6_o1Kyq-CD/96.webp',
80 'tags': ['Paryż', 'Francja', 'Polska', 'Imigranci', 'Morawiecki', 'Tusk'],
87 # ['src']['hls']['levels'] variant m3u8 urls only; master m3u8 is 404
88 'url': 'https://banbye.com/watch/v_a_gPFuC9LoW5',
90 'id': 'v_a_gPFuC9LoW5',
92 'title': 'md5:183524056bebdfa245fd6d214f63c0fe',
93 'description': 'md5:943ac87287ca98d28d8b8797719827c6',
94 'uploader': 'wRealu24',
95 'channel_id': 'ch_wrealu24',
96 'channel_url': 'https://banbye.com/channel/ch_wrealu24',
97 'upload_date': '20231113',
98 'timestamp': 1699874062,
101 'dislike_count': int,
102 'comment_count': int,
103 'thumbnail': 'https://cdn.banbye.com/video/v_a_gPFuC9LoW5/96.webp',
104 'tags': ['jaszczur', 'sejm', 'lewica', 'polska', 'ukrainizacja', 'pierwszeposiedzeniesejmu'],
106 'expected_warnings': ['Failed to download m3u8'],
108 # ['src']['hls']['masterPlaylist'] m3u8 only
109 'url': 'https://banbye.com/watch/v_B0rsKWsr-aaa',
111 'id': 'v_B0rsKWsr-aaa',
113 'title': 'md5:00b254164b82101b3f9e5326037447ed',
114 'description': 'md5:3fd8b48aa81954ba024bc60f5de6e167',
115 'uploader': 'PSTV Piotr Szlachtowicz ',
116 'channel_id': 'ch_KV9EVObkB9wB',
117 'channel_url': 'https://banbye.com/channel/ch_KV9EVObkB9wB',
118 'upload_date': '20240629',
119 'timestamp': 1719646816,
123 'dislike_count': int,
124 'comment_count': int,
125 'thumbnail': 'https://cdn.banbye.com/video/v_B0rsKWsr-aaa/96.webp',
126 'tags': ['Biden', 'Trump', 'Wybory', 'USA'],
130 def _real_extract(self
, url
):
131 video_id
= self
._match
_id
(url
)
132 playlist_id
= self
._extract
_playlist
_id
(url
, 'playlistId')
134 if self
._yes
_playlist
(playlist_id
, video_id
):
135 return self
._extract
_playlist
(playlist_id
)
137 data
= self
._download
_json
(f
'{self._API_BASE}/videos/{video_id}', video_id
)
140 'url': f
'{self._CDN_BASE}/video/{video_id}/{quality}.webp',
141 } for quality
in [48, 96, 144, 240, 512, 1080]]
144 url_data
= self
._download
_json
(f
'{self._API_BASE}/videos/{video_id}/url', video_id
, data
=b
'')
145 if master_url
:= traverse_obj(url_data
, ('src', 'hls', 'masterPlaylist', {url_or_none}
)):
146 formats
= self
._extract
_m
3u8_formats
(master_url
, video_id
, 'mp4', m3u8_id
='hls', fatal
=False)
148 for format_id
, format_url
in traverse_obj(url_data
, (
149 'src', ('mp4', 'hls'), 'levels', {dict.items
}, lambda _
, v
: url_or_none(v
[1]))):
150 ext
= determine_ext(format_url
)
151 is_hls
= ext
== 'm3u8'
154 'ext': 'mp4' if is_hls
else ext
,
155 'format_id': join_nonempty(is_hls
and 'hls', format_id
),
156 'protocol': 'm3u8_native' if is_hls
else 'https',
157 'height': int_or_none(format_id
),
159 self
._remove
_duplicate
_formats
(formats
)
163 'title': data
.get('title'),
164 'description': data
.get('desc'),
165 'uploader': traverse_obj(data
, ('channel', 'name')),
166 'channel_id': data
.get('channelId'),
167 'channel_url': format_field(data
, 'channelId', 'https://banbye.com/channel/%s'),
168 'timestamp': unified_timestamp(data
.get('publishedAt')),
169 'duration': data
.get('duration'),
170 'tags': data
.get('tags'),
172 'thumbnails': thumbnails
,
173 'like_count': data
.get('likes'),
174 'dislike_count': data
.get('dislikes'),
175 'view_count': data
.get('views'),
176 'comment_count': data
.get('commentCount'),
180 class BanByeChannelIE(BanByeBaseIE
):
181 _VALID_URL
= r
'https?://(?:www\.)?banbye\.com/(?:en/)?channel/(?P<id>\w+)'
183 'url': 'https://banbye.com/channel/ch_wrealu24',
187 'description': 'md5:da54e48416b74dfdde20a04867c0c2f6',
189 'playlist_mincount': 791,
191 'url': 'https://banbye.com/channel/ch_wrealu24?playlist=p_Ld82N6gBw_OJ',
193 'title': 'Krzysztof Karoń',
194 'id': 'p_Ld82N6gBw_OJ',
200 def _real_extract(self
, url
):
201 channel_id
= self
._match
_id
(url
)
202 playlist_id
= self
._extract
_playlist
_id
(url
)
205 return self
._extract
_playlist
(playlist_id
)
207 def page_func(page_num
):
208 data
= self
._download
_json
(f
'{self._API_BASE}/videos', channel_id
, query
={
209 'channelId': channel_id
,
211 'limit': self
._PAGE
_SIZE
,
212 'offset': page_num
* self
._PAGE
_SIZE
,
213 }, note
=f
'Downloading page {page_num + 1}')
215 self
.url_result(f
"{self._VIDEO_BASE}/{video['_id']}", BanByeIE
)
216 for video
in data
['items']
219 channel_data
= self
._download
_json
(f
'{self._API_BASE}/channels/{channel_id}', channel_id
)
220 entries
= InAdvancePagedList(
222 math
.ceil(channel_data
['videoCount'] / self
._PAGE
_SIZE
),
225 return self
.playlist_result(
226 entries
, channel_id
, channel_data
.get('name'), channel_data
.get('description'))