Skip to content

Commit

Permalink
able to rename playlist fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshwaran01 committed Jun 18, 2023
1 parent 9364475 commit e35b08c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,23 @@ Commands:
python main.py create <spotify_playlist_id>
```

```txt
Usage: main.py create [OPTIONS] SPOTIFY_PLAYLIST_ID
Create a YouTube Playlist from Spotify Playlist
Options:
--public create a public playlist
-n, --name TEXT Name of the YouTube playlist to be created
-d, --description TEXT Description of the playlist
--help
```

It will open the browser for authorization. Sign up with your google account to create playlist.

use `--public` flag to create a public playlist
use `--name` to name the playlist
use `--description` to set the description of the playlist

```bash
python main.py create <spotify_playlist_id> --public
Expand Down
40 changes: 32 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click
import logging
import time
import datetime

from spotify_client import SpotifyClient
from youtube_client import YouTubeClient
Expand All @@ -20,7 +21,9 @@ def cli():
@click.command()
@click.argument("spotify_playlist_id")
@click.option("--public", is_flag=True, help="create a public playlist")
def create(spotify_playlist_id: str, public: bool):
@click.option("--name", "-n", help="Name of the YouTube playlist to be created")
@click.option("--description", "-d", help="Description of the playlist")
def create(spotify_playlist_id: str, public: bool, name: str, description: str):
"""Create a YouTube Playlist from Spotify Playlist"""

spotify = SpotifyClient()
Expand All @@ -32,12 +35,31 @@ def create(spotify_playlist_id: str, public: bool):
privacy_status = "public"
else:
privacy_status = "private"

youtube_playlist_id = youtube.create_playlist(
spotify_playlist.name,
spotify_playlist.description,
privacy_status=privacy_status,
)["id"]

if name and description:
youtube_playlist_id = youtube.create_playlist(
name,
description,
privacy_status=privacy_status,
)["id"]
elif description:
youtube_playlist_id = youtube.create_playlist(
spotify_playlist.name,
description,
privacy_status=privacy_status,
)["id"]
elif name:
youtube_playlist_id = youtube.create_playlist(
name,
spotify_playlist.description,
privacy_status=privacy_status,
)["id"]
else:
youtube_playlist_id = youtube.create_playlist(
spotify_playlist.name,
spotify_playlist.description,
privacy_status=privacy_status,
)["id"]

for track in spotify_playlist.tracks:
logging.info(f"Searching for {track}")
Expand Down Expand Up @@ -101,7 +123,9 @@ def sync(spotify_playlist_id: str, youtube_playlist_id: str):
for song in songs_to_be_removed:
youtube.remove_song_playlist(youtube_playlist_id, song)

logging.info("Synced ..")
t = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

logging.info(f"Spotify playlist {spotify_playlist.name} Synced on {t}")
logging.info(
f"Playlist found at https://www.youtube.com/playlist?list={youtube_playlist_id}"
)
Expand Down

0 comments on commit e35b08c

Please sign in to comment.