Update zspotify.py

This commit is contained in:
Footsiefat 2021-10-14 14:39:22 +13:00 committed by GitHub
parent 5d836483e5
commit 04f9bbbe14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 4 deletions

View File

@ -15,14 +15,14 @@ import json
import music_tag import music_tag
from librespot.audio.decoders import AudioQuality from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality
from librespot.core import Session from librespot.core import Session
from librespot.metadata import TrackId from librespot.metadata import TrackId
from librespot.player.codecs import VorbisOnlyAudioQuality
from pydub import AudioSegment from pydub import AudioSegment
quality: AudioQuality = AudioQuality.HIGH quality: AudioQuality = AudioQuality.HIGH
#quality: AudioQuality = AudioQuality.VERY_HIGH #Uncomment this line if you have a premium account
session: Session = None session: Session = None
import hashlib import hashlib
@ -367,10 +367,20 @@ def downloadTrack(track_id_str: str, extra_paths = ""):
os.makedirs(rootPath + extra_paths) os.makedirs(rootPath + extra_paths)
with open(filename,'wb') as f: with open(filename,'wb') as f:
'''
chunk_size = 1024 * 16 chunk_size = 1024 * 16
buffer = bytearray(chunk_size) buffer = bytearray(chunk_size)
bpos = 0 bpos = 0
'''
#With the updated version of librespot my faster download method broke so we are using the old fallback method
while True:
byte = stream.input_stream.stream().read()
if byte == b'':
break
f.write(byte)
'''
while True: while True:
byte = stream.input_stream.stream().read() byte = stream.input_stream.stream().read()
@ -380,13 +390,14 @@ def downloadTrack(track_id_str: str, extra_paths = ""):
f.write(buffer[0:bpos]) f.write(buffer[0:bpos])
break break
print(bpos)
buffer[bpos] = byte buffer[bpos] = byte
bpos += 1 bpos += 1
if bpos == (chunk_size): if bpos == (chunk_size):
f.write(buffer) f.write(buffer)
bpos = 0 bpos = 0
'''
convertToMp3(filename) convertToMp3(filename)
setAudioTags(filename, artists, name, albumName, releaseYear, disc_number, track_number) setAudioTags(filename, artists, name, albumName, releaseYear, disc_number, track_number)
setMusicThumbnail(filename, imageUrl) setMusicThumbnail(filename, imageUrl)
@ -444,4 +455,4 @@ if __name__ == "__main__":
#TO DO'S: #TO DO'S:
#MAKE AUDIO SAVING MORE EFFICIENT #MAKE AUDIO SAVING MORE EFFICIENT