diff --git a/doc/default.env b/doc/default.env index f93f70f..f8899d4 100644 --- a/doc/default.env +++ b/doc/default.env @@ -10,4 +10,5 @@ WORKER_COUNT=4 #unless you have issues, 4 is a safe default. # SECONDS_INTERVAL=60 !!--DEPRECATED--!! MANUAL_PLAYLISTS= LIDARR_SYNC=False -CRON_SCHEDULE=0 1 * * * #Takes values that are compatible with supercronic. @daily recommended \ No newline at end of file +CRON_SCHEDULE=0 1 * * * #Takes values that are compatible with supercronic. @daily recommended +INCLUDE_PLAYLIST_AUTHOR="false" # Add the author of the playlist to the title (e.g. `My Favourites [John H.]`) diff --git a/doc/default_config.toml b/doc/default_config.toml index b3da2e2..090e041 100644 --- a/doc/default_config.toml +++ b/doc/default_config.toml @@ -17,3 +17,4 @@ plex_users = "" #COMMA SEPARATED LIST, NO SPACES! user1,user2 NOT user1, user2 worker_count = 16 seconds_interval = 60 #Deprecated, should be replaced with crontab generator manual_playlists = "" #No spaces, comma separated. Might work with a mix of IDs and URLs but best to pick one format +include_playlist_author="false" # Add the author of the playlist to the title (e.g. My Favourites [John H.]) diff --git a/spotiplex/config.py b/spotiplex/config.py index bbf10fb..9ab7f19 100644 --- a/spotiplex/config.py +++ b/spotiplex/config.py @@ -30,6 +30,7 @@ class Config: MANUAL_PLAYLISTS: str = os.environ.get("MANUAL_PLAYLISTS", "None") LIDARR_SYNC = os.environ.get("LIDARR_SYNC", "false") FIRST_RUN = os.environ.get("FIRST_RUN", "False") + INCLUDE_PLAYLIST_AUTHOR = os.environ.get("INCLUDE_PLAYLIST_AUTHOR", "false") else: spotify_config = read_config("spotify") plex_config = read_config("plex") @@ -52,3 +53,4 @@ class Config: MANUAL_PLAYLISTS: str = spotiplex_config.get("manual_playlists", "None") LIDARR_SYNC = spotiplex_config.get("lidarr_sync", "false") FIRST_RUN = spotiplex_config.get("first_run", "False") + INCLUDE_PLAYLIST_AUTHOR = spotiplex_config.get("include_playlist_author", "false") diff --git a/spotiplex/modules/spotify/main.py b/spotiplex/modules/spotify/main.py index 8fe3000..1e84c4b 100644 --- a/spotiplex/modules/spotify/main.py +++ b/spotiplex/modules/spotify/main.py @@ -43,6 +43,19 @@ def get_playlist_tracks( logger.debug(f"Error fetching tracks from Spotify: {e}") return tracks + def get_playlist_author(self: "SpotifyClass", playlist_id: str) -> str | None: + """Fetch the name of a Spotify playlist.""" + try: + return self.sp.playlist(playlist_id, fields=["owner"])["owner"]["display_name"] + except Exception as e: + logger.debug( + f""" + Error retrieving playlist owner's name from Spotify for playlist {playlist_id} + """, + ) + logger.debug(f"Error was {e}") + return None + def get_playlist_name(self: "SpotifyClass", playlist_id: str) -> str | None: """Fetch the name of a Spotify playlist.""" try: diff --git a/spotiplex/modules/spotiplex/main.py b/spotiplex/modules/spotiplex/main.py index 10e23bd..f8d18b3 100644 --- a/spotiplex/modules/spotiplex/main.py +++ b/spotiplex/modules/spotiplex/main.py @@ -26,6 +26,7 @@ def __init__( self.default_user: str = self.plex_service.plex.myPlexAccount().username self.worker_count: int = Config.WORKER_COUNT self.replace_existing = Config.PLEX_REPLACE + self.include_playlist_author = Config.INCLUDE_PLAYLIST_AUTHOR if not playlist_id: self.lidarr_service = LidarrClass() self.lidarr = lidarr @@ -84,6 +85,18 @@ def process_playlist(self: "Spotiplex", playlist: str) -> None: playlist_name: str | None = self.spotify_service.get_playlist_name( playlist_id, ) + if (self.include_playlist_author): + playlist_author: str | None = self.spotify_service.get_playlist_author( + playlist_id, + ) + + parts = playlist_author.split() + first_name = parts[0] + last_name = parts[-1] + last_initial = last_name[0] # Get the first letter of the last name + short_author = f"{first_name} {last_initial}." + + playlist_name = f"{playlist_name} [{short_author}]" if playlist_name: if "Discover Weekly" in playlist_name or "Daily Mix" in playlist_name: