Changed video get stream url method

This commit is contained in:
R. M 2023-03-27 08:39:09 -03:00
parent f87bee7732
commit b2521e2933
2 changed files with 17 additions and 8 deletions

View File

@ -3,7 +3,7 @@ import argparse
import traceback
from .gamdl import Gamdl
__version__ = '1.3'
__version__ = '1.4'
def main():
@ -140,14 +140,12 @@ def main():
final_location = dl.get_final_location('.m4v', tags)
if dl.check_exists(final_location) and not args.overwrite:
continue
playlist = dl.get_playlist_music_video(webplayback)
stream_url_audio = dl.get_stream_url_music_video_audio(playlist)
stream_url_video, stream_url_audio = dl.get_stream_url_music_video(webplayback)
decryption_keys_audio = dl.get_decryption_keys_music_video(stream_url_audio, track_id)
encrypted_location_audio = dl.get_encrypted_location_audio(track_id)
dl.download(encrypted_location_audio, stream_url_audio)
decrypted_location_audio = dl.get_decrypted_location_audio(track_id)
dl.decrypt(encrypted_location_audio, decrypted_location_audio, decryption_keys_audio)
stream_url_video = dl.get_stream_url_music_video_video(playlist)
decryption_keys_video = dl.get_decryption_keys_music_video(stream_url_video, track_id)
encrypted_location_video = dl.get_encrypted_location_video(track_id)
dl.download(encrypted_location_video, stream_url_video)

View File

@ -87,10 +87,6 @@ class Gamdl:
return response
def get_playlist_music_video(self, webplayback):
return m3u8.load(webplayback['hls-playlist-url'])
def get_stream_url_song(self, webplayback):
return next(i for i in webplayback["assets"] if i["flavor"] == "28:ctrp256")['URL']
@ -106,6 +102,21 @@ class Gamdl:
return [i for i in playlist.playlists if 'avc' in i.stream_info.codecs][-1].uri
def get_stream_url_music_video(self, webplayback):
with YoutubeDL({
'allow_unplayable_formats': True,
'quiet': True,
'no_warnings': True,
}) as ydl:
playlist = ydl.extract_info(webplayback['hls-playlist-url'], download = False)
if self.prefer_hevc:
stream_url_video = playlist['formats'][-1]['url']
else:
stream_url_video = [i['url'] for i in playlist['formats'] if i['vcodec'] is not None and 'avc1' in i['vcodec']][-1]
stream_url_audio = next(i['url'] for i in playlist['formats'] if 'audio-stereo-256' in i['format_id'])
return stream_url_video, stream_url_audio
def check_exists(self, final_location):
return Path(final_location).exists()