mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2025-07-01 23:33:11 +00:00
added support for converting to an ogg file rather than mp3
This commit is contained in:
parent
ef983f0596
commit
455bc01603
15
zspotify.py
15
zspotify.py
@ -28,7 +28,7 @@ import hashlib
|
|||||||
|
|
||||||
rootPath = "ZSpotify Music/"
|
rootPath = "ZSpotify Music/"
|
||||||
skipExistingFiles = True
|
skipExistingFiles = True
|
||||||
|
musicFormat = "mp3" #or "ogg"
|
||||||
|
|
||||||
#miscellaneous functions for general use
|
#miscellaneous functions for general use
|
||||||
def clear():
|
def clear():
|
||||||
@ -257,15 +257,16 @@ def checkPremium(access_token):
|
|||||||
|
|
||||||
|
|
||||||
#Functions directly related to modifying the downloaded audio and its metadata
|
#Functions directly related to modifying the downloaded audio and its metadata
|
||||||
def convertToMp3(filename):
|
def convertAudioFormat(filename):
|
||||||
print("### CONVERTING TO MP3 ###")
|
global musicFormat
|
||||||
|
print("### CONVERTING TO " + musicFormat.upper() + " ###")
|
||||||
raw_audio = AudioSegment.from_file(filename, format="ogg",
|
raw_audio = AudioSegment.from_file(filename, format="ogg",
|
||||||
frame_rate=44100, channels=2, sample_width=2)
|
frame_rate=44100, channels=2, sample_width=2)
|
||||||
if quality == AudioQuality.VERY_HIGH:
|
if quality == AudioQuality.VERY_HIGH:
|
||||||
bitrate = "320k"
|
bitrate = "320k"
|
||||||
else:
|
else:
|
||||||
bitrate = "160k"
|
bitrate = "160k"
|
||||||
raw_audio.export(filename, format="mp3", bitrate=bitrate)
|
raw_audio.export(filename, format=musicFormat, bitrate=bitrate)
|
||||||
|
|
||||||
def setAudioTags(filename, artists, name, albumName, releaseYear, disc_number, track_number):
|
def setAudioTags(filename, artists, name, albumName, releaseYear, disc_number, track_number):
|
||||||
print("### SETTING MUSIC TAGS ###")
|
print("### SETTING MUSIC TAGS ###")
|
||||||
@ -380,13 +381,13 @@ def get_saved_tracks(access_token):
|
|||||||
|
|
||||||
#Functions directly related to downloading stuff
|
#Functions directly related to downloading stuff
|
||||||
def downloadTrack(track_id_str: str, extra_paths = ""):
|
def downloadTrack(track_id_str: str, extra_paths = ""):
|
||||||
global rootPath, skipExistingFiles
|
global rootPath, skipExistingFiles, musicFormat
|
||||||
|
|
||||||
track_id = TrackId.from_base62(track_id_str)
|
track_id = TrackId.from_base62(track_id_str)
|
||||||
artists, albumName, name, imageUrl, releaseYear, disc_number, track_number, scrapedSongId, isPlayAble = getSongInfo(track_id_str)
|
artists, albumName, name, imageUrl, releaseYear, disc_number, track_number, scrapedSongId, isPlayAble = getSongInfo(track_id_str)
|
||||||
|
|
||||||
songName = artists[0] + " - " + name
|
songName = artists[0] + " - " + name
|
||||||
filename = rootPath + extra_paths + songName + '.mp3'
|
filename = rootPath + extra_paths + songName + '.' + musicFormat
|
||||||
|
|
||||||
|
|
||||||
if not isPlayAble:
|
if not isPlayAble:
|
||||||
@ -446,7 +447,7 @@ def downloadTrack(track_id_str: str, extra_paths = ""):
|
|||||||
bpos = 0
|
bpos = 0
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
convertToMp3(filename)
|
convertAudioFormat(filename)
|
||||||
except:
|
except:
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
print("### SKIPPING:", songName, "(GENERAL CONVERSION ERROR) ###")
|
print("### SKIPPING:", songName, "(GENERAL CONVERSION ERROR) ###")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user