6 from .common
import InfoExtractor
7 from ..networking
import HEADRequest
24 class LBRYBaseIE(InfoExtractor
):
25 _BASE_URL_REGEX
= r
'(?x)(?:https?://(?:www\.)?(?:lbry\.tv|odysee\.com)/|lbry://)'
26 _CLAIM_ID_REGEX
= r
'[0-9a-f]{1,40}'
27 _OPT_CLAIM_ID
= f
'[^$@:/?#&]+(?:[:#]{_CLAIM_ID_REGEX})?'
28 _SUPPORTED_STREAM_TYPES
= ['video', 'audio']
31 def _call_api_proxy(self
, method
, display_id
, params
, resource
):
32 headers
= {'Content-Type': 'application/json-rpc'}
33 token
= try_get(self
._get
_cookies
('https://odysee.com'), lambda x
: x
['auth_token'].value
)
35 headers
['x-lbry-auth-token'] = token
36 response
= self
._download
_json
(
37 'https://api.lbry.tv/api/v1/proxy',
38 display_id
, f
'Downloading {resource} JSON metadata',
44 err
= response
.get('error')
47 f
'{self.IE_NAME} said: {err.get("code")} - {err.get("message")}', expected
=True)
48 return response
['result']
50 def _resolve_url(self
, url
, display_id
, resource
):
51 return self
._call
_api
_proxy
(
52 'resolve', display_id
, {'urls': url
}, resource
)[url
]
54 def _permanent_url(self
, url
, claim_name
, claim_id
):
56 url
.replace('lbry://', 'https://lbry.tv/'),
57 f
'/{claim_name}:{claim_id}')
59 def _parse_stream(self
, stream
, url
):
60 stream_type
= traverse_obj(stream
, ('value', 'stream_type', {str}
))
62 info
= traverse_obj(stream
, {
63 'title': ('value', 'title', {str}
),
64 'thumbnail': ('value', 'thumbnail', 'url', {url_or_none}
),
65 'description': ('value', 'description', {str}
),
66 'license': ('value', 'license', {str}
),
67 'timestamp': ('timestamp', {int_or_none}
),
68 'release_timestamp': ('value', 'release_time', {int_or_none}
),
69 'tags': ('value', 'tags', ..., filter),
70 'duration': ('value', stream_type
, 'duration', {int_or_none}
),
71 'channel': ('signing_channel', 'value', 'title', {str}
),
72 'channel_id': ('signing_channel', 'claim_id', {str}
),
73 'uploader_id': ('signing_channel', 'name', {str}
),
76 if info
.get('uploader_id') and info
.get('channel_id'):
77 info
['channel_url'] = self
._permanent
_url
(url
, info
['uploader_id'], info
['channel_id'])
81 def _fetch_page(self
, display_id
, url
, params
, page
):
86 'page_size': self
._PAGE
_SIZE
,
89 result
= self
._call
_api
_proxy
(
90 'claim_search', display_id
, page_params
, f
'page {page}')
91 for item
in traverse_obj(result
, ('items', lambda _
, v
: v
['name'] and v
['claim_id'])):
93 **self
._parse
_stream
(item
, url
),
95 'id': item
['claim_id'],
96 'url': self
._permanent
_url
(url
, item
['name'], item
['claim_id']),
99 def _playlist_entries(self
, url
, display_id
, claim_param
, metadata
):
101 content
= qs
.get('content', [None])[0]
103 'fee_amount': qs
.get('fee_amount', ['>=0'])[0],
105 'new': ['release_time'],
106 'top': ['effective_amount'],
107 'trending': ['trending_group', 'trending_mixed'],
108 }[qs
.get('order', ['new'])[0]],
109 'claim_type': 'stream',
110 'stream_types': [content
] if content
in ['audio', 'video'] else self
._SUPPORTED
_STREAM
_TYPES
,
113 duration
= qs
.get('duration', [None])[0]
115 params
['duration'] = {
119 language
= qs
.get('language', ['all'])[0]
120 if language
!= 'all':
121 languages
= [language
]
123 languages
.append('none')
124 params
['any_languages'] = languages
126 entries
= OnDemandPagedList(
127 functools
.partial(self
._fetch
_page
, display_id
, url
, params
),
130 return self
.playlist_result(
131 entries
, display_id
, **traverse_obj(metadata
, ('value', {
133 'description': 'description',
137 class LBRYIE(LBRYBaseIE
):
139 IE_DESC
= 'odysee.com'
140 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ rf
'''
141 (?:\$/(?:download|embed)/)?
143 [^$@:/?#]+/{LBRYBaseIE._CLAIM_ID_REGEX}
144 |(?:@{LBRYBaseIE._OPT_CLAIM_ID}/)?{LBRYBaseIE._OPT_CLAIM_ID}
148 'url': 'https://lbry.tv/@Mantega:1/First-day-LBRY:1',
149 'md5': '65bd7ec1f6744ada55da8e4c48a2edf9',
151 'id': '17f983b61f53091fb8ea58a9c56804e4ff8cff4d',
153 'title': 'First day in LBRY? Start HERE!',
154 'description': 'md5:f6cb5c704b332d37f5119313c2c98f51',
155 'timestamp': 1595694354,
156 'upload_date': '20200725',
157 'release_timestamp': 1595340697,
158 'release_date': '20200721',
161 'thumbnail': 'https://spee.ch/7/67f2d809c263288c.png',
163 'uploader_id': '@Mantega',
165 'channel': 'LBRY/Odysee rats united!!!',
166 'channel_id': '1c8ad6a2ab4e889a71146ae4deeb23bb92dab627',
167 'channel_url': 'https://lbry.tv/@Mantega:1c8ad6a2ab4e889a71146ae4deeb23bb92dab627',
178 'url': 'https://lbry.tv/@LBRYFoundation:0/Episode-1:e',
179 'md5': 'c94017d3eba9b49ce085a8fad6b98d00',
181 'id': 'e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
183 'title': 'The LBRY Foundation Community Podcast Episode 1 - Introduction, Streaming on LBRY, Transcoding',
184 'description': 'md5:661ac4f1db09f31728931d7b88807a61',
185 'timestamp': 1591312601,
186 'upload_date': '20200604',
187 'release_timestamp': 1591312421,
188 'release_date': '20200604',
191 'channel': 'The LBRY Foundation',
192 'channel_id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
193 'channel_url': 'https://lbry.tv/@LBRYFoundation:0ed629d2b9c601300cacf7eabe9da0be79010212',
195 'thumbnail': 'https://spee.ch/d/0bc63b0e6bf1492d.png',
197 'uploader_id': '@LBRYFoundation',
200 'url': 'https://odysee.com/@gardeningincanada:b/plants-i-will-never-grow-again.-the:e',
201 'md5': 'c35fac796f62a14274b4dc2addb5d0ba',
203 'id': 'e51671357333fe22ae88aad320bde2f6f96b1410',
205 'title': 'PLANTS I WILL NEVER GROW AGAIN. THE BLACK LIST PLANTS FOR A CANADIAN GARDEN | Gardening in Canada 🍁',
206 'description': 'md5:9c539c6a03fb843956de61a4d5288d5e',
207 'timestamp': 1618254123,
208 'upload_date': '20210412',
209 'release_timestamp': 1618254002,
210 'release_date': '20210412',
213 'channel': 'Gardening In Canada',
214 'channel_id': 'b8be0e93b423dad221abe29545fbe8ec36e806bc',
215 'channel_url': 'https://odysee.com/@gardeningincanada:b8be0e93b423dad221abe29545fbe8ec36e806bc',
216 'uploader_id': '@gardeningincanada',
217 'formats': 'mincount:3',
218 'thumbnail': 'https://thumbnails.lbry.com/AgHSc_HzrrE',
219 'license': 'Copyrighted (contact publisher)',
222 # HLS live stream (might expire)
223 'url': 'https://odysee.com/@RT:fd/livestream_RT:d',
225 'id': 'fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
227 'live_status': 'is_live',
228 'title': 'startswith:RT News | Livestream 24/7',
229 'description': 'md5:fe68d0056dfe79c1a6b8ce8c34d5f6fa',
232 'release_timestamp': int,
236 'channel_id': 'fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
237 'channel_url': 'https://odysee.com/@RT:fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
238 'formats': 'mincount:1',
239 'thumbnail': 'startswith:https://thumb',
241 'uploader_id': '@RT',
243 'params': {'skip_download': True},
245 # original quality format w/higher resolution than HLS formats
246 'url': 'https://odysee.com/@wickedtruths:2/Biotechnological-Invasion-of-Skin-(April-2023):4',
247 'md5': '305b0b3b369bde1b984961f005b67193',
249 'id': '41fbfe805eb73c8d3012c0c49faa0f563274f634',
251 'title': 'Biotechnological Invasion of Skin (April 2023)',
252 'description': 'md5:fe28689db2cb7ba3436d819ac3ffc378',
253 'channel': 'Wicked Truths',
254 'channel_id': '23d2bbf856b0ceed5b1d7c5960bcc72da5a20cb0',
255 'channel_url': 'https://odysee.com/@wickedtruths:23d2bbf856b0ceed5b1d7c5960bcc72da5a20cb0',
256 'uploader_id': '@wickedtruths',
257 'timestamp': 1695114347,
258 'upload_date': '20230919',
259 'release_timestamp': 1685617473,
260 'release_date': '20230601',
262 'thumbnail': 'https://thumbs.odycdn.com/4e6d39da4df0cfdad45f64e253a15959.webp',
263 'tags': ['smart skin surveillance', 'biotechnology invasion of skin', 'morgellons'],
265 'protocol': 'https', # test for direct mp4 download
268 'url': 'https://odysee.com/@BrodieRobertson:5/apple-is-tracking-everything-you-do-on:e',
269 'only_matching': True,
271 'url': 'https://odysee.com/@ScammerRevolts:b0/I-SYSKEY\'D-THE-SAME-SCAMMERS-3-TIMES!:b',
272 'only_matching': True,
274 'url': 'https://lbry.tv/Episode-1:e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
275 'only_matching': True,
277 'url': 'https://lbry.tv/$/embed/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
278 'only_matching': True,
280 'url': 'https://lbry.tv/Episode-1:e7',
281 'only_matching': True,
283 'url': 'https://lbry.tv/@LBRYFoundation/Episode-1',
284 'only_matching': True,
286 'url': 'https://lbry.tv/$/download/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
287 'only_matching': True,
289 'url': 'https://lbry.tv/@lacajadepandora:a/TRUMP-EST%C3%81-BIEN-PUESTO-con-Pilar-Baselga,-Carlos-Senra,-Luis-Palacios-(720p_30fps_H264-192kbit_AAC):1',
290 'only_matching': True,
292 'url': 'lbry://@lbry#3f/odysee#7',
293 'only_matching': True,
296 def _real_extract(self
, url
):
297 display_id
= self
._match
_id
(url
)
298 if display_id
.startswith('@'):
299 display_id
= display_id
.replace(':', '#')
301 display_id
= display_id
.replace('/', ':')
302 display_id
= urllib
.parse
.unquote(display_id
)
303 uri
= 'lbry://' + display_id
304 result
= self
._resolve
_url
(uri
, display_id
, 'stream')
305 headers
= {'Referer': 'https://odysee.com/'}
308 stream_type
= traverse_obj(result
, ('value', 'stream_type', {str}
))
310 if stream_type
in self
._SUPPORTED
_STREAM
_TYPES
:
311 claim_id
, is_live
= result
['claim_id'], False
312 streaming_url
= self
._call
_api
_proxy
(
313 'get', claim_id
, {'uri': uri
}, 'streaming url')['streaming_url']
315 # GET request to v3 API returns original video/audio file if available
316 direct_url
= re
.sub(r
'/api/v\d+/', '/api/v3/', streaming_url
)
317 urlh
= self
._request
_webpage
(
318 direct_url
, display_id
, 'Checking for original quality', headers
=headers
, fatal
=False)
319 if urlh
and urlhandle_detect_ext(urlh
) != 'm3u8':
322 'format_id': 'original',
324 **traverse_obj(result
, ('value', {
325 'ext': ('source', (('name', {determine_ext}
), ('media_type', {mimetype2ext}
))),
326 'filesize': ('source', 'size', {int_or_none}
),
327 'width': ('video', 'width', {int_or_none}
),
328 'height': ('video', 'height', {int_or_none}
),
330 'vcodec': 'none' if stream_type
== 'audio' else None,
333 # HEAD request returns redirect response to m3u8 URL if available
334 final_url
= self
._request
_webpage
(
335 HEADRequest(streaming_url
), display_id
, headers
=headers
,
336 note
='Downloading streaming redirect url info').url
338 elif result
.get('value_type') == 'stream':
339 claim_id
, is_live
= result
['signing_channel']['claim_id'], True
340 live_data
= self
._download
_json
(
341 'https://api.odysee.live/livestream/is_live', claim_id
,
342 query
={'channel_claim_id': claim_id
},
343 note
='Downloading livestream JSON metadata')['data']
344 final_url
= live_data
.get('VideoURL')
345 # Upcoming videos may still give VideoURL
346 if not live_data
.get('Live'):
348 self
.raise_no_formats('This stream is not live', True, claim_id
)
351 raise UnsupportedError(url
)
353 if determine_ext(final_url
) == 'm3u8':
354 formats
.extend(self
._extract
_m
3u8_formats
(
355 final_url
, display_id
, 'mp4', m3u8_id
='hls', live
=is_live
, headers
=headers
))
358 **self
._parse
_stream
(result
, url
),
362 'http_headers': headers
,
366 class LBRYChannelIE(LBRYBaseIE
):
367 IE_NAME
= 'lbry:channel'
368 IE_DESC
= 'odysee.com channels'
369 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ rf
'(?P<id>@{LBRYBaseIE._OPT_CLAIM_ID})/?(?:[?&]|$)'
371 'url': 'https://lbry.tv/@LBRYFoundation:0',
373 'id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
374 'title': 'The LBRY Foundation',
375 'description': 'Channel for the LBRY Foundation. Follow for updates and news.',
377 'playlist_mincount': 29,
379 'url': 'https://lbry.tv/@LBRYFoundation',
380 'only_matching': True,
382 'url': 'lbry://@lbry#3f',
383 'only_matching': True,
386 def _real_extract(self
, url
):
387 display_id
= self
._match
_id
(url
).replace(':', '#')
388 result
= self
._resolve
_url
(f
'lbry://{display_id}', display_id
, 'channel')
389 claim_id
= result
['claim_id']
391 return self
._playlist
_entries
(url
, claim_id
, {'channel_ids': [claim_id
]}, result
)
394 class LBRYPlaylistIE(LBRYBaseIE
):
395 IE_NAME
= 'lbry:playlist'
396 IE_DESC
= 'odysee.com playlists'
397 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'\$/(?:play)?list/(?P<id>[0-9a-f-]+)'
399 'url': 'https://odysee.com/$/playlist/ffef782f27486f0ac138bde8777f72ebdd0548c2',
401 'id': 'ffef782f27486f0ac138bde8777f72ebdd0548c2',
402 'title': 'Théâtre Classique',
403 'description': 'Théâtre Classique',
405 'playlist_mincount': 4,
407 'url': 'https://odysee.com/$/list/9c6658b3dd21e4f2a0602d523a13150e2b48b770',
409 'id': '9c6658b3dd21e4f2a0602d523a13150e2b48b770',
410 'title': 'Social Media Exposed',
411 'description': 'md5:98af97317aacd5b85d595775ea37d80e',
413 'playlist_mincount': 34,
415 'url': 'https://odysee.com/$/playlist/938fb11d-215f-4d1c-ad64-723954df2184',
417 'id': '938fb11d-215f-4d1c-ad64-723954df2184',
419 'playlist_mincount': 1000,
422 def _real_extract(self
, url
):
423 display_id
= self
._match
_id
(url
)
424 result
= traverse_obj(self
._call
_api
_proxy
('claim_search', display_id
, {
425 'claim_ids': [display_id
],
428 'page_size': self
._PAGE
_SIZE
,
429 }, 'playlist'), ('items', 0))
430 claim_param
= {'claim_ids': traverse_obj(result
, ('value', 'claims', ..., {str}
))}
432 return self
._playlist
_entries
(url
, display_id
, claim_param
, result
)