Skip to content

Commit 2f1b20f

Browse files
committed
config default would be config.cfg but in current directory of shell
1 parent 28a161d commit 2f1b20f

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ Options:
5252
Spotify playlist name, ID, URL, or URI;
5353
repeatable.
5454
-l, --list List available playlists.
55-
-c, --config PATH Path to configuration file. [default:
56-
config.cfg]
57-
-o, --output PATH Directory to save exported files. [default:
58-
./playlists]
59-
-f, --format [csv|json] Output file format. [default: csv]
55+
-c, --config PATH Path to configuration file (if omitted, uses
56+
./config.cfg next to this script).
57+
-o, --output PATH Directory to save exported files (if
58+
omitted, uses ./playlists).
59+
-f, --format [csv|json] Output file format (if omitted, defaults to
60+
'csv').
6061
--uris Include album and artist URIs.
6162
--external-ids Include track ISRC and album UPC.
6263
--no-bar Hide progress bar.

exportify-cli.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ def load_config(config_path: Path) -> configparser.ConfigParser:
102102
Copy the Client ID, Client Secret and Redirect URI and paste them below.""")
103103

104104
spotify_cfg = {
105-
"client_id": click.prompt("Spotify Client ID", type=str),
105+
"client_id": click.prompt("Spotify Client ID", type=str).strip(),
106106
"client_secret": click.prompt(
107107
"Spotify Client Secret",
108108
hide_input=True,
109109
type=str,
110-
),
110+
).strip(),
111111
"redirect_uri": click.prompt(
112112
"Redirect URI",
113113
type=str,
114114
default="http://127.0.1:3000/callback",
115-
),
115+
).strip(),
116116
}
117117

118118
config["spotify"] = spotify_cfg
@@ -122,7 +122,7 @@ def load_config(config_path: Path) -> configparser.ConfigParser:
122122
# Write initial config
123123
with config_path.open("w") as f:
124124
config.write(f)
125-
logger.info(f"Wrote new config to {config_path}")
125+
logger.info(f"Wrote new config to {config_path}")
126126
# Add CLI defaults
127127
ensure_exportify_cli(config, config_path)
128128
return config
@@ -143,8 +143,7 @@ def init_spotify_client(cfg: configparser.ConfigParser) -> spotipy.Spotify:
143143
client_secret=creds["client_secret"],
144144
redirect_uri=creds["redirect_uri"],
145145
scope="playlist-read-private playlist-read-collaborative user-library-read",
146-
open_browser=True,
147-
cache_path=".cache",
146+
cache_path=Path(__file__).parent / Path(".cache"),
148147
)
149148
return spotipy.Spotify(auth_manager=auth, retries=10)
150149

@@ -463,28 +462,25 @@ def format_usage(self, ctx, formatter) -> None:
463462
"-c",
464463
"--config",
465464
"config",
466-
default="config.cfg",
467-
show_default=True,
465+
default=None,
468466
type=click.Path(),
469-
help="Path to configuration file.",
467+
help="Path to configuration file (if omitted, uses ./config.cfg next to this script).",
470468
)
471469
@optgroup.option(
472470
"-o",
473471
"--output",
474472
"output_param",
475473
default="./playlists",
476-
show_default=True,
477474
type=click.Path(),
478-
help="Directory to save exported files.",
475+
help="Directory to save exported files (if omitted, uses ./playlists).",
479476
)
480477
@optgroup.option(
481478
"-f",
482479
"--format",
483480
"format_param",
484481
type=click.Choice(["csv", "json"]),
485482
default="csv",
486-
show_default=True,
487-
help="Output file format.",
483+
help="Output file format (if omitted, defaults to 'csv').",
488484
)
489485
@optgroup.option(
490486
"--uris",
@@ -519,7 +515,7 @@ def main(
519515
export_all: bool,
520516
playlist: tuple[str, ...],
521517
list_only: bool,
522-
config: str,
518+
config: None | str,
523519
output_param: str,
524520
format_param: str,
525521
uris_flag: bool,
@@ -532,7 +528,12 @@ def main(
532528
click.echo(main.get_help(ctx=click.get_current_context()))
533529
sys.exit(1)
534530

535-
cfg_path = Path(config)
531+
if config:
532+
cfg_path = Path(config).expanduser()
533+
if cfg_path.is_dir():
534+
cfg_path = cfg_path / Path("config.cfg")
535+
else:
536+
cfg_path = Path(__file__).parent / Path("config.cfg")
536537
cfg = load_config(cfg_path)
537538

538539
# Resolve config vs CLI

0 commit comments

Comments
 (0)