5 from .common
import InfoExtractor
23 class LBRYBaseIE(InfoExtractor
):
24 _BASE_URL_REGEX
= r
'(?:https?://(?:www\.)?(?:lbry\.tv|odysee\.com)/|lbry://)'
25 _CLAIM_ID_REGEX
= r
'[0-9a-f]{1,40}'
26 _OPT_CLAIM_ID
= '[^:/?#&]+(?:[:#]%s)?' % _CLAIM_ID_REGEX
27 _SUPPORTED_STREAM_TYPES
= ['video', 'audio']
29 def _call_api_proxy(self
, method
, display_id
, params
, resource
):
30 headers
= {'Content-Type': 'application/json-rpc'}
31 token
= try_get(self
._get
_cookies
('https://odysee.com'), lambda x
: x
['auth_token'].value
)
33 headers
['x-lbry-auth-token'] = token
34 response
= self
._download
_json
(
35 'https://api.lbry.tv/api/v1/proxy',
36 display_id
, 'Downloading %s JSON metadata' % resource
,
42 err
= response
.get('error')
45 f
'{self.IE_NAME} said: {err.get("code")} - {err.get("message")}', expected
=True)
46 return response
['result']
48 def _resolve_url(self
, url
, display_id
, resource
):
49 return self
._call
_api
_proxy
(
50 'resolve', display_id
, {'urls': url}
, resource
)[url
]
52 def _permanent_url(self
, url
, claim_name
, claim_id
):
54 url
.replace('lbry://', 'https://lbry.tv/'),
55 '/%s:%s' % (claim_name
, claim_id
))
57 def _parse_stream(self
, stream
, url
):
58 stream_type
= traverse_obj(stream
, ('value', 'stream_type', {str}
))
60 info
= traverse_obj(stream
, {
61 'title': ('value', 'title', {str}
),
62 'thumbnail': ('value', 'thumbnail', 'url', {url_or_none}
),
63 'description': ('value', 'description', {str}
),
64 'license': ('value', 'license', {str}
),
65 'timestamp': ('timestamp', {int_or_none}
),
66 'release_timestamp': ('value', 'release_time', {int_or_none}
),
67 'tags': ('value', 'tags', ..., {lambda x: x or None}
),
68 'duration': ('value', stream_type
, 'duration', {int_or_none}
),
69 'channel': ('signing_channel', 'value', 'title', {str}
),
70 'channel_id': ('signing_channel', 'claim_id', {str}
),
73 channel_name
= traverse_obj(stream
, ('signing_channel', 'name', {str}
))
74 if channel_name
and info
.get('channel_id'):
75 info
['channel_url'] = self
._permanent
_url
(url
, channel_name
, info
['channel_id'])
80 class LBRYIE(LBRYBaseIE
):
82 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'(?P<id>\$/[^/]+/[^/]+/{1}|@{0}/{0}|(?!@){0})'.format(LBRYBaseIE
._OPT
_CLAIM
_ID
, LBRYBaseIE
._CLAIM
_ID
_REGEX
)
85 'url': 'https://lbry.tv/@Mantega:1/First-day-LBRY:1',
86 'md5': 'fffd15d76062e9a985c22c7c7f2f4805',
88 'id': '17f983b61f53091fb8ea58a9c56804e4ff8cff4d',
90 'title': 'First day in LBRY? Start HERE!',
91 'description': 'md5:f6cb5c704b332d37f5119313c2c98f51',
92 'timestamp': 1595694354,
93 'upload_date': '20200725',
94 'release_timestamp': 1595340697,
95 'release_date': '20200721',
98 'thumbnail': 'https://spee.ch/7/67f2d809c263288c.png',
101 'channel': 'LBRY/Odysee rats united!!!',
102 'channel_id': '1c8ad6a2ab4e889a71146ae4deeb23bb92dab627',
103 'channel_url': 'https://lbry.tv/@Mantega:1c8ad6a2ab4e889a71146ae4deeb23bb92dab627',
114 'url': 'https://lbry.tv/@LBRYFoundation:0/Episode-1:e',
115 'md5': 'c94017d3eba9b49ce085a8fad6b98d00',
117 'id': 'e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
119 'title': 'The LBRY Foundation Community Podcast Episode 1 - Introduction, Streaming on LBRY, Transcoding',
120 'description': 'md5:661ac4f1db09f31728931d7b88807a61',
121 'timestamp': 1591312601,
122 'upload_date': '20200604',
123 'release_timestamp': 1591312421,
124 'release_date': '20200604',
127 'channel': 'The LBRY Foundation',
128 'channel_id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
129 'channel_url': 'https://lbry.tv/@LBRYFoundation:0ed629d2b9c601300cacf7eabe9da0be79010212',
131 'thumbnail': 'https://spee.ch/d/0bc63b0e6bf1492d.png',
136 'url': 'https://odysee.com/@gardeningincanada:b/plants-i-will-never-grow-again.-the:e',
137 'md5': '25049011f3c8bc2f8b60ad88a031837e',
139 'id': 'e51671357333fe22ae88aad320bde2f6f96b1410',
141 'title': 'PLANTS I WILL NEVER GROW AGAIN. THE BLACK LIST PLANTS FOR A CANADIAN GARDEN | Gardening in Canada 🍁',
142 'description': 'md5:9c539c6a03fb843956de61a4d5288d5e',
143 'timestamp': 1618254123,
144 'upload_date': '20210412',
145 'release_timestamp': 1618254002,
146 'release_date': '20210412',
149 'channel': 'Gardening In Canada',
150 'channel_id': 'b8be0e93b423dad221abe29545fbe8ec36e806bc',
151 'channel_url': 'https://odysee.com/@gardeningincanada:b8be0e93b423dad221abe29545fbe8ec36e806bc',
152 'formats': 'mincount:3',
153 'thumbnail': 'https://thumbnails.lbry.com/AgHSc_HzrrE',
154 'license': 'Copyrighted (contact publisher)',
157 # HLS live stream (might expire)
158 'url': 'https://odysee.com/@RT:fd/livestream_RT:d',
160 'id': 'fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
162 'live_status': 'is_live',
163 'title': 'startswith:RT News | Livestream 24/7',
164 'description': 'md5:fe68d0056dfe79c1a6b8ce8c34d5f6fa',
167 'release_timestamp': int,
172 'channel_id': 'fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
173 'channel_url': 'https://odysee.com/@RT:fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
174 'formats': 'mincount:1',
175 'thumbnail': 'startswith:https://thumb',
178 'params': {'skip_download': True}
180 # original quality format w/higher resolution than HLS formats
181 'url': 'https://odysee.com/@wickedtruths:2/Biotechnological-Invasion-of-Skin-(April-2023):4',
182 'md5': '305b0b3b369bde1b984961f005b67193',
184 'id': '41fbfe805eb73c8d3012c0c49faa0f563274f634',
186 'title': 'Biotechnological Invasion of Skin (April 2023)',
187 'description': 'md5:709a2f4c07bd8891cda3a7cc2d6fcf5c',
188 'channel': 'Wicked Truths',
189 'channel_id': '23d2bbf856b0ceed5b1d7c5960bcc72da5a20cb0',
190 'channel_url': 'https://odysee.com/@wickedtruths:23d2bbf856b0ceed5b1d7c5960bcc72da5a20cb0',
191 'timestamp': 1685790036,
192 'upload_date': '20230603',
193 'release_timestamp': 1685617473,
194 'release_date': '20230601',
196 'thumbnail': 'https://thumbs.odycdn.com/4e6d39da4df0cfdad45f64e253a15959.webp',
197 'tags': ['smart skin surveillance', 'biotechnology invasion of skin', 'morgellons'],
199 'protocol': 'https', # test for direct mp4 download
202 'url': 'https://odysee.com/@BrodieRobertson:5/apple-is-tracking-everything-you-do-on:e',
203 'only_matching': True,
205 'url': 'https://odysee.com/@ScammerRevolts:b0/I-SYSKEY\'D-THE-SAME-SCAMMERS-3-TIMES!:b',
206 'only_matching': True,
208 'url': 'https://lbry.tv/Episode-1:e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
209 'only_matching': True,
211 'url': 'https://lbry.tv/$/embed/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
212 'only_matching': True,
214 'url': 'https://lbry.tv/Episode-1:e7',
215 'only_matching': True,
217 'url': 'https://lbry.tv/@LBRYFoundation/Episode-1',
218 'only_matching': True,
220 'url': 'https://lbry.tv/$/download/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
221 'only_matching': True,
223 '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',
224 'only_matching': True,
226 'url': 'lbry://@lbry#3f/odysee#7',
227 'only_matching': True,
230 def _real_extract(self
, url
):
231 display_id
= self
._match
_id
(url
)
232 if display_id
.startswith('$/'):
233 display_id
= display_id
.split('/', 2)[-1].replace('/', ':')
235 display_id
= display_id
.replace(':', '#')
236 display_id
= urllib
.parse
.unquote(display_id
)
237 uri
= 'lbry://' + display_id
238 result
= self
._resolve
_url
(uri
, display_id
, 'stream')
239 headers
= {'Referer': 'https://odysee.com/'}
242 stream_type
= traverse_obj(result
, ('value', 'stream_type', {str}
))
244 if stream_type
in self
._SUPPORTED
_STREAM
_TYPES
:
245 claim_id
, is_live
= result
['claim_id'], False
246 streaming_url
= self
._call
_api
_proxy
(
247 'get', claim_id
, {'uri': uri}
, 'streaming url')['streaming_url']
249 # GET request returns original video/audio file if available
250 ext
= urlhandle_detect_ext(self
._request
_webpage
(
251 streaming_url
, display_id
, 'Checking for original quality', headers
=headers
))
254 'url': streaming_url
,
255 'format_id': 'original',
257 **traverse_obj(result
, ('value', {
258 'ext': ('source', (('name', {determine_ext}
), ('media_type', {mimetype2ext}
))),
259 'filesize': ('source', 'size', {int_or_none}
),
260 'width': ('video', 'width', {int_or_none}
),
261 'height': ('video', 'height', {int_or_none}
),
263 'vcodec': 'none' if stream_type
== 'audio' else None,
266 # HEAD request returns redirect response to m3u8 URL if available
267 final_url
= self
._request
_webpage
(
268 HEADRequest(streaming_url
), display_id
, headers
=headers
,
269 note
='Downloading streaming redirect url info').geturl()
271 elif result
.get('value_type') == 'stream':
272 claim_id
, is_live
= result
['signing_channel']['claim_id'], True
273 live_data
= self
._download
_json
(
274 'https://api.odysee.live/livestream/is_live', claim_id
,
275 query
={'channel_claim_id': claim_id}
,
276 note
='Downloading livestream JSON metadata')['data']
277 final_url
= live_data
.get('VideoURL')
278 # Upcoming videos may still give VideoURL
279 if not live_data
.get('Live'):
281 self
.raise_no_formats('This stream is not live', True, claim_id
)
284 raise UnsupportedError(url
)
286 if determine_ext(final_url
) == 'm3u8':
287 formats
.extend(self
._extract
_m
3u8_formats
(
288 final_url
, display_id
, 'mp4', m3u8_id
='hls', live
=is_live
, headers
=headers
))
291 **self
._parse
_stream
(result
, url
),
295 'http_headers': headers
,
299 class LBRYChannelIE(LBRYBaseIE
):
300 IE_NAME
= 'lbry:channel'
301 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'(?P<id>@%s)/?(?:[?&]|$)' % LBRYBaseIE
._OPT
_CLAIM
_ID
303 'url': 'https://lbry.tv/@LBRYFoundation:0',
305 'id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
306 'title': 'The LBRY Foundation',
307 'description': 'Channel for the LBRY Foundation. Follow for updates and news.',
309 'playlist_mincount': 29,
311 'url': 'https://lbry.tv/@LBRYFoundation',
312 'only_matching': True,
314 'url': 'lbry://@lbry#3f',
315 'only_matching': True,
319 def _fetch_page(self
, claim_id
, url
, params
, page
):
322 'channel_ids': [claim_id
],
323 'claim_type': 'stream',
326 'page_size': self
._PAGE
_SIZE
,
328 page_params
.update(params
)
329 result
= self
._call
_api
_proxy
(
330 'claim_search', claim_id
, page_params
, 'page %d' % page
)
331 for item
in (result
.get('items') or []):
332 stream_claim_name
= item
.get('name')
333 stream_claim_id
= item
.get('claim_id')
334 if not (stream_claim_name
and stream_claim_id
):
338 **self
._parse
_stream
(item
, url
),
340 'id': stream_claim_id
,
341 'url': self
._permanent
_url
(url
, stream_claim_name
, stream_claim_id
),
344 def _real_extract(self
, url
):
345 display_id
= self
._match
_id
(url
).replace(':', '#')
346 result
= self
._resolve
_url
(
347 'lbry://' + display_id
, display_id
, 'channel')
348 claim_id
= result
['claim_id']
350 content
= qs
.get('content', [None])[0]
352 'fee_amount': qs
.get('fee_amount', ['>=0'])[0],
354 'new': ['release_time'],
355 'top': ['effective_amount'],
356 'trending': ['trending_group', 'trending_mixed'],
357 }[qs
.get('order', ['new'])[0]],
358 'stream_types': [content
] if content
in ['audio', 'video'] else self
._SUPPORTED
_STREAM
_TYPES
,
360 duration
= qs
.get('duration', [None])[0]
362 params
['duration'] = {
366 language
= qs
.get('language', ['all'])[0]
367 if language
!= 'all':
368 languages
= [language
]
370 languages
.append('none')
371 params
['any_languages'] = languages
372 entries
= OnDemandPagedList(
373 functools
.partial(self
._fetch
_page
, claim_id
, url
, params
),
375 result_value
= result
.get('value') or {}
376 return self
.playlist_result(
377 entries
, claim_id
, result_value
.get('title'),
378 result_value
.get('description'))