Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append to playlist if its already existing #109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions spotify2ytmusic/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,26 +453,31 @@ def copy_playlist(
ytmusic_playlist_id = get_playlist_id_by_name(yt, pl_name)
print(f"Looking up playlist '{pl_name}': id={ytmusic_playlist_id}")

if ytmusic_playlist_id is None:
if not ytmusic_playlist_id or ytmusic_playlist_id is None:
if pl_name == "":
print("No playlist name or ID provided, creating playlist...")
spotify_pls: dict = load_playlists_json()
for pl in spotify_pls["playlists"]:
if len(pl.keys()) > 3 and pl["id"] == spotify_playlist_id:
pl_name = pl["name"]

ytmusic_playlist_id = _ytmusic_create_playlist(
yt,
title=pl_name,
description=pl_name,
privacy_status=privacy_status,
)
ytmusic_playlist_id = get_playlist_id_by_name(yt, pl_name)

# create_playlist returns a dict if there was an error
if isinstance(ytmusic_playlist_id, dict):
print(f"ERROR: Failed to create playlist: {ytmusic_playlist_id}")
sys.exit(1)
print(f"NOTE: Created playlist '{pl_name}' with ID: {ytmusic_playlist_id}")
if not ytmusic_playlist_id:
ytmusic_playlist_id = _ytmusic_create_playlist(
yt,
title=pl_name,
description=pl_name,
privacy_status=privacy_status,
)

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

copier(
iter_spotify_playlist(
Expand Down
2 changes: 1 addition & 1 deletion spotify2ytmusic/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def __init__(self) -> None:
command=lambda: self.call_func(
func=backend.copy_playlist,
args=(
self.spotify_playlist_id.get(),
self.spotify_playlist_id.get().strip(),
self.yt_playlist_id.get(),
"utf-8",
False,
Expand Down