2023-08-01 20:21:16 +02:00
|
|
|
import urllib.parse
|
|
|
|
|
2017-03-20 23:49:31 +01:00
|
|
|
from .common import InfoExtractor
|
2018-04-15 19:31:25 +02:00
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
2023-08-01 20:21:16 +02:00
|
|
|
str_or_none,
|
|
|
|
traverse_obj,
|
2018-04-15 19:31:25 +02:00
|
|
|
)
|
2017-03-20 23:49:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
class PicartoIE(InfoExtractor):
|
2021-04-01 10:28:33 +02:00
|
|
|
_VALID_URL = r'https?://(?:www.)?picarto\.tv/(?P<id>[a-zA-Z0-9]+)'
|
2017-03-20 23:49:31 +01:00
|
|
|
_TEST = {
|
|
|
|
'url': 'https://picarto.tv/Setz',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'Setz',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 're:^Setz [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
|
|
|
|
'timestamp': int,
|
2024-06-12 01:09:58 +02:00
|
|
|
'is_live': True,
|
2017-03-20 23:49:31 +01:00
|
|
|
},
|
2018-04-15 19:31:25 +02:00
|
|
|
'skip': 'Stream is offline',
|
2017-03-20 23:49:31 +01:00
|
|
|
}
|
|
|
|
|
2018-04-15 19:31:25 +02:00
|
|
|
@classmethod
|
|
|
|
def suitable(cls, url):
|
2024-06-12 01:09:58 +02:00
|
|
|
return False if PicartoVodIE.suitable(url) else super().suitable(url)
|
2018-04-15 19:31:25 +02:00
|
|
|
|
2017-03-20 23:49:31 +01:00
|
|
|
def _real_extract(self, url):
|
2021-04-01 10:28:33 +02:00
|
|
|
channel_id = self._match_id(url)
|
|
|
|
|
|
|
|
data = self._download_json(
|
|
|
|
'https://ptvintern.picarto.tv/ptvapi', channel_id, query={
|
|
|
|
'query': '''{
|
|
|
|
channel(name: "%s") {
|
|
|
|
adult
|
|
|
|
id
|
|
|
|
online
|
|
|
|
stream_name
|
|
|
|
title
|
|
|
|
}
|
|
|
|
getLoadBalancerUrl(channel_name: "%s") {
|
|
|
|
url
|
|
|
|
}
|
2024-06-12 01:09:58 +02:00
|
|
|
}''' % (channel_id, channel_id), # noqa: UP031
|
2021-04-01 10:28:33 +02:00
|
|
|
})['data']
|
|
|
|
metadata = data['channel']
|
|
|
|
|
|
|
|
if metadata.get('online') == 0:
|
2017-03-20 23:49:31 +01:00
|
|
|
raise ExtractorError('Stream is offline', expected=True)
|
2021-04-01 10:28:33 +02:00
|
|
|
title = metadata['title']
|
2017-03-20 23:49:31 +01:00
|
|
|
|
2018-04-15 19:31:25 +02:00
|
|
|
cdn_data = self._download_json(
|
2021-04-01 10:28:33 +02:00
|
|
|
data['getLoadBalancerUrl']['url'] + '/stream/json_' + metadata['stream_name'] + '.js',
|
|
|
|
channel_id, 'Downloading load balancing info')
|
2018-04-15 19:31:25 +02:00
|
|
|
|
|
|
|
formats = []
|
2021-04-01 10:28:33 +02:00
|
|
|
for source in (cdn_data.get('source') or []):
|
|
|
|
source_url = source.get('url')
|
|
|
|
if not source_url:
|
2018-04-15 19:31:25 +02:00
|
|
|
continue
|
2021-04-01 10:28:33 +02:00
|
|
|
source_type = source.get('type')
|
|
|
|
if source_type == 'html5/application/vnd.apple.mpegurl':
|
|
|
|
formats.extend(self._extract_m3u8_formats(
|
|
|
|
source_url, channel_id, 'mp4', m3u8_id='hls', fatal=False))
|
|
|
|
elif source_type == 'html5/video/mp4':
|
|
|
|
formats.append({
|
|
|
|
'url': source_url,
|
|
|
|
})
|
2017-03-20 23:49:31 +01:00
|
|
|
|
2018-05-21 23:02:16 +02:00
|
|
|
mature = metadata.get('adult')
|
2018-04-15 19:31:25 +02:00
|
|
|
if mature is None:
|
|
|
|
age_limit = None
|
|
|
|
else:
|
|
|
|
age_limit = 18 if mature is True else 0
|
|
|
|
|
2017-03-20 23:49:31 +01:00
|
|
|
return {
|
|
|
|
'id': channel_id,
|
2021-12-15 17:00:46 +01:00
|
|
|
'title': title.strip(),
|
2017-03-20 23:49:31 +01:00
|
|
|
'is_live': True,
|
2018-11-11 10:08:54 +01:00
|
|
|
'channel': channel_id,
|
2021-04-01 10:28:33 +02:00
|
|
|
'channel_id': metadata.get('id'),
|
2024-06-12 01:09:58 +02:00
|
|
|
'channel_url': f'https://picarto.tv/{channel_id}',
|
2018-04-15 19:31:25 +02:00
|
|
|
'age_limit': age_limit,
|
|
|
|
'formats': formats,
|
2017-03-20 23:49:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PicartoVodIE(InfoExtractor):
|
2023-08-01 20:21:16 +02:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?picarto\.tv/(?:videopopout|\w+/videos)/(?P<id>[^/?#&]+)'
|
2018-04-15 19:31:25 +02:00
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://picarto.tv/videopopout/ArtofZod_2017.12.12.00.13.23.flv',
|
|
|
|
'md5': '3ab45ba4352c52ee841a28fb73f2d9ca',
|
2017-03-20 23:49:31 +01:00
|
|
|
'info_dict': {
|
2018-04-15 19:31:25 +02:00
|
|
|
'id': 'ArtofZod_2017.12.12.00.13.23.flv',
|
2017-03-20 23:49:31 +01:00
|
|
|
'ext': 'mp4',
|
2018-04-15 19:31:25 +02:00
|
|
|
'title': 'ArtofZod_2017.12.12.00.13.23.flv',
|
2024-06-12 01:09:58 +02:00
|
|
|
'thumbnail': r're:^https?://.*\.jpg',
|
2018-04-15 19:31:25 +02:00
|
|
|
},
|
2023-08-01 20:21:16 +02:00
|
|
|
'skip': 'The VOD does not exist',
|
|
|
|
}, {
|
|
|
|
'url': 'https://picarto.tv/ArtofZod/videos/772650',
|
|
|
|
'md5': '00067a0889f1f6869cc512e3e79c521b',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '772650',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Art of Zod - Drawing and Painting',
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg',
|
|
|
|
'channel': 'ArtofZod',
|
|
|
|
'age_limit': 18,
|
2024-06-12 01:09:58 +02:00
|
|
|
},
|
2018-04-15 19:31:25 +02:00
|
|
|
}, {
|
|
|
|
'url': 'https://picarto.tv/videopopout/Plague',
|
|
|
|
'only_matching': True,
|
|
|
|
}]
|
2017-03-20 23:49:31 +01:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
video_id = self._match_id(url)
|
2018-04-15 19:31:25 +02:00
|
|
|
|
2023-08-01 20:21:16 +02:00
|
|
|
data = self._download_json(
|
|
|
|
'https://ptvintern.picarto.tv/ptvapi', video_id, query={
|
|
|
|
'query': f'''{{
|
|
|
|
video(id: "{video_id}") {{
|
|
|
|
id
|
|
|
|
title
|
|
|
|
adult
|
|
|
|
file_name
|
|
|
|
video_recording_image_url
|
|
|
|
channel {{
|
|
|
|
name
|
|
|
|
}}
|
|
|
|
}}
|
2024-06-12 01:09:58 +02:00
|
|
|
}}''',
|
2023-08-01 20:21:16 +02:00
|
|
|
})['data']['video']
|
|
|
|
|
|
|
|
file_name = data['file_name']
|
|
|
|
netloc = urllib.parse.urlparse(data['video_recording_image_url']).netloc
|
2018-04-15 19:31:25 +02:00
|
|
|
|
|
|
|
formats = self._extract_m3u8_formats(
|
2023-08-01 20:21:16 +02:00
|
|
|
f'https://{netloc}/stream/hls/{file_name}/index.m3u8', video_id, 'mp4', m3u8_id='hls')
|
2017-03-20 23:49:31 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
2023-08-01 20:21:16 +02:00
|
|
|
**traverse_obj(data, {
|
|
|
|
'id': ('id', {str_or_none}),
|
|
|
|
'title': ('title', {str}),
|
|
|
|
'thumbnail': 'video_recording_image_url',
|
|
|
|
'channel': ('channel', 'name', {str}),
|
|
|
|
'age_limit': ('adult', {lambda x: 18 if x else 0}),
|
|
|
|
}),
|
2018-04-15 19:31:25 +02:00
|
|
|
'formats': formats,
|
2017-03-20 23:49:31 +01:00
|
|
|
}
|