mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-28 01:18:30 +00:00
feat: parse access_hash from url for tracks too
This commit is contained in:
parent
c71008ed60
commit
df89f7643d
@ -758,7 +758,10 @@ def _real_extract(self, url):
|
||||
|
||||
class VKMusicIE(VKBaseIE):
|
||||
IE_NAME = 'vk:music'
|
||||
_VALID_URL = r'https?://(?:(?:m|new)\.)?vk\.com/(?:audio(?P<track_id>-?\d+_\d+)|(?:.*[\?&](?:act|z)=audio_playlist|music/[a-z]+/)(?P<playlist_id>(?P<pl_oid>-?\d+)_(?P<pl_id>\d+))(?:(?:%2F|_|[?&]access_hash=)(?P<access_hash>[0-9a-f]+))?)'
|
||||
|
||||
# Debug and test on https://regexr.com/8dlot
|
||||
_VALID_URL = r'https?://(?:(?:m|new)\.)?vk\.com/(?:audio(?P<track_id>-?\d+_\d+)|(?:.*[\?&](?:act|z)=audio_playlist|music/[a-z]+/)(?P<playlist_id>(?P<pl_oid>-?\d+)_(?P<pl_id>\d+)))(?:(?:%2F|_|[?&]access_hash=)(?P<access_hash>[0-9a-f]+))?'
|
||||
|
||||
_TESTS = [
|
||||
{
|
||||
'url': 'https://vk.com/audio-2001746599_34746599',
|
||||
@ -909,12 +912,12 @@ def _real_extract(self, url):
|
||||
mobj = self._match_valid_url(url)
|
||||
track_id = mobj.group('track_id')
|
||||
playlist_id = mobj.group('playlist_id')
|
||||
access_hash = mobj.group('access_hash')
|
||||
|
||||
if track_id:
|
||||
if not access_hash:
|
||||
webpage = self._download_webpage(url, track_id)
|
||||
|
||||
# copied regex from VKWallPostIE
|
||||
# XXX: common code should be unified, moved to a class
|
||||
data_audio = self._search_regex(
|
||||
r'data-audio="([^"]+)', webpage, 'data-audio attr',
|
||||
default=None, group=1)
|
||||
@ -935,7 +938,12 @@ def _real_extract(self, url):
|
||||
self._parse_json(unescapeHTML(data_exec), track_id),
|
||||
('AudioPlayerBlock/init', 'firstAudio'))
|
||||
|
||||
one_more_id = meta[24]
|
||||
del data_exec
|
||||
|
||||
del data_audio
|
||||
del webpage
|
||||
|
||||
access_hash = meta[24]
|
||||
|
||||
block_reason = traverse_obj(
|
||||
self._parse_json(meta[12], track_id, fatal=False),
|
||||
@ -944,12 +952,9 @@ def _real_extract(self, url):
|
||||
if block_reason == 'geo':
|
||||
self.raise_geo_restricted()
|
||||
|
||||
del data_audio
|
||||
del webpage
|
||||
|
||||
meta = self._download_payload('al_audio', track_id, {
|
||||
'act': 'reload_audios',
|
||||
'audio_ids': f'{track_id}_{one_more_id}',
|
||||
'audio_ids': f'{track_id}_{access_hash}',
|
||||
})[0][0]
|
||||
|
||||
url = _unmask_url(meta[2], self._parse_vk_id())
|
||||
@ -968,7 +973,7 @@ def _real_extract(self, url):
|
||||
elif playlist_id:
|
||||
meta = self._download_payload('al_audio', playlist_id, {
|
||||
'act': 'load_section',
|
||||
'access_hash': mobj.group('access_hash') or '',
|
||||
'access_hash': access_hash or '',
|
||||
'claim': '0',
|
||||
'context': '',
|
||||
'from_id': self._parse_vk_id(),
|
||||
|
Loading…
Reference in New Issue
Block a user