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
= '[^$@:/?#&]+(?:[:#]%s)?' % _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
, 'Downloading %s JSON metadata' % resource
,
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 '/%s:%s' % (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', ..., {lambda x: x or None}
),
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 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ rf
'''
140 (?:\$/(?:download|embed)/)?
142 [^$@:/?#]+/{LBRYBaseIE._CLAIM_ID_REGEX}
143 |(?:@{LBRYBaseIE._OPT_CLAIM_ID}/)?{LBRYBaseIE._OPT_CLAIM_ID}
147 'url': 'https://lbry.tv/@Mantega:1/First-day-LBRY:1',
148 'md5': '65bd7ec1f6744ada55da8e4c48a2edf9',
150 'id': '17f983b61f53091fb8ea58a9c56804e4ff8cff4d',
152 'title': 'First day in LBRY? Start HERE!',
153 'description': 'md5:f6cb5c704b332d37f5119313c2c98f51',
154 'timestamp': 1595694354,
155 'upload_date': '20200725',
156 'release_timestamp': 1595340697,
157 'release_date': '20200721',
160 'thumbnail': 'https://spee.ch/7/67f2d809c263288c.png',
162 'uploader_id': '@Mantega',
164 'channel': 'LBRY/Odysee rats united!!!',
165 'channel_id': '1c8ad6a2ab4e889a71146ae4deeb23bb92dab627',
166 'channel_url': 'https://lbry.tv/@Mantega:1c8ad6a2ab4e889a71146ae4deeb23bb92dab627',
177 'url': 'https://lbry.tv/@LBRYFoundation:0/Episode-1:e',
178 'md5': 'c94017d3eba9b49ce085a8fad6b98d00',
180 'id': 'e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
182 'title': 'The LBRY Foundation Community Podcast Episode 1 - Introduction, Streaming on LBRY, Transcoding',
183 'description': 'md5:661ac4f1db09f31728931d7b88807a61',
184 'timestamp': 1591312601,
185 'upload_date': '20200604',
186 'release_timestamp': 1591312421,
187 'release_date': '20200604',
190 'channel': 'The LBRY Foundation',
191 'channel_id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
192 'channel_url': 'https://lbry.tv/@LBRYFoundation:0ed629d2b9c601300cacf7eabe9da0be79010212',
194 'thumbnail': 'https://spee.ch/d/0bc63b0e6bf1492d.png',
196 'uploader_id': '@LBRYFoundation',
199 'url': 'https://odysee.com/@gardeningincanada:b/plants-i-will-never-grow-again.-the:e',
200 'md5': 'c35fac796f62a14274b4dc2addb5d0ba',
202 'id': 'e51671357333fe22ae88aad320bde2f6f96b1410',
204 'title': 'PLANTS I WILL NEVER GROW AGAIN. THE BLACK LIST PLANTS FOR A CANADIAN GARDEN | Gardening in Canada 🍁',
205 'description': 'md5:9c539c6a03fb843956de61a4d5288d5e',
206 'timestamp': 1618254123,
207 'upload_date': '20210412',
208 'release_timestamp': 1618254002,
209 'release_date': '20210412',
212 'channel': 'Gardening In Canada',
213 'channel_id': 'b8be0e93b423dad221abe29545fbe8ec36e806bc',
214 'channel_url': 'https://odysee.com/@gardeningincanada:b8be0e93b423dad221abe29545fbe8ec36e806bc',
215 'uploader_id': '@gardeningincanada',
216 'formats': 'mincount:3',
217 'thumbnail': 'https://thumbnails.lbry.com/AgHSc_HzrrE',
218 'license': 'Copyrighted (contact publisher)',
221 # HLS live stream (might expire)
222 'url': 'https://odysee.com/@RT:fd/livestream_RT:d',
224 'id': 'fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
226 'live_status': 'is_live',
227 'title': 'startswith:RT News | Livestream 24/7',
228 'description': 'md5:fe68d0056dfe79c1a6b8ce8c34d5f6fa',
231 'release_timestamp': int,
235 'channel_id': 'fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
236 'channel_url': 'https://odysee.com/@RT:fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
237 'formats': 'mincount:1',
238 'thumbnail': 'startswith:https://thumb',
240 'uploader_id': '@RT',
242 'params': {'skip_download': True}
244 # original quality format w/higher resolution than HLS formats
245 'url': 'https://odysee.com/@wickedtruths:2/Biotechnological-Invasion-of-Skin-(April-2023):4',
246 'md5': '305b0b3b369bde1b984961f005b67193',
248 'id': '41fbfe805eb73c8d3012c0c49faa0f563274f634',
250 'title': 'Biotechnological Invasion of Skin (April 2023)',
251 'description': 'md5:fe28689db2cb7ba3436d819ac3ffc378',
252 'channel': 'Wicked Truths',
253 'channel_id': '23d2bbf856b0ceed5b1d7c5960bcc72da5a20cb0',
254 'channel_url': 'https://odysee.com/@wickedtruths:23d2bbf856b0ceed5b1d7c5960bcc72da5a20cb0',
255 'uploader_id': '@wickedtruths',
256 'timestamp': 1695114347,
257 'upload_date': '20230919',
258 'release_timestamp': 1685617473,
259 'release_date': '20230601',
261 'thumbnail': 'https://thumbs.odycdn.com/4e6d39da4df0cfdad45f64e253a15959.webp',
262 'tags': ['smart skin surveillance', 'biotechnology invasion of skin', 'morgellons'],
264 'protocol': 'https', # test for direct mp4 download
267 'url': 'https://odysee.com/@BrodieRobertson:5/apple-is-tracking-everything-you-do-on:e',
268 'only_matching': True,
270 'url': 'https://odysee.com/@ScammerRevolts:b0/I-SYSKEY\'D-THE-SAME-SCAMMERS-3-TIMES!:b',
271 'only_matching': True,
273 'url': 'https://lbry.tv/Episode-1:e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
274 'only_matching': True,
276 'url': 'https://lbry.tv/$/embed/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
277 'only_matching': True,
279 'url': 'https://lbry.tv/Episode-1:e7',
280 'only_matching': True,
282 'url': 'https://lbry.tv/@LBRYFoundation/Episode-1',
283 'only_matching': True,
285 'url': 'https://lbry.tv/$/download/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
286 'only_matching': True,
288 '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',
289 'only_matching': True,
291 'url': 'lbry://@lbry#3f/odysee#7',
292 'only_matching': True,
295 def _real_extract(self
, url
):
296 display_id
= self
._match
_id
(url
)
297 if display_id
.startswith('@'):
298 display_id
= display_id
.replace(':', '#')
300 display_id
= display_id
.replace('/', ':')
301 display_id
= urllib
.parse
.unquote(display_id
)
302 uri
= 'lbry://' + display_id
303 result
= self
._resolve
_url
(uri
, display_id
, 'stream')
304 headers
= {'Referer': 'https://odysee.com/'}
307 stream_type
= traverse_obj(result
, ('value', 'stream_type', {str}
))
309 if stream_type
in self
._SUPPORTED
_STREAM
_TYPES
:
310 claim_id
, is_live
= result
['claim_id'], False
311 streaming_url
= self
._call
_api
_proxy
(
312 'get', claim_id
, {'uri': uri}
, 'streaming url')['streaming_url']
314 # GET request to v3 API returns original video/audio file if available
315 direct_url
= re
.sub(r
'/api/v\d+/', '/api/v3/', streaming_url
)
316 urlh
= self
._request
_webpage
(
317 direct_url
, display_id
, 'Checking for original quality', headers
=headers
, fatal
=False)
318 if urlh
and urlhandle_detect_ext(urlh
) != 'm3u8':
321 'format_id': 'original',
323 **traverse_obj(result
, ('value', {
324 'ext': ('source', (('name', {determine_ext}
), ('media_type', {mimetype2ext}
))),
325 'filesize': ('source', 'size', {int_or_none}
),
326 'width': ('video', 'width', {int_or_none}
),
327 'height': ('video', 'height', {int_or_none}
),
329 'vcodec': 'none' if stream_type
== 'audio' else None,
332 # HEAD request returns redirect response to m3u8 URL if available
333 final_url
= self
._request
_webpage
(
334 HEADRequest(streaming_url
), display_id
, headers
=headers
,
335 note
='Downloading streaming redirect url info').url
337 elif result
.get('value_type') == 'stream':
338 claim_id
, is_live
= result
['signing_channel']['claim_id'], True
339 live_data
= self
._download
_json
(
340 'https://api.odysee.live/livestream/is_live', claim_id
,
341 query
={'channel_claim_id': claim_id}
,
342 note
='Downloading livestream JSON metadata')['data']
343 final_url
= live_data
.get('VideoURL')
344 # Upcoming videos may still give VideoURL
345 if not live_data
.get('Live'):
347 self
.raise_no_formats('This stream is not live', True, claim_id
)
350 raise UnsupportedError(url
)
352 if determine_ext(final_url
) == 'm3u8':
353 formats
.extend(self
._extract
_m
3u8_formats
(
354 final_url
, display_id
, 'mp4', m3u8_id
='hls', live
=is_live
, headers
=headers
))
357 **self
._parse
_stream
(result
, url
),
361 'http_headers': headers
,
365 class LBRYChannelIE(LBRYBaseIE
):
366 IE_NAME
= 'lbry:channel'
367 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ rf
'(?P<id>@{LBRYBaseIE._OPT_CLAIM_ID})/?(?:[?&]|$)'
369 'url': 'https://lbry.tv/@LBRYFoundation:0',
371 'id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
372 'title': 'The LBRY Foundation',
373 'description': 'Channel for the LBRY Foundation. Follow for updates and news.',
375 'playlist_mincount': 29,
377 'url': 'https://lbry.tv/@LBRYFoundation',
378 'only_matching': True,
380 'url': 'lbry://@lbry#3f',
381 'only_matching': True,
384 def _real_extract(self
, url
):
385 display_id
= self
._match
_id
(url
).replace(':', '#')
386 result
= self
._resolve
_url
(f
'lbry://{display_id}', display_id
, 'channel')
387 claim_id
= result
['claim_id']
389 return self
._playlist
_entries
(url
, claim_id
, {'channel_ids': [claim_id]}
, result
)
392 class LBRYPlaylistIE(LBRYBaseIE
):
393 IE_NAME
= 'lbry:playlist'
394 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'\$/(?:play)?list/(?P<id>[0-9a-f-]+)'
396 'url': 'https://odysee.com/$/playlist/ffef782f27486f0ac138bde8777f72ebdd0548c2',
398 'id': 'ffef782f27486f0ac138bde8777f72ebdd0548c2',
399 'title': 'Théâtre Classique',
400 'description': 'Théâtre Classique',
402 'playlist_mincount': 4,
404 'url': 'https://odysee.com/$/list/9c6658b3dd21e4f2a0602d523a13150e2b48b770',
406 'id': '9c6658b3dd21e4f2a0602d523a13150e2b48b770',
407 'title': 'Social Media Exposed',
408 'description': 'md5:98af97317aacd5b85d595775ea37d80e',
410 'playlist_mincount': 34,
412 'url': 'https://odysee.com/$/playlist/938fb11d-215f-4d1c-ad64-723954df2184',
414 'id': '938fb11d-215f-4d1c-ad64-723954df2184',
416 'playlist_mincount': 1000,
419 def _real_extract(self
, url
):
420 display_id
= self
._match
_id
(url
)
421 result
= traverse_obj(self
._call
_api
_proxy
('claim_search', display_id
, {
422 'claim_ids': [display_id
],
425 'page_size': self
._PAGE
_SIZE
,
426 }, 'playlist'), ('items', 0))
427 claim_param
= {'claim_ids': traverse_obj(result, ('value', 'claims', ..., {str}
))}
429 return self
._playlist
_entries
(url
, display_id
, claim_param
, result
)