Skip to content

Commit

Permalink
Error detection on create_playlist call to ytmusicapi
Browse files Browse the repository at this point in the history
  • Loading branch information
linsomniac committed Jan 13, 2024
1 parent 8c56ccf commit a7966ae
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions spotify2ytmusic/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,22 @@ def parse_arguments():
src_pl_id = args.spotify_playlist_id
dst_pl_id = args.ytmusic_playlist_id

yt = get_ytmusic()
if dst_pl_id.startswith("+"):
yt = get_ytmusic()
pl_name = dst_pl_id[1:]

dst_pl_id = get_playlist_id_by_name(yt, pl_name)
print(f"Looking up playlist '{pl_name}': id={dst_pl_id}")
if dst_pl_id is None:
dst_pl_id = yt.create_playlist(title=pl_name, description=pl_name)

# create_playlist returns a dict if there was an error
if isinstance(dst_pl_id, dict):
print(f"ERROR: Failed to create playlist: {dst_pl_id}")
sys.exit(1)
print(f"NOTE: Created playlist '{pl_name}' with ID: {dst_pl_id}")

copier(src_pl_id, dst_pl_id, args.dry_run, args.track_sleep)
copier(src_pl_id, dst_pl_id, args.dry_run, args.track_sleep, yt=yt)


def copier(
Expand All @@ -193,8 +198,11 @@ def copier(
dry_run: bool = False,
track_sleep: float = 0.1,
spotify_playlist_file: str = "playlists.json",
*,
yt: Optional[YTMusic] = None,
):
yt = get_ytmusic()
if yt is None:
yt = get_ytmusic()

spotify_pls = json.load(open(spotify_playlist_file, "r"))
if dst_pl_id is not None:
Expand Down

0 comments on commit a7966ae

Please sign in to comment.