mirror of
				https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
				synced 2025-11-04 05:20:34 +00:00 
			
		
		
		
	cleaned up code using linter
This commit is contained in:
		
							parent
							
								
									2878f38808
								
							
						
					
					
						commit
						6e76f09421
					
				
							
								
								
									
										4
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "python.linting.pylintEnabled": true,
 | 
				
			||||||
 | 
					  "python.linting.enabled": true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										28
									
								
								zspotify.py
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								zspotify.py
									
									
									
									
									
								
							@ -51,8 +51,8 @@ def wait(seconds: int = 3):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def sanitize_data(value):
 | 
					def sanitize_data(value):
 | 
				
			||||||
    global sanitize
 | 
					 | 
				
			||||||
    """ Returns given string with problematic removed """
 | 
					    """ Returns given string with problematic removed """
 | 
				
			||||||
 | 
					    global sanitize
 | 
				
			||||||
    for i in sanitize:
 | 
					    for i in sanitize:
 | 
				
			||||||
        value = value.replace(i, "")
 | 
					        value = value.replace(i, "")
 | 
				
			||||||
    return value.replace("|", "-")
 | 
					    return value.replace("|", "-")
 | 
				
			||||||
@ -114,7 +114,7 @@ def client():
 | 
				
			|||||||
                    download_track(song['track']['id'], "Liked Songs/")
 | 
					                    download_track(song['track']['id'], "Liked Songs/")
 | 
				
			||||||
                print("\n")
 | 
					                print("\n")
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            track_id_str, album_id_str, playlist_id_str, episode_id_str = regexInputForUrls(
 | 
					            track_id_str, album_id_str, playlist_id_str, episode_id_str = regex_input_for_urls(
 | 
				
			||||||
                sys.argv[1])
 | 
					                sys.argv[1])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if track_id_str is not None:
 | 
					            if track_id_str is not None:
 | 
				
			||||||
@ -129,14 +129,14 @@ def client():
 | 
				
			|||||||
                                   sanitize_data(name) + "/")
 | 
					                                   sanitize_data(name) + "/")
 | 
				
			||||||
                    print("\n")
 | 
					                    print("\n")
 | 
				
			||||||
            elif episode_id_str is not None:
 | 
					            elif episode_id_str is not None:
 | 
				
			||||||
                downloadEpisode(episode_id_str)
 | 
					                download_episode(episode_id_str)
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        search_text = input("Enter search or URL: ")
 | 
					        search_text = input("Enter search or URL: ")
 | 
				
			||||||
        search(search_text)
 | 
					        search(search_text)
 | 
				
			||||||
    wait()
 | 
					    wait()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def regexInputForUrls(search_input):
 | 
					def regex_input_for_urls(search_input):
 | 
				
			||||||
    track_uri_search = re.search(
 | 
					    track_uri_search = re.search(
 | 
				
			||||||
        r"^spotify:track:(?P<TrackID>[0-9a-zA-Z]{22})$", search_input)
 | 
					        r"^spotify:track:(?P<TrackID>[0-9a-zA-Z]{22})$", search_input)
 | 
				
			||||||
    track_url_search = re.search(
 | 
					    track_url_search = re.search(
 | 
				
			||||||
@ -196,7 +196,7 @@ def regexInputForUrls(search_input):
 | 
				
			|||||||
    return track_id_str, album_id_str, playlist_id_str, episode_id_str
 | 
					    return track_id_str, album_id_str, playlist_id_str, episode_id_str
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def getEpisodeInfo(episode_id_str):
 | 
					def get_episode_info(episode_id_str):
 | 
				
			||||||
    token = SESSION.tokens().get("user-read-email")
 | 
					    token = SESSION.tokens().get("user-read-email")
 | 
				
			||||||
    info = json.loads(requests.get("https://api.spotify.com/v1/episodes/" +
 | 
					    info = json.loads(requests.get("https://api.spotify.com/v1/episodes/" +
 | 
				
			||||||
                                   episode_id_str, headers={"Authorization": "Bearer %s" % token}).text)
 | 
					                                   episode_id_str, headers={"Authorization": "Bearer %s" % token}).text)
 | 
				
			||||||
@ -207,14 +207,14 @@ def getEpisodeInfo(episode_id_str):
 | 
				
			|||||||
        return info["show"]["name"], info["name"]
 | 
					        return info["show"]["name"], info["name"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def downloadEpisode(episode_id_str):
 | 
					def download_episode(episode_id_str):
 | 
				
			||||||
    global ROOT_PODCAST_PATH
 | 
					    global ROOT_PODCAST_PATH
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    podcastName, episodeName = getEpisodeInfo(episode_id_str)
 | 
					    podcast_name, episode_name = get_episode_info(episode_id_str)
 | 
				
			||||||
    if podcastName == None:
 | 
					    if podcast_name is None:
 | 
				
			||||||
        print("###   SKIPPING: (EPISODE NOT FOUND)   ###")
 | 
					        print("###   SKIPPING: (EPISODE NOT FOUND)   ###")
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        filename = podcastName + " - " + episodeName + ".wav"
 | 
					        filename = podcast_name + " - " + episode_name + ".wav"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        episode_id = EpisodeId.from_base62(episode_id_str)
 | 
					        episode_id = EpisodeId.from_base62(episode_id_str)
 | 
				
			||||||
        stream = SESSION.content_feeder().load(
 | 
					        stream = SESSION.content_feeder().load(
 | 
				
			||||||
@ -342,8 +342,8 @@ def get_song_info(song_id):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def check_premium():
 | 
					def check_premium():
 | 
				
			||||||
    global FORCE_PREMIUM
 | 
					 | 
				
			||||||
    """ If user has spotify premium return true """
 | 
					    """ If user has spotify premium return true """
 | 
				
			||||||
 | 
					    global FORCE_PREMIUM
 | 
				
			||||||
    return bool((SESSION.get_user_attribute("type") == "premium") or FORCE_PREMIUM)
 | 
					    return bool((SESSION.get_user_attribute("type") == "premium") or FORCE_PREMIUM)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -386,8 +386,8 @@ def set_music_thumbnail(filename, image_url):
 | 
				
			|||||||
def conv_artist_format(artists):
 | 
					def conv_artist_format(artists):
 | 
				
			||||||
    """ Returns converted artist format """
 | 
					    """ Returns converted artist format """
 | 
				
			||||||
    formatted = ""
 | 
					    formatted = ""
 | 
				
			||||||
    for x in artists:
 | 
					    for artist in artists:
 | 
				
			||||||
        formatted += x + ", "
 | 
					        formatted += artist + ", "
 | 
				
			||||||
    return formatted[:-2]
 | 
					    return formatted[:-2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -575,7 +575,7 @@ def download_from_user_playlist():
 | 
				
			|||||||
# Core functions here
 | 
					# Core functions here
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def checkRaw():
 | 
					def check_raw():
 | 
				
			||||||
    global RAW_AUDIO_AS_IS, MUSIC_FORMAT
 | 
					    global RAW_AUDIO_AS_IS, MUSIC_FORMAT
 | 
				
			||||||
    if RAW_AUDIO_AS_IS:
 | 
					    if RAW_AUDIO_AS_IS:
 | 
				
			||||||
        MUSIC_FORMAT = "wav"
 | 
					        MUSIC_FORMAT = "wav"
 | 
				
			||||||
@ -583,7 +583,7 @@ def checkRaw():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
    """ Main function """
 | 
					    """ Main function """
 | 
				
			||||||
    checkRaw()
 | 
					    check_raw()
 | 
				
			||||||
    login()
 | 
					    login()
 | 
				
			||||||
    client()
 | 
					    client()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user