mirror of
				https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
				synced 2025-11-04 05:20:34 +00:00 
			
		
		
		
	Fixed premium account check
This commit is contained in:
		
							parent
							
								
									8c2a83d51e
								
							
						
					
					
						commit
						ab2c64f84a
					
				
							
								
								
									
										20
									
								
								zspotify.py
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								zspotify.py
									
									
									
									
									
								
							@ -27,8 +27,9 @@ 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
 | 
				
			||||||
RAW_AUDIO_AS_IS = False # set to True if you wish you save the raw audio without re-encoding it.
 | 
					# set to True if you wish you save the raw audio without re-encoding it.
 | 
				
			||||||
 | 
					RAW_AUDIO_AS_IS = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# miscellaneous functions for general use
 | 
					# miscellaneous functions for general use
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -93,7 +94,7 @@ def client():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    token = SESSION.tokens().get("user-read-email")
 | 
					    token = SESSION.tokens().get("user-read-email")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if check_premium(token):
 | 
					    if check_premium():
 | 
				
			||||||
        print("###   DETECTED PREMIUM ACCOUNT - USING VERY_HIGH QUALITY   ###")
 | 
					        print("###   DETECTED PREMIUM ACCOUNT - USING VERY_HIGH QUALITY   ###")
 | 
				
			||||||
        QUALITY = AudioQuality.VERY_HIGH
 | 
					        QUALITY = AudioQuality.VERY_HIGH
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
@ -259,13 +260,10 @@ def get_song_info(song_id):
 | 
				
			|||||||
    return artists, album_name, name, image_url, release_year, disc_number, track_number, scraped_song_id, is_playable
 | 
					    return artists, album_name, name, image_url, release_year, disc_number, track_number, scraped_song_id, is_playable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def check_premium(access_token):
 | 
					def check_premium():
 | 
				
			||||||
    global FORCE_PREMIUM
 | 
					    global FORCE_PREMIUM
 | 
				
			||||||
    """ If user has spotify premium return true """
 | 
					    """ If user has spotify premium return true """
 | 
				
			||||||
    headers = {'Authorization': f'Bearer {access_token}'}
 | 
					    return bool((SESSION.get_user_attribute("type") == "premium") or FORCE_PREMIUM)
 | 
				
			||||||
    resp = requests.get('https://api.spotify.com/v1/me',
 | 
					 | 
				
			||||||
                        headers=headers).json()
 | 
					 | 
				
			||||||
    return bool(("product" in resp and resp["product"] == "premium") or FORCE_PREMIUM)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Functions directly related to modifying the downloaded audio and its metadata
 | 
					# Functions directly related to modifying the downloaded audio and its metadata
 | 
				
			||||||
@ -458,10 +456,10 @@ def download_track(track_id_str: str, extra_paths=""):
 | 
				
			|||||||
                    except:
 | 
					                    except:
 | 
				
			||||||
                        os.remove(filename)
 | 
					                        os.remove(filename)
 | 
				
			||||||
                        print("###   SKIPPING:", song_name,
 | 
					                        print("###   SKIPPING:", song_name,
 | 
				
			||||||
                            "(GENERAL CONVERSION ERROR)   ###")
 | 
					                              "(GENERAL CONVERSION ERROR)   ###")
 | 
				
			||||||
                    else:
 | 
					                    else:
 | 
				
			||||||
                        set_audio_tags(filename, artists, name, album_name,
 | 
					                        set_audio_tags(filename, artists, name, album_name,
 | 
				
			||||||
                                    release_year, disc_number, track_number)
 | 
					                                       release_year, disc_number, track_number)
 | 
				
			||||||
                        set_music_thumbnail(filename, image_url)
 | 
					                        set_music_thumbnail(filename, image_url)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -496,11 +494,13 @@ def download_from_user_playlist():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Core functions here
 | 
					# Core functions here
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def checkRaw():
 | 
					def checkRaw():
 | 
				
			||||||
    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 = "raw"
 | 
					        MUSIC_FORMAT = "raw"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
    """ Main function """
 | 
					    """ Main function """
 | 
				
			||||||
    checkRaw()
 | 
					    checkRaw()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user