2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
11 compat_urllib_parse_unquote
,
12 compat_urllib_parse_urlparse
,
25 class LBRYBaseIE(InfoExtractor
):
26 _BASE_URL_REGEX
= r
'(?:https?://(?:www\.)?(?:lbry\.tv|odysee\.com)/|lbry://)'
27 _CLAIM_ID_REGEX
= r
'[0-9a-f]{1,40}'
28 _OPT_CLAIM_ID
= '[^:/?#&]+(?:[:#]%s)?' % _CLAIM_ID_REGEX
29 _SUPPORTED_STREAM_TYPES
= ['video', 'audio']
31 def _call_api_proxy(self
, method
, display_id
, params
, resource
):
32 return self
._download
_json
(
33 'https://api.lbry.tv/api/v1/proxy',
34 display_id
, 'Downloading %s JSON metadata' % resource
,
35 headers
={'Content-Type': 'application/json-rpc'}
,
39 }).encode())['result']
41 def _resolve_url(self
, url
, display_id
, resource
):
42 return self
._call
_api
_proxy
(
43 'resolve', display_id
, {'urls': url}
, resource
)[url
]
45 def _permanent_url(self
, url
, claim_name
, claim_id
):
47 url
.replace('lbry://', 'https://lbry.tv/'),
48 '/%s:%s' % (claim_name
, claim_id
))
50 def _parse_stream(self
, stream
, url
):
51 stream_value
= stream
.get('value') or {}
52 stream_type
= stream_value
.get('stream_type')
53 source
= stream_value
.get('source') or {}
54 media
= stream_value
.get(stream_type
) or {}
55 signing_channel
= stream
.get('signing_channel') or {}
56 channel_name
= signing_channel
.get('name')
57 channel_claim_id
= signing_channel
.get('claim_id')
59 if channel_name
and channel_claim_id
:
60 channel_url
= self
._permanent
_url
(url
, channel_name
, channel_claim_id
)
63 'thumbnail': try_get(stream_value
, lambda x
: x
['thumbnail']['url'], compat_str
),
64 'description': stream_value
.get('description'),
65 'license': stream_value
.get('license'),
66 'timestamp': int_or_none(stream
.get('timestamp')),
67 'release_timestamp': int_or_none(stream_value
.get('release_time')),
68 'tags': stream_value
.get('tags'),
69 'duration': int_or_none(media
.get('duration')),
70 'channel': try_get(signing_channel
, lambda x
: x
['value']['title']),
71 'channel_id': channel_claim_id
,
72 'channel_url': channel_url
,
73 'ext': determine_ext(source
.get('name')) or mimetype2ext(source
.get('media_type')),
74 'filesize': int_or_none(source
.get('size')),
76 if stream_type
== 'audio':
77 info
['vcodec'] = 'none'
80 'width': int_or_none(media
.get('width')),
81 'height': int_or_none(media
.get('height')),
86 class LBRYIE(LBRYBaseIE
):
88 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'(?P<id>\$/[^/]+/[^/]+/{1}|@{0}/{0}|(?!@){0})'.format(LBRYBaseIE
._OPT
_CLAIM
_ID
, LBRYBaseIE
._CLAIM
_ID
_REGEX
)
91 'url': 'https://lbry.tv/@Mantega:1/First-day-LBRY:1',
92 'md5': '65bd7ec1f6744ada55da8e4c48a2edf9',
94 'id': '17f983b61f53091fb8ea58a9c56804e4ff8cff4d',
96 'title': 'First day in LBRY? Start HERE!',
97 'description': 'md5:f6cb5c704b332d37f5119313c2c98f51',
98 'timestamp': 1595694354,
99 'upload_date': '20200725',
100 'release_timestamp': 1595340697,
101 'release_date': '20200721',
107 'url': 'https://lbry.tv/@LBRYFoundation:0/Episode-1:e',
108 'md5': 'c94017d3eba9b49ce085a8fad6b98d00',
110 'id': 'e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
112 'title': 'The LBRY Foundation Community Podcast Episode 1 - Introduction, Streaming on LBRY, Transcoding',
113 'description': 'md5:661ac4f1db09f31728931d7b88807a61',
114 'timestamp': 1591312601,
115 'upload_date': '20200604',
116 'release_timestamp': 1591312421,
117 'release_date': '20200604',
120 'channel': 'The LBRY Foundation',
121 'channel_id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
122 'channel_url': 'https://lbry.tv/@LBRYFoundation:0ed629d2b9c601300cacf7eabe9da0be79010212',
127 'url': 'https://odysee.com/@gardeningincanada:b/plants-i-will-never-grow-again.-the:e',
128 'md5': 'fc82f45ea54915b1495dd7cb5cc1289f',
130 'id': 'e51671357333fe22ae88aad320bde2f6f96b1410',
132 'title': 'PLANTS I WILL NEVER GROW AGAIN. THE BLACK LIST PLANTS FOR A CANADIAN GARDEN | Gardening in Canada 🍁',
133 'description': 'md5:9c539c6a03fb843956de61a4d5288d5e',
134 'timestamp': 1618254123,
135 'upload_date': '20210412',
136 'release_timestamp': 1618254002,
137 'release_date': '20210412',
140 'channel': 'Gardening In Canada',
141 'channel_id': 'b8be0e93b423dad221abe29545fbe8ec36e806bc',
142 'channel_url': 'https://odysee.com/@gardeningincanada:b8be0e93b423dad221abe29545fbe8ec36e806bc',
143 'formats': 'mincount:3',
146 'url': 'https://odysee.com/@BrodieRobertson:5/apple-is-tracking-everything-you-do-on:e',
147 'only_matching': True,
149 'url': "https://odysee.com/@ScammerRevolts:b0/I-SYSKEY'D-THE-SAME-SCAMMERS-3-TIMES!:b",
150 'only_matching': True,
152 'url': 'https://lbry.tv/Episode-1:e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
153 'only_matching': True,
155 'url': 'https://lbry.tv/$/embed/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
156 'only_matching': True,
158 'url': 'https://lbry.tv/Episode-1:e7',
159 'only_matching': True,
161 'url': 'https://lbry.tv/@LBRYFoundation/Episode-1',
162 'only_matching': True,
164 'url': 'https://lbry.tv/$/download/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
165 'only_matching': True,
167 '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',
168 'only_matching': True,
170 'url': 'lbry://@lbry#3f/odysee#7',
171 'only_matching': True,
174 def _real_extract(self
, url
):
175 display_id
= self
._match
_id
(url
)
176 if display_id
.startswith('$/'):
177 display_id
= display_id
.split('/', 2)[-1].replace('/', ':')
179 display_id
= display_id
.replace(':', '#')
180 display_id
= compat_urllib_parse_unquote(display_id
)
181 uri
= 'lbry://' + display_id
182 result
= self
._resolve
_url
(uri
, display_id
, 'stream')
183 result_value
= result
['value']
184 if result_value
.get('stream_type') not in self
._SUPPORTED
_STREAM
_TYPES
:
185 raise ExtractorError('Unsupported URL', expected
=True)
186 claim_id
= result
['claim_id']
187 title
= result_value
['title']
188 streaming_url
= self
._call
_api
_proxy
(
189 'get', claim_id
, {'uri': uri}
, 'streaming url')['streaming_url']
190 info
= self
._parse
_stream
(result
, url
)
191 urlh
= self
._request
_webpage
(
192 streaming_url
, display_id
, note
='Downloading streaming redirect url info')
193 if determine_ext(urlh
.geturl()) == 'm3u8':
194 info
['formats'] = self
._extract
_m
3u8_formats
(
195 urlh
.geturl(), display_id
, 'mp4', entry_protocol
='m3u8_native',
197 self
._sort
_formats
(info
['formats'])
199 info
['url'] = streaming_url
207 class LBRYChannelIE(LBRYBaseIE
):
208 IE_NAME
= 'lbry:channel'
209 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'(?P<id>@%s)/?(?:[?&]|$)' % LBRYBaseIE
._OPT
_CLAIM
_ID
211 'url': 'https://lbry.tv/@LBRYFoundation:0',
213 'id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
214 'title': 'The LBRY Foundation',
215 'description': 'Channel for the LBRY Foundation. Follow for updates and news.',
217 'playlist_count': 29,
219 'url': 'https://lbry.tv/@LBRYFoundation',
220 'only_matching': True,
222 'url': 'lbry://@lbry#3f',
223 'only_matching': True,
227 def _fetch_page(self
, claim_id
, url
, params
, page
):
230 'channel_ids': [claim_id
],
231 'claim_type': 'stream',
234 'page_size': self
._PAGE
_SIZE
,
236 page_params
.update(params
)
237 result
= self
._call
_api
_proxy
(
238 'claim_search', claim_id
, page_params
, 'page %d' % page
)
239 for item
in (result
.get('items') or []):
240 stream_claim_name
= item
.get('name')
241 stream_claim_id
= item
.get('claim_id')
242 if not (stream_claim_name
and stream_claim_id
):
245 info
= self
._parse
_stream
(item
, url
)
248 'id': stream_claim_id
,
249 'title': try_get(item
, lambda x
: x
['value']['title']),
250 'url': self
._permanent
_url
(url
, stream_claim_name
, stream_claim_id
),
254 def _real_extract(self
, url
):
255 display_id
= self
._match
_id
(url
).replace(':', '#')
256 result
= self
._resolve
_url
(
257 'lbry://' + display_id
, display_id
, 'channel')
258 claim_id
= result
['claim_id']
259 qs
= compat_parse_qs(compat_urllib_parse_urlparse(url
).query
)
260 content
= qs
.get('content', [None])[0]
262 'fee_amount': qs
.get('fee_amount', ['>=0'])[0],
264 'new': ['release_time'],
265 'top': ['effective_amount'],
266 'trending': ['trending_group', 'trending_mixed'],
267 }[qs
.get('order', ['new'])[0]],
268 'stream_types': [content
] if content
in ['audio', 'video'] else self
._SUPPORTED
_STREAM
_TYPES
,
270 duration
= qs
.get('duration', [None])[0]
272 params
['duration'] = {
276 language
= qs
.get('language', ['all'])[0]
277 if language
!= 'all':
278 languages
= [language
]
280 languages
.append('none')
281 params
['any_languages'] = languages
282 entries
= OnDemandPagedList(
283 functools
.partial(self
._fetch
_page
, claim_id
, url
, params
),
285 result_value
= result
.get('value') or {}
286 return self
.playlist_result(
287 entries
, claim_id
, result_value
.get('title'),
288 result_value
.get('description'))