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

Readded playlist to like action from guglielmobartelloni:playlist-to-like #102

Merged
merged 8 commits into from
Jun 18, 2024
Merged
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
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ spotify_to_ytmusic
A simple command line script to clone a Spotify playlist to YouTube Music.

- Transfer a single Spotify playlist
- Like all the songs in a Spotify playlist
- Update a transferred playlist on YouTube Music
- Transfer all playlists for a Spotify user
- Like all songs from all playlists for a Spotify user
- Remove playlists from YouTube Music


Expand Down
6 changes: 6 additions & 0 deletions spotify_to_ytmusic/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def all(args):
"PUBLIC" if p["public"] else "PRIVATE",
videoIds,
)
if args.like:
for id in videoIds:
ytmusic.rate_song(id, "LIKE")
_print_success(p["name"], playlist_id)
except Exception as ex:
print(f"Could not transfer playlist {p['name']}. {str(ex)}")
Expand All @@ -58,6 +61,9 @@ def _create_ytmusic(args, playlist, ytmusic):
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"])
if args.like:
for id in videoIds:
ytmusic.rate_song(id, "LIKE")

playlistId = ytmusic.create_playlist(
name, info, "PUBLIC" if args.public else "PRIVATE", videoIds
Expand Down
12 changes: 12 additions & 0 deletions spotify_to_ytmusic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def get_args(args=None):
action="store_true",
help="Make created playlist public. Default: private",
)
spotify_playlist_create.add_argument(
"-l",
"--like",
action="store_true",
help="Like the songs in the specified playlist",
)

create_parser = subparsers.add_parser(
"create",
Expand Down Expand Up @@ -77,6 +83,12 @@ def get_args(args=None):
)
all_parser.add_argument("user", type=str, help="Spotify userid of the specified user.")
all_parser.set_defaults(func=controllers.all)
all_parser.add_argument(
"-l",
"--like",
action="store_true",
help="Like the songs in all of the public playlist",
)

return parser.parse_args(args)

Expand Down
3 changes: 3 additions & 0 deletions spotify_to_ytmusic/ytmusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def __init__(self):
def create_playlist(self, name, info, privacy="PRIVATE", tracks=None):
return self.api.create_playlist(name, info, privacy, video_ids=tracks)

def rate_song(self, id, rating):
return self.api.rate_song(id, rating)

def search_songs(self, tracks):
videoIds = []
songs = list(tracks)
Expand Down