def validate_spotify_url(url): """ Validate the URL and determine if the item type is supported. :return Boolean indicating whether or not item is supported """ item_type, item_id = parse_spotify_url(url) log.debug(f"Got item type {item_type} and item_id {item_id}") if item_type not in ['album', 'track', 'playlist']: log.error("Only albums/tracks/playlists are supported") return False if item_id is None: log.error("Couldn't get a valid id") return False return True
def parse_spotify_url(url): """ Parse the provided Spotify playlist URL and determine if it is a playlist, track or album. :param url: URL to be parsed :return tuple indicating the type and id of the item """ if url.startswith("spotify:"): log.error("Spotify URI was provided instead of a playlist/album/track URL.") sys.exit(1) parsed_url = url.replace("https://open.spotify.com/", "") item_type = parsed_url.split("/")[0] item_id = parsed_url.split("/")[1] return item_type, item_id
def validate_spotify_url(url): """ Validate the URL to determine if the item type is supported. :return Boolean . """ type, id = parse_spotify_url(url) log.debug(f" item type :{type} ; item_id: {id}") if type not in ['album', 'track', 'playlist']: log.error("Only albums/tracks/playlists are supported") return False if id is None: log.error("Couldn't get a valid id") return False return True
def parse_spotify_url(url): """ Parse the provided Spotify playlist URL and determine if it is a playlist, track or album. :param url: URL to be parsed :param download_directory: Location where to save :param format_string: format string for the file conversion :return tuple indicating the type and id of the item """ if url.startswith("spotify:"): log.error( "Spotify URI was provided instead of a playlist/album/track URL.") sys.exit(1) parsed_url = url.replace("https://open.spotify.com/", "") item_type = parsed_url.split("/")[0] item_id = parsed_url.split("/")[1] return item_type, item_id