Skip to content

Commit

Permalink
fix CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Apr 8, 2023
1 parent 3b6ab66 commit 7f47f5c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
9 changes: 5 additions & 4 deletions spotify_to_ytmusic/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def all(args):
playlist_id = ytmusic.create_playlist(
p["name"],
p["description"],
"PUBLIC" if args.public else "PRIVATE",
"PUBLIC" if p['public'] else "PRIVATE",
videoIds,
)
print(playlist_id)
Expand All @@ -47,7 +47,7 @@ def create(args):
if args.date:
date = " " + datetime.today().strftime("%m/%d/%Y")

playlist = _get_spotify_playlist(args.playlist)
playlist = _get_spotify_playlist(spotify, args.playlist)
name = args.name + date if args.name else playlist["name"] + date
info = playlist["description"] if (args.info is None) else args.info
videoIds = ytmusic.search_songs(playlist["tracks"])
Expand All @@ -63,10 +63,11 @@ def create(args):

def update(args):
spotify, ytmusic = _init()
playlist = _get_spotify_playlist(args.playlist)
playlist = _get_spotify_playlist(spotify, args.playlist)
playlistId = ytmusic.get_playlist_id(args.name)
videoIds = ytmusic.search_songs(playlist["tracks"])
ytmusic.remove_songs(playlistId)
if not args.append:
ytmusic.remove_songs(playlistId)
ytmusic.add_playlist_items(playlistId, videoIds)


Expand Down
24 changes: 12 additions & 12 deletions spotify_to_ytmusic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@ def get_args(args=None):
setup_parser.set_defaults(func=controllers.setup)
setup_parser.add_argument("--file", type=Path, help="Optional path to a settings.ini file")

playlist_creator = argparse.ArgumentParser(add_help=False)
playlist_creator.add_argument(
"-p",
"--public",
action="store_true",
help="Make created playlist public. Default: private",
)
spotify_playlist = argparse.ArgumentParser(add_help=False)
spotify_playlist.add_argument("playlist", type=str, help="Provide a playlist Spotify link.")

create_parser = subparsers.add_parser(
"create",
help="Create a new playlist on YouTube Music.",
parents=[playlist_creator],
parents=[spotify_playlist],
)
create_parser.set_defaults(func=controllers.create)
create_parser.add_argument("playlist", type=str, help="Provide a playlist Spotify link.")
create_parser.add_argument(
"-d",
"--date",
Expand All @@ -45,10 +39,17 @@ def get_args(args=None):
type=str,
help="Provide a name for the YouTube Music playlist. Default: Spotify playlist name",
)
create_parser.add_argument(
"-p",
"--public",
action="store_true",
help="Make created playlist public. Default: private",
)

update_parser = subparsers.add_parser(
"update",
help="Delete all entries in the provided Google Play Music playlist and update the playlist with entries from the Spotify playlist.",
parents=[spotify_playlist],
)
update_parser.set_defaults(func=controllers.update)
update_parser.add_argument(
Expand All @@ -66,10 +67,9 @@ def get_args(args=None):

all_parser = subparsers.add_parser(
"all",
help="Transfer all public playlists of the specified user (Spotify User ID).",
parents=[playlist_creator],
help="Transfer all public playlists of the specified user (Spotify User ID)."
)
update_parser.add_argument(
all_parser.add_argument(
"user", type=str, help="Spotify userid of the specified user."
)
all_parser.set_defaults(func=controllers.all)
Expand Down
2 changes: 1 addition & 1 deletion spotify_to_ytmusic/ytmusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def search_songs(self, tracks):
videoIds = []
songs = list(tracks)
notFound = list()
print("Searching YouTube...")
for i, song in enumerate(songs):
name = re.sub(r" \(feat.*\..+\)", "", song["name"])
query = song["artist"] + " " + name
Expand All @@ -36,7 +37,6 @@ def search_songs(self, tracks):
else:
videoIds.append(targetSong)

print("Searching YouTube...")
if i > 0 and i % 10 == 0:
print(f"YouTube tracks: {i}/{len(songs)}")

Expand Down

0 comments on commit 7f47f5c

Please sign in to comment.