2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
10 compat_urllib_parse_unquote
,
23 class LBRYBaseIE(InfoExtractor
):
24 _BASE_URL_REGEX
= r
'https?://(?:www\.)?(?:lbry\.tv|odysee\.com)/'
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 return self
._download
_json
(
31 'https://api.lbry.tv/api/v1/proxy',
32 display_id
, 'Downloading %s JSON metadata' % resource
,
33 headers
={'Content-Type': 'application/json-rpc'}
,
37 }).encode())['result']
39 def _resolve_url(self
, url
, display_id
, resource
):
40 return self
._call
_api
_proxy
(
41 'resolve', display_id
, {'urls': url}
, resource
)[url
]
43 def _permanent_url(self
, url
, claim_name
, claim_id
):
44 return urljoin(url
, '/%s:%s' % (claim_name
, claim_id
))
46 def _parse_stream(self
, stream
, url
):
47 stream_value
= stream
.get('value') or {}
48 stream_type
= stream_value
.get('stream_type')
49 source
= stream_value
.get('source') or {}
50 media
= stream_value
.get(stream_type
) or {}
51 signing_channel
= stream
.get('signing_channel') or {}
52 channel_name
= signing_channel
.get('name')
53 channel_claim_id
= signing_channel
.get('claim_id')
55 if channel_name
and channel_claim_id
:
56 channel_url
= self
._permanent
_url
(url
, channel_name
, channel_claim_id
)
59 'thumbnail': try_get(stream_value
, lambda x
: x
['thumbnail']['url'], compat_str
),
60 'description': stream_value
.get('description'),
61 'license': stream_value
.get('license'),
62 'timestamp': int_or_none(stream
.get('timestamp')),
63 'tags': stream_value
.get('tags'),
64 'duration': int_or_none(media
.get('duration')),
65 'channel': try_get(signing_channel
, lambda x
: x
['value']['title']),
66 'channel_id': channel_claim_id
,
67 'channel_url': channel_url
,
68 'ext': determine_ext(source
.get('name')) or mimetype2ext(source
.get('media_type')),
69 'filesize': int_or_none(source
.get('size')),
71 if stream_type
== 'audio':
72 info
['vcodec'] = 'none'
75 'width': int_or_none(media
.get('width')),
76 'height': int_or_none(media
.get('height')),
81 class LBRYIE(LBRYBaseIE
):
83 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'(?P<id>\$/[^/]+/[^/]+/{1}|@{0}/{0}|(?!@){0})'.format(LBRYBaseIE
._OPT
_CLAIM
_ID
, LBRYBaseIE
._CLAIM
_ID
_REGEX
)
86 'url': 'https://lbry.tv/@Mantega:1/First-day-LBRY:1',
87 'md5': '65bd7ec1f6744ada55da8e4c48a2edf9',
89 'id': '17f983b61f53091fb8ea58a9c56804e4ff8cff4d',
91 'title': 'First day in LBRY? Start HERE!',
92 'description': 'md5:f6cb5c704b332d37f5119313c2c98f51',
93 'timestamp': 1595694354,
94 'upload_date': '20200725',
100 'url': 'https://lbry.tv/@LBRYFoundation:0/Episode-1:e',
101 'md5': 'c94017d3eba9b49ce085a8fad6b98d00',
103 'id': 'e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
105 'title': 'The LBRY Foundation Community Podcast Episode 1 - Introduction, Streaming on LBRY, Transcoding',
106 'description': 'md5:661ac4f1db09f31728931d7b88807a61',
107 'timestamp': 1591312601,
108 'upload_date': '20200604',
111 'channel': 'The LBRY Foundation',
112 'channel_id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
113 'channel_url': 'https://lbry.tv/@LBRYFoundation:0ed629d2b9c601300cacf7eabe9da0be79010212',
117 'url': 'https://odysee.com/@BrodieRobertson:5/apple-is-tracking-everything-you-do-on:e',
118 'only_matching': True,
120 'url': "https://odysee.com/@ScammerRevolts:b0/I-SYSKEY'D-THE-SAME-SCAMMERS-3-TIMES!:b",
121 'only_matching': True,
123 'url': 'https://lbry.tv/Episode-1:e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
124 'only_matching': True,
126 'url': 'https://lbry.tv/$/embed/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
127 'only_matching': True,
129 'url': 'https://lbry.tv/Episode-1:e7',
130 'only_matching': True,
132 'url': 'https://lbry.tv/@LBRYFoundation/Episode-1',
133 'only_matching': True,
135 'url': 'https://lbry.tv/$/download/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
136 'only_matching': True,
138 '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',
139 'only_matching': True,
142 def _real_extract(self
, url
):
143 display_id
= self
._match
_id
(url
)
144 if display_id
.startswith('$/'):
145 display_id
= display_id
.split('/', 2)[-1].replace('/', ':')
147 display_id
= display_id
.replace(':', '#')
148 display_id
= compat_urllib_parse_unquote(display_id
)
149 uri
= 'lbry://' + display_id
150 result
= self
._resolve
_url
(uri
, display_id
, 'stream')
151 result_value
= result
['value']
152 if result_value
.get('stream_type') not in self
._SUPPORTED
_STREAM
_TYPES
:
153 raise ExtractorError('Unsupported URL', expected
=True)
154 claim_id
= result
['claim_id']
155 title
= result_value
['title']
156 streaming_url
= self
._call
_api
_proxy
(
157 'get', claim_id
, {'uri': uri}
, 'streaming url')['streaming_url']
158 info
= self
._parse
_stream
(result
, url
)
162 'url': streaming_url
,
167 class LBRYChannelIE(LBRYBaseIE
):
168 IE_NAME
= 'lbry:channel'
169 _VALID_URL
= LBRYBaseIE
._BASE
_URL
_REGEX
+ r
'(?P<id>@%s)/?(?:[?#&]|$)' % LBRYBaseIE
._OPT
_CLAIM
_ID
171 'url': 'https://lbry.tv/@LBRYFoundation:0',
173 'id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
174 'title': 'The LBRY Foundation',
175 'description': 'Channel for the LBRY Foundation. Follow for updates and news.',
177 'playlist_count': 29,
179 'url': 'https://lbry.tv/@LBRYFoundation',
180 'only_matching': True,
184 def _fetch_page(self
, claim_id
, url
, page
):
186 result
= self
._call
_api
_proxy
(
187 'claim_search', claim_id
, {
188 'channel_ids': [claim_id
],
189 'claim_type': 'stream',
192 'page_size': self
._PAGE
_SIZE
,
193 'stream_types': self
._SUPPORTED
_STREAM
_TYPES
,
195 for item
in (result
.get('items') or []):
196 stream_claim_name
= item
.get('name')
197 stream_claim_id
= item
.get('claim_id')
198 if not (stream_claim_name
and stream_claim_id
):
201 info
= self
._parse
_stream
(item
, url
)
204 'id': stream_claim_id
,
205 'title': try_get(item
, lambda x
: x
['value']['title']),
206 'url': self
._permanent
_url
(url
, stream_claim_name
, stream_claim_id
),
210 def _real_extract(self
, url
):
211 display_id
= self
._match
_id
(url
).replace(':', '#')
212 result
= self
._resolve
_url
(
213 'lbry://' + display_id
, display_id
, 'channel')
214 claim_id
= result
['claim_id']
215 entries
= OnDemandPagedList(
216 functools
.partial(self
._fetch
_page
, claim_id
, url
),
218 result_value
= result
.get('value') or {}
219 return self
.playlist_result(
220 entries
, claim_id
, result_value
.get('title'),
221 result_value
.get('description'))