Update zspotify.py

This commit is contained in:
Footsiefat 2021-10-16 21:41:30 +13:00 committed by GitHub
parent 97c2812522
commit c138b0c7a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -361,50 +361,52 @@ def downloadTrack(track_id_str: str, extra_paths = ""):
print("### FOUND SONG:", songName, " ###") print("### FOUND SONG:", songName, " ###")
stream = session.content_feeder().load( try:
track_id, VorbisOnlyAudioQuality(quality), False, None) stream = session.content_feeder().load(
track_id, VorbisOnlyAudioQuality(quality), False, None)
except:
print("### SKIPPING:", songName, "(GENERAL DOWNLOAD ERROR) ###")
else:
print("### DOWNLOADING RAW AUDIO ###")
if not os.path.isdir(rootPath + extra_paths):
print("### DOWNLOADING RAW AUDIO ###") os.makedirs(rootPath + extra_paths)
if not os.path.isdir(rootPath + extra_paths): with open(filename,'wb') as f:
os.makedirs(rootPath + extra_paths) '''
chunk_size = 1024 * 16
with open(filename,'wb') as f: buffer = bytearray(chunk_size)
''' bpos = 0
chunk_size = 1024 * 16 '''
buffer = bytearray(chunk_size)
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:
byte = stream.input_stream.stream().read()
if byte == -1: #With the updated version of librespot my faster download method broke so we are using the old fallback method
# flush buffer before breaking while True:
if bpos > 0: byte = stream.input_stream.stream().read()
f.write(buffer[0:bpos]) if byte == b'':
break break
f.write(byte)
print(bpos) '''
buffer[bpos] = byte while True:
bpos += 1 byte = stream.input_stream.stream().read()
if byte == -1:
# flush buffer before breaking
if bpos > 0:
f.write(buffer[0:bpos])
break
if bpos == (chunk_size): print(bpos)
f.write(buffer) buffer[bpos] = byte
bpos = 0 bpos += 1
'''
convertToMp3(filename) if bpos == (chunk_size):
setAudioTags(filename, artists, name, albumName, releaseYear, disc_number, track_number) f.write(buffer)
setMusicThumbnail(filename, imageUrl) bpos = 0
'''
convertToMp3(filename)
setAudioTags(filename, artists, name, albumName, releaseYear, disc_number, track_number)
setMusicThumbnail(filename, imageUrl)
def downloadAlbum(album): def downloadAlbum(album):
token = session.tokens().get("user-read-email") token = session.tokens().get("user-read-email")