mirror of
				https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
				synced 2025-11-03 21:10:34 +00:00 
			
		
		
		
	Added raw audio option
This commit is contained in:
		
							parent
							
								
									6616fd30f4
								
							
						
					
					
						commit
						f3da7398c7
					
				
							
								
								
									
										31
									
								
								zspotify.py
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								zspotify.py
									
									
									
									
									
								
							@ -20,12 +20,13 @@ from librespot.metadata import TrackId
 | 
				
			|||||||
from pydub import AudioSegment
 | 
					from pydub import AudioSegment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SESSION: Session = None
 | 
					SESSION: Session = None
 | 
				
			||||||
 | 
					sanitize = ["\\", "/", ":", "*", "?", "'", "<", ">", '"']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ROOT_PATH = "ZSpotify Music/"
 | 
					ROOT_PATH = "ZSpotify Music/"
 | 
				
			||||||
SKIP_EXISTING_FILES = True
 | 
					SKIP_EXISTING_FILES = True
 | 
				
			||||||
MUSIC_FORMAT = "mp3"  # or "ogg"
 | 
					MUSIC_FORMAT = "mp3"  # or "ogg"
 | 
				
			||||||
FORCE_PREMIUM = False # set to True if not detecting your premium account automatically
 | 
					FORCE_PREMIUM = False # set to True if not detecting your premium account automatically
 | 
				
			||||||
sanitize = ["\\", "/", ":", "*", "?", "'", "<", ">", '"']
 | 
					RAW_AUDIO_AS_IS = False # set to True if you wish you save the raw audio without re-encoding it.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# miscellaneous functions for general use
 | 
					# miscellaneous functions for general use
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -411,7 +412,7 @@ def get_saved_tracks(access_token):
 | 
				
			|||||||
# Functions directly related to downloading stuff
 | 
					# Functions directly related to downloading stuff
 | 
				
			||||||
def download_track(track_id_str: str, extra_paths=""):
 | 
					def download_track(track_id_str: str, extra_paths=""):
 | 
				
			||||||
    """ Downloads raw song audio from Spotify """
 | 
					    """ Downloads raw song audio from Spotify """
 | 
				
			||||||
    global ROOT_PATH, SKIP_EXISTING_FILES, MUSIC_FORMAT
 | 
					    global ROOT_PATH, SKIP_EXISTING_FILES, MUSIC_FORMAT, RAW_AUDIO_AS_IS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    track_id = TrackId.from_base62(track_id_str)
 | 
					    track_id = TrackId.from_base62(track_id_str)
 | 
				
			||||||
    artists, album_name, name, image_url, release_year, disc_number, track_number, scraped_song_id, is_playable = get_song_info(
 | 
					    artists, album_name, name, image_url, release_year, disc_number, track_number, scraped_song_id, is_playable = get_song_info(
 | 
				
			||||||
@ -452,16 +453,17 @@ def download_track(track_id_str: str, extra_paths=""):
 | 
				
			|||||||
                        if byte == b'':
 | 
					                        if byte == b'':
 | 
				
			||||||
                            break
 | 
					                            break
 | 
				
			||||||
                        file.write(byte)
 | 
					                        file.write(byte)
 | 
				
			||||||
                try:
 | 
					                if not RAW_AUDIO_AS_IS:
 | 
				
			||||||
                    convert_audio_format(filename)
 | 
					                    try:
 | 
				
			||||||
                except:
 | 
					                        convert_audio_format(filename)
 | 
				
			||||||
                    os.remove(filename)
 | 
					                    except:
 | 
				
			||||||
                    print("###   SKIPPING:", song_name,
 | 
					                        os.remove(filename)
 | 
				
			||||||
                          "(GENERAL CONVERSION ERROR)   ###")
 | 
					                        print("###   SKIPPING:", song_name,
 | 
				
			||||||
                else:
 | 
					                            "(GENERAL CONVERSION ERROR)   ###")
 | 
				
			||||||
                    set_audio_tags(filename, artists, name, album_name,
 | 
					                    else:
 | 
				
			||||||
                                   release_year, disc_number, track_number)
 | 
					                        set_audio_tags(filename, artists, name, album_name,
 | 
				
			||||||
                    set_music_thumbnail(filename, image_url)
 | 
					                                    release_year, disc_number, track_number)
 | 
				
			||||||
 | 
					                        set_music_thumbnail(filename, image_url)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def download_album(album):
 | 
					def download_album(album):
 | 
				
			||||||
@ -495,9 +497,14 @@ def download_from_user_playlist():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Core functions here
 | 
					# Core functions here
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def checkRaw():
 | 
				
			||||||
 | 
					    global RAW_AUDIO_AS_IS, MUSIC_FORMAT
 | 
				
			||||||
 | 
					    if RAW_AUDIO_AS_IS:
 | 
				
			||||||
 | 
					        MUSIC_FORMAT = "raw"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
    """ Main function """
 | 
					    """ Main function """
 | 
				
			||||||
 | 
					    checkRaw()
 | 
				
			||||||
    login()
 | 
					    login()
 | 
				
			||||||
    client()
 | 
					    client()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user