4 from .common
import InfoExtractor
5 from ..compat
import compat_str
, compat_urllib_parse_unquote
20 class LBRYBaseIE(InfoExtractor
):
21 _BASE_URL_REGEX
= r
'(?:https?://(?:www\.)?(?:lbry\.tv|odysee\.com)/|lbry://)'
22 _CLAIM_ID_REGEX
= r
'[0-9a-f]{1,40}'
23 _OPT_CLAIM_ID
= '[^:/?#&]+(?:[:#]%s)?' % _CLAIM_ID_REGEX
24 _SUPPORTED_STREAM_TYPES
= ['video', 'audio']
26 def _call_api_proxy(self
, method
, display_id
, params
, resource
):
27 headers
= {'Content-Type': 'application/json-rpc'}
28 token
= try_get(self
._get
_cookies
('https://odysee.com'), lambda x
: x
['auth_token'].value
)
30 headers
['x-lbry-auth-token'] = token
31 response
= self
._download
_json
(
32 'https://api.lbry.tv/api/v1/proxy',
33 display_id
, 'Downloading %s JSON metadata' % resource
,
39 err
= response
.get('error')
42 f
'{self.IE_NAME} said: {err.get("code")} - {err.get("message")}', expected
=True)
43 return response
['result']
45 def _resolve_url(self
, url
, display_id
, resource
):
46 return self
._call
_api
_proxy
(
47 'resolve', display_id
, {'urls': url}
, resource
)[url
]
49 def _permanent_url(self
, url
, claim_name
, claim_id
):
51 url
.replace('lbry://', 'https://lbry.tv/'),
52 '/%s:%s' % (claim_name
, claim_id
))
54 def _parse_stream(self
, stream
, url
):
55 stream_value
= stream
.get('value') or {}
56 stream_type
= stream_value
.get('stream_type')
57 source
= stream_value
.get('source') or {}
58 media
= stream_value
.get(stream_type
) or {}
59 signing_channel
= stream
.get('signing_channel') or {}
60 channel_name
= signing_channel
.get('name')
61 channel_claim_id
= signing_channel
.get('claim_id')
63 if channel_name
and channel_claim_id
:
64 channel_url
= self
._permanent
_url
(url
, channel_name
, channel_claim_id
)
67 'thumbnail': try_get(stream_value
, lambda x
: x
['thumbnail']['url'], compat_str
),
68 'description': stream_value
.get('description'),
69 'license': stream_value
.get('license'),
70 'timestamp': int_or_none(stream
.get('timestamp')),
71 'release_timestamp': int_or_none(stream_value
.get('release_time')),
72 'tags': stream_value
.get('tags'),
73 'duration': int_or_none(media
.get('duration')),
74 'channel': try_get(signing_channel
, lambda x
: x
['value']['title']),
75 'channel_id': channel_claim_id
,
76 'channel_url': channel_url
,
77 'ext': determine_ext(source
.get('name')) or mimetype2ext(source
.get('media_type')),
78 'filesize': int_or_none(source
.get('size')),
80 if stream_type
== 'audio':
81 info
['vcodec'] = 'none'
84 'width': int_or_none(media
.get('width')),
85 'height': int_or_none(media
.get('height')),
90 class LBRYIE(LBRYBaseIE
):
92 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'(?P<id>\$/[^/]+/[^/]+/{1}|@{0}/{0}|(?!@){0})'.format(LBRYBaseIE
._OPT
_CLAIM
_ID
, LBRYBaseIE
._CLAIM
_ID
_REGEX
)
95 'url': 'https://lbry.tv/@Mantega:1/First-day-LBRY:1',
96 'md5': 'fffd15d76062e9a985c22c7c7f2f4805',
98 'id': '17f983b61f53091fb8ea58a9c56804e4ff8cff4d',
100 'title': 'First day in LBRY? Start HERE!',
101 'description': 'md5:f6cb5c704b332d37f5119313c2c98f51',
102 'timestamp': 1595694354,
103 'upload_date': '20200725',
104 'release_timestamp': 1595340697,
105 'release_date': '20200721',
108 'thumbnail': 'https://spee.ch/7/67f2d809c263288c.png',
111 'channel': 'LBRY/Odysee rats united!!!',
112 'channel_id': '1c8ad6a2ab4e889a71146ae4deeb23bb92dab627',
113 'channel_url': 'https://lbry.tv/@Mantega:1c8ad6a2ab4e889a71146ae4deeb23bb92dab627',
124 'url': 'https://lbry.tv/@LBRYFoundation:0/Episode-1:e',
125 'md5': 'c94017d3eba9b49ce085a8fad6b98d00',
127 'id': 'e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
129 'title': 'The LBRY Foundation Community Podcast Episode 1 - Introduction, Streaming on LBRY, Transcoding',
130 'description': 'md5:661ac4f1db09f31728931d7b88807a61',
131 'timestamp': 1591312601,
132 'upload_date': '20200604',
133 'release_timestamp': 1591312421,
134 'release_date': '20200604',
137 'channel': 'The LBRY Foundation',
138 'channel_id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
139 'channel_url': 'https://lbry.tv/@LBRYFoundation:0ed629d2b9c601300cacf7eabe9da0be79010212',
141 'thumbnail': 'https://spee.ch/d/0bc63b0e6bf1492d.png',
146 'url': 'https://odysee.com/@gardeningincanada:b/plants-i-will-never-grow-again.-the:e',
147 'md5': '25049011f3c8bc2f8b60ad88a031837e',
149 'id': 'e51671357333fe22ae88aad320bde2f6f96b1410',
151 'title': 'PLANTS I WILL NEVER GROW AGAIN. THE BLACK LIST PLANTS FOR A CANADIAN GARDEN | Gardening in Canada 🍁',
152 'description': 'md5:9c539c6a03fb843956de61a4d5288d5e',
153 'timestamp': 1618254123,
154 'upload_date': '20210412',
155 'release_timestamp': 1618254002,
156 'release_date': '20210412',
159 'channel': 'Gardening In Canada',
160 'channel_id': 'b8be0e93b423dad221abe29545fbe8ec36e806bc',
161 'channel_url': 'https://odysee.com/@gardeningincanada:b8be0e93b423dad221abe29545fbe8ec36e806bc',
162 'formats': 'mincount:3',
163 'thumbnail': 'https://thumbnails.lbry.com/AgHSc_HzrrE',
164 'license': 'Copyrighted (contact publisher)',
167 # HLS live stream (might expire)
168 'url': 'https://odysee.com/@RT:fd/livestream_RT:d',
170 'id': 'fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
172 'live_status': 'is_live',
173 'title': 'startswith:RT News | Livestream 24/7',
174 'description': 'md5:fe68d0056dfe79c1a6b8ce8c34d5f6fa',
177 'release_timestamp': int,
182 'channel_id': 'fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
183 'channel_url': 'https://odysee.com/@RT:fdd11cb3ab75f95efb7b3bc2d726aa13ac915b66',
184 'formats': 'mincount:1',
185 'thumbnail': 'startswith:https://thumb',
188 'params': {'skip_download': True}
190 'url': 'https://odysee.com/@BrodieRobertson:5/apple-is-tracking-everything-you-do-on:e',
191 'only_matching': True,
193 'url': 'https://odysee.com/@ScammerRevolts:b0/I-SYSKEY\'D-THE-SAME-SCAMMERS-3-TIMES!:b',
194 'only_matching': True,
196 'url': 'https://lbry.tv/Episode-1:e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
197 'only_matching': True,
199 'url': 'https://lbry.tv/$/embed/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
200 'only_matching': True,
202 'url': 'https://lbry.tv/Episode-1:e7',
203 'only_matching': True,
205 'url': 'https://lbry.tv/@LBRYFoundation/Episode-1',
206 'only_matching': True,
208 'url': 'https://lbry.tv/$/download/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
209 'only_matching': True,
211 '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',
212 'only_matching': True,
214 'url': 'lbry://@lbry#3f/odysee#7',
215 'only_matching': True,
218 def _real_extract(self
, url
):
219 display_id
= self
._match
_id
(url
)
220 if display_id
.startswith('$/'):
221 display_id
= display_id
.split('/', 2)[-1].replace('/', ':')
223 display_id
= display_id
.replace(':', '#')
224 display_id
= compat_urllib_parse_unquote(display_id
)
225 uri
= 'lbry://' + display_id
226 result
= self
._resolve
_url
(uri
, display_id
, 'stream')
227 headers
= {'Referer': 'https://odysee.com/'}
228 if result
['value'].get('stream_type') in self
._SUPPORTED
_STREAM
_TYPES
:
229 claim_id
, is_live
= result
['claim_id'], False
230 streaming_url
= self
._call
_api
_proxy
(
231 'get', claim_id
, {'uri': uri}
, 'streaming url')['streaming_url']
232 final_url
= self
._request
_webpage
(
233 HEADRequest(streaming_url
), display_id
, headers
=headers
,
234 note
='Downloading streaming redirect url info').geturl()
235 elif result
.get('value_type') == 'stream':
236 claim_id
, is_live
= result
['signing_channel']['claim_id'], True
237 live_data
= self
._download
_json
(
238 'https://api.odysee.live/livestream/is_live', claim_id
,
239 query
={'channel_claim_id': claim_id}
,
240 note
='Downloading livestream JSON metadata')['data']
241 streaming_url
= final_url
= live_data
.get('VideoURL')
242 # Upcoming videos may still give VideoURL
243 if not live_data
.get('Live'):
244 streaming_url
= final_url
= None
245 self
.raise_no_formats('This stream is not live', True, claim_id
)
247 raise UnsupportedError(url
)
249 info
= self
._parse
_stream
(result
, url
)
250 if determine_ext(final_url
) == 'm3u8':
251 info
['formats'] = self
._extract
_m
3u8_formats
(
252 final_url
, display_id
, 'mp4', 'm3u8_native', m3u8_id
='hls', live
=is_live
, headers
=headers
)
253 self
._sort
_formats
(info
['formats'])
255 info
['url'] = streaming_url
259 'title': result
['value']['title'],
261 'http_headers': headers
,
265 class LBRYChannelIE(LBRYBaseIE
):
266 IE_NAME
= 'lbry:channel'
267 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'(?P<id>@%s)/?(?:[?&]|$)' % LBRYBaseIE
._OPT
_CLAIM
_ID
269 'url': 'https://lbry.tv/@LBRYFoundation:0',
271 'id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
272 'title': 'The LBRY Foundation',
273 'description': 'Channel for the LBRY Foundation. Follow for updates and news.',
275 'playlist_mincount': 29,
277 'url': 'https://lbry.tv/@LBRYFoundation',
278 'only_matching': True,
280 'url': 'lbry://@lbry#3f',
281 'only_matching': True,
285 def _fetch_page(self
, claim_id
, url
, params
, page
):
288 'channel_ids': [claim_id
],
289 'claim_type': 'stream',
292 'page_size': self
._PAGE
_SIZE
,
294 page_params
.update(params
)
295 result
= self
._call
_api
_proxy
(
296 'claim_search', claim_id
, page_params
, 'page %d' % page
)
297 for item
in (result
.get('items') or []):
298 stream_claim_name
= item
.get('name')
299 stream_claim_id
= item
.get('claim_id')
300 if not (stream_claim_name
and stream_claim_id
):
303 info
= self
._parse
_stream
(item
, url
)
306 'id': stream_claim_id
,
307 'title': try_get(item
, lambda x
: x
['value']['title']),
308 'url': self
._permanent
_url
(url
, stream_claim_name
, stream_claim_id
),
312 def _real_extract(self
, url
):
313 display_id
= self
._match
_id
(url
).replace(':', '#')
314 result
= self
._resolve
_url
(
315 'lbry://' + display_id
, display_id
, 'channel')
316 claim_id
= result
['claim_id']
318 content
= qs
.get('content', [None])[0]
320 'fee_amount': qs
.get('fee_amount', ['>=0'])[0],
322 'new': ['release_time'],
323 'top': ['effective_amount'],
324 'trending': ['trending_group', 'trending_mixed'],
325 }[qs
.get('order', ['new'])[0]],
326 'stream_types': [content
] if content
in ['audio', 'video'] else self
._SUPPORTED
_STREAM
_TYPES
,
328 duration
= qs
.get('duration', [None])[0]
330 params
['duration'] = {
334 language
= qs
.get('language', ['all'])[0]
335 if language
!= 'all':
336 languages
= [language
]
338 languages
.append('none')
339 params
['any_languages'] = languages
340 entries
= OnDemandPagedList(
341 functools
.partial(self
._fetch
_page
, claim_id
, url
, params
),
343 result_value
= result
.get('value') or {}
344 return self
.playlist_result(
345 entries
, claim_id
, result_value
.get('title'),
346 result_value
.get('description'))