diff --git a/ytm2spt.py b/ytm2spt.py index 924f940..c21218e 100644 --- a/ytm2spt.py +++ b/ytm2spt.py @@ -318,14 +318,9 @@ def run_command(self): create_new = self.create_new_checkbox.isChecked() limit = self.limit_input.value() if self.limit_input.value() > 0 else None - os.environ["SPOTIFY_USER_ID"] = SETTINGS.value("SPOTIFY_USER_ID") - os.environ["SPOTIFY_CLIENT_ID"] = SETTINGS.value("SPOTIFY_CLIENT_ID") - os.environ["SPOTIFY_CLIENT_SECRET"] = SETTINGS.value("SPOTIFY_CLIENT_SECRET") - os.environ["SPOTIFY_REDIRECT_URI"] = SETTINGS.value("SPOTIFY_REDIRECT_URI") - # Run ytm2spt self.worker = RunCommandWorker(youtube_arg, spotify_arg, spotify_playlist_name, youtube_oauth, dry_run, create_new, limit) - self.worker.finished.connect(self.run_finished) + self.worker.completed.connect(self.run_finished) self.worker.error.connect(self.run_error) self.worker.start() @@ -355,7 +350,7 @@ def yt_private_toggled(self): class RunCommandWorker(QThread): - finished = Signal() + completed = Signal() error = Signal(str) def __init__(self, youtube_arg, spotify_arg, spotify_playlist_name, youtube_oauth, dry_run, create_new, limit): @@ -370,8 +365,12 @@ def __init__(self, youtube_arg, spotify_arg, spotify_playlist_name, youtube_oaut def run(self): try: + os.environ["SPOTIFY_USER_ID"] = SETTINGS.value("SPOTIFY_USER_ID") + os.environ["SPOTIFY_CLIENT_ID"] = SETTINGS.value("SPOTIFY_CLIENT_ID") + os.environ["SPOTIFY_CLIENT_SECRET"] = SETTINGS.value("SPOTIFY_CLIENT_SECRET") + os.environ["SPOTIFY_REDIRECT_URI"] = SETTINGS.value("SPOTIFY_REDIRECT_URI") ytm2spt.main(self.youtube_arg, self.spotify_arg, self.spotify_playlist_name, self.youtube_oauth, self.dry_run, self.create_new, self.limit) - self.finished.emit() + self.completed.emit() except Exception as e: print(e) print(traceback.format_exc()) diff --git a/ytm2spt/__init__.py b/ytm2spt/__init__.py index 81958fe..fb31b03 100644 --- a/ytm2spt/__init__.py +++ b/ytm2spt/__init__.py @@ -146,6 +146,8 @@ def main(youtube_arg, spotify_arg, spotify_playlist_name, youtube_oauth, dryrun, if dryrun: ytm2spt_logger.info("Dryrun mode enabled. No songs will be added to Spotify.") else: + if not (spotify_arg or spotify_playlist_name): + spotify_playlist_name = yt.get_playlist_title() spotify_id = get_spotify_playlist_id(spotify_arg, spotify_playlist_name, create_new, dryrun) ytm2spt_logger.info(f"Spotify Playlist ID: {spotify_id}") sp.set_playlist_id(spotify_id) diff --git a/ytm2spt/spotify.py b/ytm2spt/spotify.py index 722de62..b176470 100755 --- a/ytm2spt/spotify.py +++ b/ytm2spt/spotify.py @@ -17,11 +17,11 @@ def generate_description() -> str: class Spotify: def __init__(self): - self.user_id = os.getenv('SPOTIFY_USER_ID') + self.user_id = os.environ["SPOTIFY_USER_ID"] self.spotify = spotipy.Spotify(auth_manager=SpotifyOAuth( - client_id=os.getenv('SPOTIFY_CLIENT_ID'), - client_secret=os.getenv('SPOTIFY_CLIENT_SECRET'), - redirect_uri=os.getenv('SPOTIFY_REDIRECT_URI'), + client_id=os.environ['SPOTIFY_CLIENT_ID'], + client_secret=os.environ['SPOTIFY_CLIENT_SECRET'], + redirect_uri=os.environ['SPOTIFY_REDIRECT_URI'], scope='playlist-read-collaborative playlist-modify-private playlist-modify-public playlist-read-private ugc-image-upload' )) self.playlist_id = ""