2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
10 compat_urllib_parse_unquote
,
24 class LBRYBaseIE(InfoExtractor
):
25 _BASE_URL_REGEX
= r
'(?: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']
30 def _call_api_proxy(self
, method
, display_id
, params
, resource
):
31 return self
._download
_json
(
32 'https://api.lbry.tv/api/v1/proxy',
33 display_id
, 'Downloading %s JSON metadata' % resource
,
34 headers
={'Content-Type': 'application/json-rpc'}
,
38 }).encode())['result']
40 def _resolve_url(self
, url
, display_id
, resource
):
41 return self
._call
_api
_proxy
(
42 'resolve', display_id
, {'urls': url}
, resource
)[url
]
44 def _permanent_url(self
, url
, claim_name
, claim_id
):
46 url
.replace('lbry://', 'https://lbry.tv/'),
47 '/%s:%s' % (claim_name
, claim_id
))
49 def _parse_stream(self
, stream
, url
):
50 stream_value
= stream
.get('value') or {}
51 stream_type
= stream_value
.get('stream_type')
52 source
= stream_value
.get('source') or {}
53 media
= stream_value
.get(stream_type
) or {}
54 signing_channel
= stream
.get('signing_channel') or {}
55 channel_name
= signing_channel
.get('name')
56 channel_claim_id
= signing_channel
.get('claim_id')
58 if channel_name
and channel_claim_id
:
59 channel_url
= self
._permanent
_url
(url
, channel_name
, channel_claim_id
)
62 'thumbnail': try_get(stream_value
, lambda x
: x
['thumbnail']['url'], compat_str
),
63 'description': stream_value
.get('description'),
64 'license': stream_value
.get('license'),
65 'timestamp': int_or_none(stream
.get('timestamp')),
66 'release_timestamp': int_or_none(stream_value
.get('release_time')),
67 'tags': stream_value
.get('tags'),
68 'duration': int_or_none(media
.get('duration')),
69 'channel': try_get(signing_channel
, lambda x
: x
['value']['title']),
70 'channel_id': channel_claim_id
,
71 'channel_url': channel_url
,
72 'ext': determine_ext(source
.get('name')) or mimetype2ext(source
.get('media_type')),
73 'filesize': int_or_none(source
.get('size')),
75 if stream_type
== 'audio':
76 info
['vcodec'] = 'none'
79 'width': int_or_none(media
.get('width')),
80 'height': int_or_none(media
.get('height')),
85 class LBRYIE(LBRYBaseIE
):
87 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'(?P<id>\$/[^/]+/[^/]+/{1}|@{0}/{0}|(?!@){0})'.format(LBRYBaseIE
._OPT
_CLAIM
_ID
, LBRYBaseIE
._CLAIM
_ID
_REGEX
)
90 'url': 'https://lbry.tv/@Mantega:1/First-day-LBRY:1',
91 'md5': '65bd7ec1f6744ada55da8e4c48a2edf9',
93 'id': '17f983b61f53091fb8ea58a9c56804e4ff8cff4d',
95 'title': 'First day in LBRY? Start HERE!',
96 'description': 'md5:f6cb5c704b332d37f5119313c2c98f51',
97 'timestamp': 1595694354,
98 'upload_date': '20200725',
99 'release_timestamp': 1595340697,
100 'release_date': '20200721',
106 'url': 'https://lbry.tv/@LBRYFoundation:0/Episode-1:e',
107 'md5': 'c94017d3eba9b49ce085a8fad6b98d00',
109 'id': 'e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
111 'title': 'The LBRY Foundation Community Podcast Episode 1 - Introduction, Streaming on LBRY, Transcoding',
112 'description': 'md5:661ac4f1db09f31728931d7b88807a61',
113 'timestamp': 1591312601,
114 'upload_date': '20200604',
115 'release_timestamp': 1591312421,
116 'release_date': '20200604',
119 'channel': 'The LBRY Foundation',
120 'channel_id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
121 'channel_url': 'https://lbry.tv/@LBRYFoundation:0ed629d2b9c601300cacf7eabe9da0be79010212',
126 'url': 'https://odysee.com/@gardeningincanada:b/plants-i-will-never-grow-again.-the:e',
127 'md5': 'fc82f45ea54915b1495dd7cb5cc1289f',
129 'id': 'e51671357333fe22ae88aad320bde2f6f96b1410',
131 'title': 'PLANTS I WILL NEVER GROW AGAIN. THE BLACK LIST PLANTS FOR A CANADIAN GARDEN | Gardening in Canada 🍁',
132 'description': 'md5:9c539c6a03fb843956de61a4d5288d5e',
133 'timestamp': 1618254123,
134 'upload_date': '20210412',
135 'release_timestamp': 1618254002,
136 'release_date': '20210412',
139 'channel': 'Gardening In Canada',
140 'channel_id': 'b8be0e93b423dad221abe29545fbe8ec36e806bc',
141 'channel_url': 'https://odysee.com/@gardeningincanada:b8be0e93b423dad221abe29545fbe8ec36e806bc',
142 'formats': 'mincount:3',
145 'url': 'https://odysee.com/@BrodieRobertson:5/apple-is-tracking-everything-you-do-on:e',
146 'only_matching': True,
148 'url': "https://odysee.com/@ScammerRevolts:b0/I-SYSKEY'D-THE-SAME-SCAMMERS-3-TIMES!:b",
149 'only_matching': True,
151 'url': 'https://lbry.tv/Episode-1:e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
152 'only_matching': True,
154 'url': 'https://lbry.tv/$/embed/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
155 'only_matching': True,
157 'url': 'https://lbry.tv/Episode-1:e7',
158 'only_matching': True,
160 'url': 'https://lbry.tv/@LBRYFoundation/Episode-1',
161 'only_matching': True,
163 'url': 'https://lbry.tv/$/download/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
164 'only_matching': True,
166 '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',
167 'only_matching': True,
169 'url': 'lbry://@lbry#3f/odysee#7',
170 'only_matching': True,
173 def _real_extract(self
, url
):
174 display_id
= self
._match
_id
(url
)
175 if display_id
.startswith('$/'):
176 display_id
= display_id
.split('/', 2)[-1].replace('/', ':')
178 display_id
= display_id
.replace(':', '#')
179 display_id
= compat_urllib_parse_unquote(display_id
)
180 uri
= 'lbry://' + display_id
181 result
= self
._resolve
_url
(uri
, display_id
, 'stream')
182 result_value
= result
['value']
183 if result_value
.get('stream_type') not in self
._SUPPORTED
_STREAM
_TYPES
:
184 raise ExtractorError('Unsupported URL', expected
=True)
185 claim_id
= result
['claim_id']
186 title
= result_value
['title']
187 streaming_url
= self
._call
_api
_proxy
(
188 'get', claim_id
, {'uri': uri}
, 'streaming url')['streaming_url']
189 info
= self
._parse
_stream
(result
, url
)
190 urlh
= self
._request
_webpage
(
191 streaming_url
, display_id
, note
='Downloading streaming redirect url info')
192 if determine_ext(urlh
.geturl()) == 'm3u8':
193 info
['formats'] = self
._extract
_m
3u8_formats
(
194 urlh
.geturl(), display_id
, 'mp4', entry_protocol
='m3u8_native',
196 self
._sort
_formats
(info
['formats'])
198 info
['url'] = streaming_url
206 class LBRYChannelIE(LBRYBaseIE
):
207 IE_NAME
= 'lbry:channel'
208 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'(?P<id>@%s)/?(?:[?&]|$)' % LBRYBaseIE
._OPT
_CLAIM
_ID
210 'url': 'https://lbry.tv/@LBRYFoundation:0',
212 'id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
213 'title': 'The LBRY Foundation',
214 'description': 'Channel for the LBRY Foundation. Follow for updates and news.',
216 'playlist_count': 29,
218 'url': 'https://lbry.tv/@LBRYFoundation',
219 'only_matching': True,
221 'url': 'lbry://@lbry#3f',
222 'only_matching': True,
226 def _fetch_page(self
, claim_id
, url
, params
, page
):
229 'channel_ids': [claim_id
],
230 'claim_type': 'stream',
233 'page_size': self
._PAGE
_SIZE
,
235 page_params
.update(params
)
236 result
= self
._call
_api
_proxy
(
237 'claim_search', claim_id
, page_params
, 'page %d' % page
)
238 for item
in (result
.get('items') or []):
239 stream_claim_name
= item
.get('name')
240 stream_claim_id
= item
.get('claim_id')
241 if not (stream_claim_name
and stream_claim_id
):
244 info
= self
._parse
_stream
(item
, url
)
247 'id': stream_claim_id
,
248 'title': try_get(item
, lambda x
: x
['value']['title']),
249 'url': self
._permanent
_url
(url
, stream_claim_name
, stream_claim_id
),
253 def _real_extract(self
, url
):
254 display_id
= self
._match
_id
(url
).replace(':', '#')
255 result
= self
._resolve
_url
(
256 'lbry://' + display_id
, display_id
, 'channel')
257 claim_id
= result
['claim_id']
259 content
= qs
.get('content', [None])[0]
261 'fee_amount': qs
.get('fee_amount', ['>=0'])[0],
263 'new': ['release_time'],
264 'top': ['effective_amount'],
265 'trending': ['trending_group', 'trending_mixed'],
266 }[qs
.get('order', ['new'])[0]],
267 'stream_types': [content
] if content
in ['audio', 'video'] else self
._SUPPORTED
_STREAM
_TYPES
,
269 duration
= qs
.get('duration', [None])[0]
271 params
['duration'] = {
275 language
= qs
.get('language', ['all'])[0]
276 if language
!= 'all':
277 languages
= [language
]
279 languages
.append('none')
280 params
['any_languages'] = languages
281 entries
= OnDemandPagedList(
282 functools
.partial(self
._fetch
_page
, claim_id
, url
, params
),
284 result_value
= result
.get('value') or {}
285 return self
.playlist_result(
286 entries
, claim_id
, result_value
.get('title'),
287 result_value
.get('description'))