def create_backup(self, playlist, extra): safe_name = playlist.name.translate( str.maketrans(" @`!\"#$%&'()*+;[{<\\|]}>^~/?", "_" * 27)) filename = (Extension.get_data_dir(self._backend._config) / f"{safe_name}-{playlist.uri}-{extra}-{time.time()}.m3u8") with filename.open("w") as f: f.write("#EXTM3U\n#EXTENC: UTF-8\n\n") for track in playlist.tracks: length = int(track.length / 1000) artists = ", ".join(a.name for a in track.artists) f.write(f"#EXTINF:{length},{artists} - {track.name}\n" f"{track.uri}\n\n") return str(filename)
def _get_spotify_config(self, config): ext = Extension() spotify_config = spotify.Config() spotify_config.load_application_key_file( os.path.join(os.path.dirname(__file__), 'spotify_appkey.key')) if config['spotify']['allow_cache']: spotify_config.cache_location = ext.get_cache_dir(config) else: spotify_config.cache_location = None spotify_config.settings_location = ext.get_data_dir(config) proxy_uri = httpclient.format_proxy(config['proxy'], auth=False) if proxy_uri is not None: logger.debug('Connecting to Spotify through proxy: %s', proxy_uri) spotify_config.proxy = proxy_uri spotify_config.proxy_username = config['proxy'].get('username') spotify_config.proxy_password = config['proxy'].get('password') return spotify_config
def _get_spotify_config(self, config): ext = Extension() spotify_config = spotify.Config() spotify_config.load_application_key_file( os.path.join(os.path.dirname(__file__), 'spotify_appkey.key')) if config['spotify']['allow_cache']: spotify_config.cache_location = ext.get_cache_dir(config) else: spotify_config.cache_location = None spotify_config.settings_location = ext.get_data_dir(config) proxy_uri = httpclient.format_proxy(config['proxy'], auth=False) if proxy_uri is not None: logger.debug('Connecting to Spotify through proxy: %s', proxy_uri) spotify_config.proxy = proxy_uri spotify_config.proxy_username = config['proxy'].get('username') spotify_config.proxy_password = config['proxy'].get('password') return spotify_config
def _get_spotify_config(self, config): ext = Extension() spotify_config = spotify.Config() spotify_config.load_application_key_file( pathlib.Path(__file__).parent / "spotify_appkey.key") if config["spotify"]["allow_cache"]: spotify_config.cache_location = bytes(ext.get_cache_dir(config)) else: spotify_config.cache_location = None spotify_config.settings_location = bytes(ext.get_data_dir(config)) proxy_uri = httpclient.format_proxy(config["proxy"], auth=False) if proxy_uri is not None: logger.debug(f"Connecting to Spotify through proxy: {proxy_uri}") spotify_config.proxy = proxy_uri spotify_config.proxy_username = config["proxy"].get("username") spotify_config.proxy_password = config["proxy"].get("password") return spotify_config