mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-06-27 13:15:04 +00:00
Compare commits
2 Commits
0d146c1e36
...
62cba8a1be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62cba8a1be | ||
|
|
239f5f36fe |
@ -18,7 +18,6 @@ from ..utils import (
|
|||||||
InAdvancePagedList,
|
InAdvancePagedList,
|
||||||
OnDemandPagedList,
|
OnDemandPagedList,
|
||||||
bool_or_none,
|
bool_or_none,
|
||||||
clean_html,
|
|
||||||
determine_ext,
|
determine_ext,
|
||||||
filter_dict,
|
filter_dict,
|
||||||
float_or_none,
|
float_or_none,
|
||||||
@ -639,31 +638,27 @@ class BiliBiliIE(BilibiliBaseIE):
|
|||||||
headers['Referer'] = url
|
headers['Referer'] = url
|
||||||
|
|
||||||
initial_state = self._search_json(r'window\.__INITIAL_STATE__\s*=', webpage, 'initial state', video_id)
|
initial_state = self._search_json(r'window\.__INITIAL_STATE__\s*=', webpage, 'initial state', video_id)
|
||||||
|
|
||||||
|
if traverse_obj(initial_state, ('error', 'trueCode')) == -403:
|
||||||
|
self.raise_login_required()
|
||||||
|
if traverse_obj(initial_state, ('error', 'trueCode')) == -404:
|
||||||
|
raise ExtractorError(
|
||||||
|
'This video may be deleted or geo-restricted. '
|
||||||
|
'You might want to try a VPN or a proxy server (with --proxy)', expected=True)
|
||||||
|
|
||||||
is_festival = 'videoData' not in initial_state
|
is_festival = 'videoData' not in initial_state
|
||||||
if is_festival:
|
if is_festival:
|
||||||
video_data = initial_state['videoInfo']
|
video_data = initial_state['videoInfo']
|
||||||
else:
|
else:
|
||||||
play_info_obj = self._search_json(
|
|
||||||
r'window\.__playinfo__\s*=', webpage, 'play info', video_id, fatal=False)
|
|
||||||
if not play_info_obj:
|
|
||||||
if traverse_obj(initial_state, ('error', 'trueCode')) == -403:
|
|
||||||
self.raise_login_required()
|
|
||||||
if traverse_obj(initial_state, ('error', 'trueCode')) == -404:
|
|
||||||
raise ExtractorError(
|
|
||||||
'This video may be deleted or geo-restricted. '
|
|
||||||
'You might want to try a VPN or a proxy server (with --proxy)', expected=True)
|
|
||||||
play_info = traverse_obj(play_info_obj, ('data', {dict}))
|
|
||||||
if not play_info:
|
|
||||||
if traverse_obj(play_info_obj, 'code') == 87007:
|
|
||||||
toast = get_element_by_class('tips-toast', webpage) or ''
|
|
||||||
msg = clean_html(
|
|
||||||
f'{get_element_by_class("belongs-to", toast) or ""},'
|
|
||||||
+ (get_element_by_class('level', toast) or ''))
|
|
||||||
raise ExtractorError(
|
|
||||||
f'This is a supporter-only video: {msg}. {self._login_hint()}', expected=True)
|
|
||||||
raise ExtractorError('Failed to extract play info')
|
|
||||||
video_data = initial_state['videoData']
|
video_data = initial_state['videoData']
|
||||||
|
|
||||||
|
if video_data.get('is_upower_exclusive'):
|
||||||
|
high_level = traverse_obj(initial_state, ('elecFullInfo', 'show_info', 'high_level', {dict})) or {}
|
||||||
|
raise ExtractorError(
|
||||||
|
'This is a supporter-only video: '
|
||||||
|
f'{join_nonempty("title", "sub_title", from_dict=high_level, delim=",")}. '
|
||||||
|
f'{self._login_hint()}', expected=True)
|
||||||
|
|
||||||
video_id, title = video_data['bvid'], video_data.get('title')
|
video_id, title = video_data['bvid'], video_data.get('title')
|
||||||
|
|
||||||
# Bilibili anthologies are similar to playlists but all videos share the same video ID as the anthology itself.
|
# Bilibili anthologies are similar to playlists but all videos share the same video ID as the anthology itself.
|
||||||
@ -689,10 +684,14 @@ class BiliBiliIE(BilibiliBaseIE):
|
|||||||
old_video_id = format_field(aid, None, f'%s_part{part_id or 1}')
|
old_video_id = format_field(aid, None, f'%s_part{part_id or 1}')
|
||||||
cid = traverse_obj(video_data, ('pages', part_id - 1, 'cid')) if part_id else video_data.get('cid')
|
cid = traverse_obj(video_data, ('pages', part_id - 1, 'cid')) if part_id else video_data.get('cid')
|
||||||
|
|
||||||
|
play_info = (
|
||||||
|
traverse_obj(
|
||||||
|
self._search_json(r'window\.__playinfo__\s*=', webpage, 'play info', video_id, default=None),
|
||||||
|
('data', {dict}))
|
||||||
|
or self._download_playinfo(video_id, cid, headers=headers))
|
||||||
|
|
||||||
festival_info = {}
|
festival_info = {}
|
||||||
if is_festival:
|
if is_festival:
|
||||||
play_info = self._download_playinfo(video_id, cid, headers=headers)
|
|
||||||
|
|
||||||
festival_info = traverse_obj(initial_state, {
|
festival_info = traverse_obj(initial_state, {
|
||||||
'uploader': ('videoInfo', 'upName'),
|
'uploader': ('videoInfo', 'upName'),
|
||||||
'uploader_id': ('videoInfo', 'upMid', {str_or_none}),
|
'uploader_id': ('videoInfo', 'upMid', {str_or_none}),
|
||||||
|
|||||||
@ -5,15 +5,16 @@ from ..utils import (
|
|||||||
get_element_text_and_html_by_tag,
|
get_element_text_and_html_by_tag,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
join_nonempty,
|
join_nonempty,
|
||||||
|
parse_qs,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
try_call,
|
try_call,
|
||||||
unified_timestamp,
|
unified_timestamp,
|
||||||
)
|
)
|
||||||
from ..utils.traversal import traverse_obj
|
from ..utils.traversal import traverse_obj, value
|
||||||
|
|
||||||
|
|
||||||
class DuoplayIE(InfoExtractor):
|
class DuoplayIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://duoplay\.ee/(?P<id>\d+)/[\w-]+/?(?:\?(?:[^#]+&)?ep=(?P<ep>\d+))?'
|
_VALID_URL = r'https?://duoplay\.ee/(?P<id>\d+)(?:[/?#]|$)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'note': 'Siberi võmm S02E12',
|
'note': 'Siberi võmm S02E12',
|
||||||
'url': 'https://duoplay.ee/4312/siberi-vomm?ep=24',
|
'url': 'https://duoplay.ee/4312/siberi-vomm?ep=24',
|
||||||
@ -34,15 +35,16 @@ class DuoplayIE(InfoExtractor):
|
|||||||
'episode_number': 12,
|
'episode_number': 12,
|
||||||
'episode_id': '24',
|
'episode_id': '24',
|
||||||
},
|
},
|
||||||
|
'skip': 'No video found',
|
||||||
}, {
|
}, {
|
||||||
'note': 'Empty title',
|
'note': 'Empty title',
|
||||||
'url': 'https://duoplay.ee/17/uhikarotid?ep=14',
|
'url': 'https://duoplay.ee/17/uhikarotid?ep=14',
|
||||||
'md5': '6aca68be71112314738dd17cced7f8bf',
|
'md5': 'cba9f5dabf2582b224d80ac44fb80e47',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '17_14',
|
'id': '17_14',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Ühikarotid',
|
'title': 'Episode 14',
|
||||||
'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
|
'thumbnail': r're:https?://.+\.jpg',
|
||||||
'description': 'md5:4719b418e058c209def41d48b601276e',
|
'description': 'md5:4719b418e058c209def41d48b601276e',
|
||||||
'upload_date': '20100916',
|
'upload_date': '20100916',
|
||||||
'timestamp': 1284661800,
|
'timestamp': 1284661800,
|
||||||
@ -52,6 +54,8 @@ class DuoplayIE(InfoExtractor):
|
|||||||
'season_number': 2,
|
'season_number': 2,
|
||||||
'episode_id': '14',
|
'episode_id': '14',
|
||||||
'release_year': 2010,
|
'release_year': 2010,
|
||||||
|
'episode': 'Episode 14',
|
||||||
|
'episode_number': 14,
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'note': 'Movie without expiry',
|
'note': 'Movie without expiry',
|
||||||
@ -68,10 +72,32 @@ class DuoplayIE(InfoExtractor):
|
|||||||
'timestamp': 1671054000,
|
'timestamp': 1671054000,
|
||||||
'release_year': 2018,
|
'release_year': 2018,
|
||||||
},
|
},
|
||||||
|
'skip': 'No video found',
|
||||||
|
}, {
|
||||||
|
'note': 'Episode url without show name',
|
||||||
|
'url': 'https://duoplay.ee/9644?ep=185',
|
||||||
|
'md5': '63f324b4fe2dbd8194dca16a6d52184a',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '9644_185',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': 'Episode 185',
|
||||||
|
'thumbnail': r're:https?://.+\.jpg',
|
||||||
|
'description': 'md5:ed25ba4e9e5d54bc291a4a0cdd241467',
|
||||||
|
'upload_date': '20241120',
|
||||||
|
'timestamp': 1732077000,
|
||||||
|
'episode': 'Episode 63',
|
||||||
|
'episode_id': '185',
|
||||||
|
'episode_number': 63,
|
||||||
|
'season': 'Season 2',
|
||||||
|
'season_number': 2,
|
||||||
|
'series': 'Telehommik',
|
||||||
|
'series_id': '9644',
|
||||||
|
},
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
telecast_id, episode = self._match_valid_url(url).group('id', 'ep')
|
telecast_id = self._match_id(url)
|
||||||
|
episode = traverse_obj(parse_qs(url), ('ep', 0, {int_or_none}, {str_or_none}))
|
||||||
video_id = join_nonempty(telecast_id, episode, delim='_')
|
video_id = join_nonempty(telecast_id, episode, delim='_')
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
video_player = try_call(lambda: extract_attributes(
|
video_player = try_call(lambda: extract_attributes(
|
||||||
@ -79,25 +105,33 @@ class DuoplayIE(InfoExtractor):
|
|||||||
if not video_player or not video_player.get('manifest-url'):
|
if not video_player or not video_player.get('manifest-url'):
|
||||||
raise ExtractorError('No video found', expected=True)
|
raise ExtractorError('No video found', expected=True)
|
||||||
|
|
||||||
|
manifest_url = video_player['manifest-url']
|
||||||
|
session_token = self._download_json(
|
||||||
|
'https://sts.postimees.ee/session/register', video_id, 'Registering session',
|
||||||
|
'Unable to register session', headers={
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'X-Original-URI': manifest_url,
|
||||||
|
})['session']
|
||||||
|
|
||||||
episode_attr = self._parse_json(video_player.get(':episode') or '', video_id, fatal=False) or {}
|
episode_attr = self._parse_json(video_player.get(':episode') or '', video_id, fatal=False) or {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'formats': self._extract_m3u8_formats(video_player['manifest-url'], video_id, 'mp4'),
|
'formats': self._extract_m3u8_formats(manifest_url, video_id, 'mp4', query={'s': session_token}),
|
||||||
**traverse_obj(episode_attr, {
|
**traverse_obj(episode_attr, {
|
||||||
'title': 'title',
|
'title': ('title', {str}),
|
||||||
'description': 'synopsis',
|
'description': ('synopsis', {str}),
|
||||||
'thumbnail': ('images', 'original'),
|
'thumbnail': ('images', 'original'),
|
||||||
'timestamp': ('airtime', {lambda x: unified_timestamp(x + ' +0200')}),
|
'timestamp': ('airtime', {lambda x: unified_timestamp(x + ' +0200')}),
|
||||||
'cast': ('cast', {lambda x: x.split(', ')}),
|
'cast': ('cast', filter, {lambda x: x.split(', ')}),
|
||||||
'release_year': ('year', {int_or_none}),
|
'release_year': ('year', {int_or_none}),
|
||||||
}),
|
}),
|
||||||
**(traverse_obj(episode_attr, {
|
**(traverse_obj(episode_attr, {
|
||||||
'title': (None, ('subtitle', ('episode_nr', {lambda x: f'Episode {x}' if x else None}))),
|
'title': (None, (('subtitle', {str}, filter), {value(f'Episode {episode}' if episode else None)})),
|
||||||
'series': 'title',
|
'series': ('title', {str}),
|
||||||
'series_id': ('telecast_id', {str_or_none}),
|
'series_id': ('telecast_id', {str_or_none}),
|
||||||
'season_number': ('season_id', {int_or_none}),
|
'season_number': ('season_id', {int_or_none}),
|
||||||
'episode': 'subtitle',
|
'episode': ('subtitle', {str}, filter),
|
||||||
'episode_number': ('episode_nr', {int_or_none}),
|
'episode_number': ('episode_nr', {int_or_none}),
|
||||||
'episode_id': ('episode_id', {str_or_none}),
|
'episode_id': ('episode_id', {str_or_none}),
|
||||||
}, get_all=False) if episode_attr.get('category') != 'movies' else {}),
|
}, get_all=False) if episode_attr.get('category') != 'movies' else {}),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user