mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 06:10:12 +01:00
Compare commits
3 Commits
32e0d5983a
...
6854b2c865
Author | SHA1 | Date | |
---|---|---|---|
|
6854b2c865 | ||
|
4b5eec0aaa | ||
|
f2767e2ce0 |
|
@ -380,6 +380,7 @@
|
|||
from .chilloutzone import ChilloutzoneIE
|
||||
from .chzzk import (
|
||||
CHZZKLiveIE,
|
||||
CHZZKChannelIE,
|
||||
CHZZKVideoIE,
|
||||
)
|
||||
from .cinemax import CinemaxIE
|
||||
|
|
|
@ -59,16 +59,15 @@ def _extract_from_api(self, video_id, tld):
|
|||
'Accept': 'application/json',
|
||||
}, fatal=False, impersonate=True) or {}
|
||||
|
||||
status = response.get('room_status')
|
||||
if status != 'public':
|
||||
if error := self._ERROR_MAP.get(status):
|
||||
raise ExtractorError(error, expected=True)
|
||||
self.report_warning('Falling back to webpage extraction')
|
||||
return None
|
||||
|
||||
m3u8_url = response.get('url')
|
||||
if not m3u8_url:
|
||||
self.raise_geo_restricted()
|
||||
status = response.get('room_status')
|
||||
if error := self._ERROR_MAP.get(status):
|
||||
raise ExtractorError(error, expected=True)
|
||||
if status == 'public':
|
||||
self.raise_geo_restricted()
|
||||
self.report_warning(f'Got status "{status}" from API; falling back to webpage extraction')
|
||||
return None
|
||||
|
||||
return {
|
||||
'id': video_id,
|
||||
|
|
|
@ -85,6 +85,91 @@ def _real_extract(self, url):
|
|||
}
|
||||
|
||||
|
||||
def _make_vod_result(data):
|
||||
assert isinstance(data, dict)
|
||||
if not data.get('videoId'):
|
||||
return
|
||||
return {
|
||||
'_type': 'url_transparent',
|
||||
'id': data.get('videoId'),
|
||||
'title': data.get('videoTitle'),
|
||||
'url': f'https://chzzk.naver.com/video/{data.get("videoNo")}',
|
||||
'thumbnail': data.get('thumbnailImageUrl'),
|
||||
'timestamp': data.get('publishDateAt'),
|
||||
'view_count': data.get('readCount'),
|
||||
'duration': data.get('duration'),
|
||||
'age_limit': 19 if data.get('adult') else 0,
|
||||
'was_live': True if data.get('videoType') == 'REPLAY' else False,
|
||||
}
|
||||
|
||||
|
||||
class CHZZKChannelIE(InfoExtractor):
|
||||
IE_NAME = 'chzzk:channel'
|
||||
_VALID_URL = r'https?://chzzk\.naver\.com/(?P<id>[\da-f]{32})'
|
||||
_TESTS = [{
|
||||
'note': 'Both video and replay included',
|
||||
'url': 'https://chzzk.naver.com/68f895c59a1043bc5019b5e08c83a5c5',
|
||||
'info_dict': {
|
||||
'id': '68f895c59a1043bc5019b5e08c83a5c5',
|
||||
'channel_id': '68f895c59a1043bc5019b5e08c83a5c5',
|
||||
'description': '나는 머찐 라디유 나는 머찐 라디유' * 26 + '나는 라디유',
|
||||
'channel': '라디유radiyu',
|
||||
'title': '라디유radiyu',
|
||||
'channel_is_verified': False,
|
||||
},
|
||||
'playlist_mincount': 4,
|
||||
}, {
|
||||
'note': 'Video list paging',
|
||||
'url': 'https://chzzk.naver.com/2d4aa2f79b0a397d032c479ef1b37a67',
|
||||
'info_dict': {
|
||||
'id': '2d4aa2f79b0a397d032c479ef1b37a67',
|
||||
'channel_id': '2d4aa2f79b0a397d032c479ef1b37a67',
|
||||
'description': '',
|
||||
'channel': '진짜후추',
|
||||
'title': '진짜후추',
|
||||
'channel_is_verified': False,
|
||||
},
|
||||
'playlist_mincount': 86,
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
channel_id = self._match_id(url)
|
||||
# even if channel got banned, the video list is still available. but downloading videos leads to error
|
||||
channel_meta = self._download_json(
|
||||
f'https://api.chzzk.naver.com/service/v1/channels/{channel_id}', channel_id,
|
||||
note='Downloading channel info', errnote='Unable to download channel info')
|
||||
if channel_meta.get('code') != 200:
|
||||
raise ExtractorError('The channel is not available: %s(%s)' % (
|
||||
channel_meta.get("message"), channel_meta.get("code")), expected=True)
|
||||
|
||||
channel_meta = channel_meta.get('content')
|
||||
if not channel_meta or not channel_meta.get('channelId'):
|
||||
raise ExtractorError('The channel does not exist', expected=True)
|
||||
|
||||
total_count = 0
|
||||
videos = []
|
||||
current_count = 0
|
||||
while current_count <= total_count:
|
||||
videos_page = self._download_json(
|
||||
f'https://api.chzzk.naver.com/service/v1/channels/{channel_id}/videos', channel_meta['channelName'],
|
||||
query={'sortType': 'LATEST', 'pagingType': 'PAGE', 'size': 18, 'videoType': '', 'page': current_count},
|
||||
note='Downloading videos page(%s/%s)' % (current_count + 1, total_count + 1), errnote='Unable to download videos page')
|
||||
if videos_page.get('code') != 200:
|
||||
raise ExtractorError('Unable to download videos page: %s(%s){videos_page.get("message")}' % (
|
||||
videos_page.get("message"), videos_page.get("code")), expected=True)
|
||||
videos_page = videos_page['content']
|
||||
videos.extend(map(_make_vod_result, videos_page['data']))
|
||||
total_count = videos_page['totalPages']
|
||||
current_count += 1
|
||||
if len(videos) != total_count:
|
||||
self.to_screen('Warning: The total count of videos is not equal to the actual count: %s != %s' % (len(videos), total_count))
|
||||
|
||||
return self.playlist_result(
|
||||
videos, channel_id, channel_meta['channelName'], channel_meta['channelDescription'],
|
||||
channel=channel_meta['channelName'], channel_id=channel_id, channel_is_verified=channel_meta['verifiedMark'],
|
||||
)
|
||||
|
||||
|
||||
class CHZZKVideoIE(InfoExtractor):
|
||||
IE_NAME = 'chzzk:video'
|
||||
_VALID_URL = r'https?://chzzk\.naver\.com/video/(?P<id>\d+)'
|
||||
|
|
Loading…
Reference in New Issue
Block a user