2021-01-01 13:26:37 +01:00
|
|
|
import functools
|
2020-11-19 20:22:59 +01:00
|
|
|
import json
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2022-06-27 02:33:31 +02:00
|
|
|
from ..compat import compat_str, compat_urllib_parse_unquote
|
2020-11-19 20:22:59 +01:00
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
2022-06-27 02:33:31 +02:00
|
|
|
HEADRequest,
|
|
|
|
OnDemandPagedList,
|
|
|
|
UnsupportedError,
|
|
|
|
determine_ext,
|
2020-11-19 20:22:59 +01:00
|
|
|
int_or_none,
|
|
|
|
mimetype2ext,
|
2021-08-22 21:02:00 +02:00
|
|
|
parse_qs,
|
2020-11-19 20:22:59 +01:00
|
|
|
try_get,
|
2021-01-01 13:26:37 +01:00
|
|
|
urljoin,
|
2020-11-19 20:22:59 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-01-01 13:26:37 +01:00
|
|
|
class LBRYBaseIE(InfoExtractor):
|
2021-03-04 19:15:28 +01:00
|
|
|
_BASE_URL_REGEX = r'(?:https?://(?:www\.)?(?:lbry\.tv|odysee\.com)/|lbry://)'
|
2021-01-01 13:26:37 +01:00
|
|
|
_CLAIM_ID_REGEX = r'[0-9a-f]{1,40}'
|
2021-03-04 19:15:28 +01:00
|
|
|
_OPT_CLAIM_ID = '[^:/?#&]+(?:[:#]%s)?' % _CLAIM_ID_REGEX
|
2021-01-01 13:26:37 +01:00
|
|
|
_SUPPORTED_STREAM_TYPES = ['video', 'audio']
|
|
|
|
|
|
|
|
def _call_api_proxy(self, method, display_id, params, resource):
|
2021-09-23 13:41:43 +02:00
|
|
|
response = self._download_json(
|
2021-01-01 13:26:37 +01:00
|
|
|
'https://api.lbry.tv/api/v1/proxy',
|
|
|
|
display_id, 'Downloading %s JSON metadata' % resource,
|
|
|
|
headers={'Content-Type': 'application/json-rpc'},
|
|
|
|
data=json.dumps({
|
|
|
|
'method': method,
|
|
|
|
'params': params,
|
2021-09-23 13:41:43 +02:00
|
|
|
}).encode())
|
|
|
|
err = response.get('error')
|
|
|
|
if err:
|
|
|
|
raise ExtractorError(
|
|
|
|
f'{self.IE_NAME} said: {err.get("code")} - {err.get("message")}', expected=True)
|
|
|
|
return response['result']
|
2021-01-01 13:26:37 +01:00
|
|
|
|
|
|
|
def _resolve_url(self, url, display_id, resource):
|
|
|
|
return self._call_api_proxy(
|
|
|
|
'resolve', display_id, {'urls': url}, resource)[url]
|
|
|
|
|
|
|
|
def _permanent_url(self, url, claim_name, claim_id):
|
2021-03-04 19:15:28 +01:00
|
|
|
return urljoin(
|
|
|
|
url.replace('lbry://', 'https://lbry.tv/'),
|
|
|
|
'/%s:%s' % (claim_name, claim_id))
|
2021-01-01 13:26:37 +01:00
|
|
|
|
|
|
|
def _parse_stream(self, stream, url):
|
|
|
|
stream_value = stream.get('value') or {}
|
|
|
|
stream_type = stream_value.get('stream_type')
|
|
|
|
source = stream_value.get('source') or {}
|
|
|
|
media = stream_value.get(stream_type) or {}
|
|
|
|
signing_channel = stream.get('signing_channel') or {}
|
|
|
|
channel_name = signing_channel.get('name')
|
|
|
|
channel_claim_id = signing_channel.get('claim_id')
|
|
|
|
channel_url = None
|
|
|
|
if channel_name and channel_claim_id:
|
|
|
|
channel_url = self._permanent_url(url, channel_name, channel_claim_id)
|
|
|
|
|
|
|
|
info = {
|
|
|
|
'thumbnail': try_get(stream_value, lambda x: x['thumbnail']['url'], compat_str),
|
|
|
|
'description': stream_value.get('description'),
|
|
|
|
'license': stream_value.get('license'),
|
|
|
|
'timestamp': int_or_none(stream.get('timestamp')),
|
2021-03-15 00:22:06 +01:00
|
|
|
'release_timestamp': int_or_none(stream_value.get('release_time')),
|
2021-01-01 13:26:37 +01:00
|
|
|
'tags': stream_value.get('tags'),
|
|
|
|
'duration': int_or_none(media.get('duration')),
|
|
|
|
'channel': try_get(signing_channel, lambda x: x['value']['title']),
|
|
|
|
'channel_id': channel_claim_id,
|
|
|
|
'channel_url': channel_url,
|
|
|
|
'ext': determine_ext(source.get('name')) or mimetype2ext(source.get('media_type')),
|
|
|
|
'filesize': int_or_none(source.get('size')),
|
|
|
|
}
|
|
|
|
if stream_type == 'audio':
|
|
|
|
info['vcodec'] = 'none'
|
|
|
|
else:
|
|
|
|
info.update({
|
|
|
|
'width': int_or_none(media.get('width')),
|
|
|
|
'height': int_or_none(media.get('height')),
|
|
|
|
})
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
class LBRYIE(LBRYBaseIE):
|
|
|
|
IE_NAME = 'lbry'
|
|
|
|
_VALID_URL = LBRYBaseIE._BASE_URL_REGEX + r'(?P<id>\$/[^/]+/[^/]+/{1}|@{0}/{0}|(?!@){0})'.format(LBRYBaseIE._OPT_CLAIM_ID, LBRYBaseIE._CLAIM_ID_REGEX)
|
2020-11-19 20:22:59 +01:00
|
|
|
_TESTS = [{
|
|
|
|
# Video
|
|
|
|
'url': 'https://lbry.tv/@Mantega:1/First-day-LBRY:1',
|
2022-06-27 02:33:31 +02:00
|
|
|
'md5': 'fffd15d76062e9a985c22c7c7f2f4805',
|
2020-11-19 20:22:59 +01:00
|
|
|
'info_dict': {
|
|
|
|
'id': '17f983b61f53091fb8ea58a9c56804e4ff8cff4d',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'First day in LBRY? Start HERE!',
|
|
|
|
'description': 'md5:f6cb5c704b332d37f5119313c2c98f51',
|
|
|
|
'timestamp': 1595694354,
|
|
|
|
'upload_date': '20200725',
|
2021-03-15 00:22:06 +01:00
|
|
|
'release_timestamp': 1595340697,
|
|
|
|
'release_date': '20200721',
|
2021-01-01 13:26:37 +01:00
|
|
|
'width': 1280,
|
|
|
|
'height': 720,
|
2022-06-27 02:33:31 +02:00
|
|
|
'thumbnail': 'https://spee.ch/7/67f2d809c263288c.png',
|
|
|
|
'license': 'None',
|
|
|
|
'duration': 346,
|
|
|
|
'channel': 'LBRY/Odysee rats united!!!',
|
|
|
|
'channel_id': '1c8ad6a2ab4e889a71146ae4deeb23bb92dab627',
|
|
|
|
'channel_url': 'https://lbry.tv/@Mantega:1c8ad6a2ab4e889a71146ae4deeb23bb92dab627',
|
|
|
|
'tags': [
|
|
|
|
'first day in lbry',
|
|
|
|
'lbc',
|
|
|
|
'lbry',
|
|
|
|
'start',
|
|
|
|
'tutorial'
|
|
|
|
],
|
2020-11-19 20:22:59 +01:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
# Audio
|
|
|
|
'url': 'https://lbry.tv/@LBRYFoundation:0/Episode-1:e',
|
|
|
|
'md5': 'c94017d3eba9b49ce085a8fad6b98d00',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
|
|
|
|
'ext': 'mp3',
|
|
|
|
'title': 'The LBRY Foundation Community Podcast Episode 1 - Introduction, Streaming on LBRY, Transcoding',
|
|
|
|
'description': 'md5:661ac4f1db09f31728931d7b88807a61',
|
|
|
|
'timestamp': 1591312601,
|
|
|
|
'upload_date': '20200604',
|
2021-03-15 00:22:06 +01:00
|
|
|
'release_timestamp': 1591312421,
|
|
|
|
'release_date': '20200604',
|
2021-01-01 13:26:37 +01:00
|
|
|
'tags': list,
|
|
|
|
'duration': 2570,
|
|
|
|
'channel': 'The LBRY Foundation',
|
|
|
|
'channel_id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
|
|
|
|
'channel_url': 'https://lbry.tv/@LBRYFoundation:0ed629d2b9c601300cacf7eabe9da0be79010212',
|
|
|
|
'vcodec': 'none',
|
2022-06-27 02:33:31 +02:00
|
|
|
'thumbnail': 'https://spee.ch/d/0bc63b0e6bf1492d.png',
|
|
|
|
'license': 'None',
|
2020-11-19 20:22:59 +01:00
|
|
|
}
|
2021-04-17 05:02:33 +02:00
|
|
|
}, {
|
|
|
|
# HLS
|
|
|
|
'url': 'https://odysee.com/@gardeningincanada:b/plants-i-will-never-grow-again.-the:e',
|
2022-06-27 02:33:31 +02:00
|
|
|
'md5': '25049011f3c8bc2f8b60ad88a031837e',
|
2021-04-17 05:02:33 +02:00
|
|
|
'info_dict': {
|
|
|
|
'id': 'e51671357333fe22ae88aad320bde2f6f96b1410',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'PLANTS I WILL NEVER GROW AGAIN. THE BLACK LIST PLANTS FOR A CANADIAN GARDEN | Gardening in Canada 🍁',
|
|
|
|
'description': 'md5:9c539c6a03fb843956de61a4d5288d5e',
|
|
|
|
'timestamp': 1618254123,
|
|
|
|
'upload_date': '20210412',
|
|
|
|
'release_timestamp': 1618254002,
|
|
|
|
'release_date': '20210412',
|
|
|
|
'tags': list,
|
|
|
|
'duration': 554,
|
|
|
|
'channel': 'Gardening In Canada',
|
|
|
|
'channel_id': 'b8be0e93b423dad221abe29545fbe8ec36e806bc',
|
|
|
|
'channel_url': 'https://odysee.com/@gardeningincanada:b8be0e93b423dad221abe29545fbe8ec36e806bc',
|
|
|
|
'formats': 'mincount:3',
|
2022-06-27 02:33:31 +02:00
|
|
|
'thumbnail': 'https://thumbnails.lbry.com/AgHSc_HzrrE',
|
|
|
|
'license': 'Copyrighted (contact publisher)',
|
2021-04-17 05:02:33 +02:00
|
|
|
}
|
2020-11-19 20:22:59 +01:00
|
|
|
}, {
|
|
|
|
'url': 'https://odysee.com/@BrodieRobertson:5/apple-is-tracking-everything-you-do-on:e',
|
|
|
|
'only_matching': True,
|
2020-11-23 22:03:08 +01:00
|
|
|
}, {
|
2022-06-27 02:33:31 +02:00
|
|
|
'url': 'https://odysee.com/@ScammerRevolts:b0/I-SYSKEY\'D-THE-SAME-SCAMMERS-3-TIMES!:b',
|
2020-11-23 22:03:08 +01:00
|
|
|
'only_matching': True,
|
2021-01-01 13:26:37 +01:00
|
|
|
}, {
|
|
|
|
'url': 'https://lbry.tv/Episode-1:e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://lbry.tv/$/embed/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://lbry.tv/Episode-1:e7',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://lbry.tv/@LBRYFoundation/Episode-1',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://lbry.tv/$/download/Episode-1/e7d93d772bd87e2b62d5ab993c1c3ced86ebb396',
|
|
|
|
'only_matching': True,
|
2021-01-16 18:12:05 +01:00
|
|
|
}, {
|
|
|
|
'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',
|
|
|
|
'only_matching': True,
|
2021-03-04 19:15:28 +01:00
|
|
|
}, {
|
|
|
|
'url': 'lbry://@lbry#3f/odysee#7',
|
|
|
|
'only_matching': True,
|
2020-11-19 20:22:59 +01:00
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-01-01 13:26:37 +01:00
|
|
|
display_id = self._match_id(url)
|
|
|
|
if display_id.startswith('$/'):
|
|
|
|
display_id = display_id.split('/', 2)[-1].replace('/', ':')
|
|
|
|
else:
|
|
|
|
display_id = display_id.replace(':', '#')
|
2021-01-16 18:12:05 +01:00
|
|
|
display_id = compat_urllib_parse_unquote(display_id)
|
2020-11-19 20:22:59 +01:00
|
|
|
uri = 'lbry://' + display_id
|
2021-01-01 13:26:37 +01:00
|
|
|
result = self._resolve_url(uri, display_id, 'stream')
|
2021-12-23 04:18:02 +01:00
|
|
|
if result['value'].get('stream_type') in self._SUPPORTED_STREAM_TYPES:
|
2022-06-27 02:33:31 +02:00
|
|
|
claim_id, is_live, headers = result['claim_id'], False, {}
|
2021-12-23 04:18:02 +01:00
|
|
|
streaming_url = self._call_api_proxy(
|
|
|
|
'get', claim_id, {'uri': uri}, 'streaming url')['streaming_url']
|
|
|
|
final_url = self._request_webpage(
|
2022-06-27 02:33:31 +02:00
|
|
|
HEADRequest(streaming_url), display_id,
|
|
|
|
note='Downloading streaming redirect url info').geturl()
|
2021-12-23 04:18:02 +01:00
|
|
|
elif result.get('value_type') == 'stream':
|
|
|
|
claim_id, is_live = result['signing_channel']['claim_id'], True
|
|
|
|
headers = {'referer': 'https://player.odysee.live/'}
|
|
|
|
live_data = self._download_json(
|
2022-06-19 02:10:22 +02:00
|
|
|
'https://api.odysee.live/livestream/is_live', claim_id,
|
|
|
|
query={'channel_claim_id': claim_id},
|
2021-12-23 04:18:02 +01:00
|
|
|
note='Downloading livestream JSON metadata')['data']
|
2022-06-19 02:10:22 +02:00
|
|
|
streaming_url = final_url = live_data.get('VideoURL')
|
|
|
|
if not final_url and not live_data.get('Live'):
|
2022-03-04 14:48:21 +01:00
|
|
|
self.raise_no_formats('This stream is not live', True, claim_id)
|
2021-12-23 04:18:02 +01:00
|
|
|
else:
|
2022-03-04 14:48:21 +01:00
|
|
|
raise UnsupportedError(url)
|
2021-12-23 04:18:02 +01:00
|
|
|
|
2021-01-01 13:26:37 +01:00
|
|
|
info = self._parse_stream(result, url)
|
2021-12-23 04:18:02 +01:00
|
|
|
if determine_ext(final_url) == 'm3u8':
|
2021-04-17 05:02:33 +02:00
|
|
|
info['formats'] = self._extract_m3u8_formats(
|
2021-12-23 04:18:02 +01:00
|
|
|
final_url, display_id, 'mp4', 'm3u8_native', m3u8_id='hls', live=is_live, headers=headers)
|
2021-04-17 05:02:33 +02:00
|
|
|
self._sort_formats(info['formats'])
|
|
|
|
else:
|
|
|
|
info['url'] = streaming_url
|
2021-12-23 04:18:02 +01:00
|
|
|
return {
|
|
|
|
**info,
|
2021-01-01 13:26:37 +01:00
|
|
|
'id': claim_id,
|
2021-12-23 04:18:02 +01:00
|
|
|
'title': result['value']['title'],
|
|
|
|
'is_live': is_live,
|
|
|
|
'http_headers': headers,
|
|
|
|
}
|
2021-01-01 13:26:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
class LBRYChannelIE(LBRYBaseIE):
|
|
|
|
IE_NAME = 'lbry:channel'
|
2021-03-04 19:15:28 +01:00
|
|
|
_VALID_URL = LBRYBaseIE._BASE_URL_REGEX + r'(?P<id>@%s)/?(?:[?&]|$)' % LBRYBaseIE._OPT_CLAIM_ID
|
2021-01-01 13:26:37 +01:00
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://lbry.tv/@LBRYFoundation:0',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '0ed629d2b9c601300cacf7eabe9da0be79010212',
|
|
|
|
'title': 'The LBRY Foundation',
|
|
|
|
'description': 'Channel for the LBRY Foundation. Follow for updates and news.',
|
|
|
|
},
|
2022-06-27 02:33:31 +02:00
|
|
|
'playlist_mincount': 29,
|
2021-01-01 13:26:37 +01:00
|
|
|
}, {
|
|
|
|
'url': 'https://lbry.tv/@LBRYFoundation',
|
|
|
|
'only_matching': True,
|
2021-03-04 19:15:28 +01:00
|
|
|
}, {
|
|
|
|
'url': 'lbry://@lbry#3f',
|
|
|
|
'only_matching': True,
|
2021-01-01 13:26:37 +01:00
|
|
|
}]
|
|
|
|
_PAGE_SIZE = 50
|
|
|
|
|
2021-03-15 00:22:06 +01:00
|
|
|
def _fetch_page(self, claim_id, url, params, page):
|
2021-01-01 13:26:37 +01:00
|
|
|
page += 1
|
2021-03-15 00:22:06 +01:00
|
|
|
page_params = {
|
|
|
|
'channel_ids': [claim_id],
|
|
|
|
'claim_type': 'stream',
|
|
|
|
'no_totals': True,
|
|
|
|
'page': page,
|
|
|
|
'page_size': self._PAGE_SIZE,
|
|
|
|
}
|
|
|
|
page_params.update(params)
|
2021-01-01 13:26:37 +01:00
|
|
|
result = self._call_api_proxy(
|
2021-03-15 00:22:06 +01:00
|
|
|
'claim_search', claim_id, page_params, 'page %d' % page)
|
2021-01-01 13:26:37 +01:00
|
|
|
for item in (result.get('items') or []):
|
|
|
|
stream_claim_name = item.get('name')
|
|
|
|
stream_claim_id = item.get('claim_id')
|
|
|
|
if not (stream_claim_name and stream_claim_id):
|
|
|
|
continue
|
|
|
|
|
|
|
|
info = self._parse_stream(item, url)
|
|
|
|
info.update({
|
|
|
|
'_type': 'url',
|
|
|
|
'id': stream_claim_id,
|
|
|
|
'title': try_get(item, lambda x: x['value']['title']),
|
|
|
|
'url': self._permanent_url(url, stream_claim_name, stream_claim_id),
|
|
|
|
})
|
|
|
|
yield info
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
display_id = self._match_id(url).replace(':', '#')
|
|
|
|
result = self._resolve_url(
|
|
|
|
'lbry://' + display_id, display_id, 'channel')
|
|
|
|
claim_id = result['claim_id']
|
2021-08-22 21:02:00 +02:00
|
|
|
qs = parse_qs(url)
|
2021-03-15 00:22:06 +01:00
|
|
|
content = qs.get('content', [None])[0]
|
|
|
|
params = {
|
|
|
|
'fee_amount': qs.get('fee_amount', ['>=0'])[0],
|
|
|
|
'order_by': {
|
|
|
|
'new': ['release_time'],
|
|
|
|
'top': ['effective_amount'],
|
|
|
|
'trending': ['trending_group', 'trending_mixed'],
|
|
|
|
}[qs.get('order', ['new'])[0]],
|
|
|
|
'stream_types': [content] if content in ['audio', 'video'] else self._SUPPORTED_STREAM_TYPES,
|
|
|
|
}
|
|
|
|
duration = qs.get('duration', [None])[0]
|
|
|
|
if duration:
|
|
|
|
params['duration'] = {
|
|
|
|
'long': '>=1200',
|
|
|
|
'short': '<=240',
|
|
|
|
}[duration]
|
|
|
|
language = qs.get('language', ['all'])[0]
|
|
|
|
if language != 'all':
|
|
|
|
languages = [language]
|
|
|
|
if language == 'en':
|
|
|
|
languages.append('none')
|
|
|
|
params['any_languages'] = languages
|
2021-01-01 13:26:37 +01:00
|
|
|
entries = OnDemandPagedList(
|
2021-03-15 00:22:06 +01:00
|
|
|
functools.partial(self._fetch_page, claim_id, url, params),
|
2021-01-01 13:26:37 +01:00
|
|
|
self._PAGE_SIZE)
|
|
|
|
result_value = result.get('value') or {}
|
|
|
|
return self.playlist_result(
|
|
|
|
entries, claim_id, result_value.get('title'),
|
|
|
|
result_value.get('description'))
|