Skip to content

Commit

Permalink
add credential validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Apr 18, 2023
1 parent 3bd1b2c commit e4151e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion spotify_to_ytmusic/spotify.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import html
import string
from urllib.parse import urlparse

import spotipy
Expand All @@ -11,8 +12,18 @@ class Spotify:
def __init__(self):
settings = Settings()
conf = settings["spotify"]
client_id = conf["client_id"]

assert set(client_id).issubset(
string.hexdigits
), f"Spotify client_id not set or invalid: {client_id}"
client_secret = conf["client_secret"]
assert set(client_secret).issubset(
string.hexdigits
), f"Spotify client_secret not set or invalid: {client_secret}"

client_credentials_manager = SpotifyClientCredentials(
client_id=conf["client_id"], client_secret=conf["client_secret"]
client_id=client_id, client_secret=client_secret
)
self.api = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

Expand Down
4 changes: 3 additions & 1 deletion spotify_to_ytmusic/ytmusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
class YTMusicTransfer:
def __init__(self):
settings = Settings()
self.api = YTMusic(settings["youtube"]["headers"], settings["youtube"]["user_id"])
headers = settings["youtube"]["headers"]
assert headers.startswith("{"), "ytmusicapi headers not set or invalid"
self.api = YTMusic(headers, settings["youtube"]["user_id"])

def create_playlist(self, name, info, privacy="PRIVATE", tracks=None):
return self.api.create_playlist(name, info, privacy, video_ids=tracks)
Expand Down

0 comments on commit e4151e8

Please sign in to comment.