user selected watchlist settings now connected to backend.
This commit is contained in:
parent
1749bb62a5
commit
2c12759dbb
2 changed files with 48 additions and 12 deletions
|
|
@ -263,8 +263,8 @@ class WatchlistScanner:
|
||||||
except Exception as img_error:
|
except Exception as img_error:
|
||||||
logger.warning(f"Could not update artist image for {watchlist_artist.artist_name}: {img_error}")
|
logger.warning(f"Could not update artist image for {watchlist_artist.artist_name}: {img_error}")
|
||||||
|
|
||||||
# Get artist discography from Spotify
|
# Get artist discography from Spotify (filtered by artist's album type preferences)
|
||||||
albums = self.get_artist_discography(watchlist_artist.spotify_artist_id, watchlist_artist.last_scan_timestamp)
|
albums = self.get_artist_discography(watchlist_artist, watchlist_artist.last_scan_timestamp)
|
||||||
|
|
||||||
if albums is None:
|
if albums is None:
|
||||||
return ScanResult(
|
return ScanResult(
|
||||||
|
|
@ -355,22 +355,38 @@ class WatchlistScanner:
|
||||||
error_message=str(e)
|
error_message=str(e)
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_artist_discography(self, spotify_artist_id: str, last_scan_timestamp: Optional[datetime] = None) -> Optional[List]:
|
def get_artist_discography(self, watchlist_artist: WatchlistArtist, last_scan_timestamp: Optional[datetime] = None) -> Optional[List]:
|
||||||
"""
|
"""
|
||||||
Get artist's discography from Spotify, optionally filtered by release date.
|
Get artist's discography from Spotify, optionally filtered by release date and album type.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
spotify_artist_id: Spotify artist ID
|
watchlist_artist: WatchlistArtist object with configuration settings
|
||||||
last_scan_timestamp: Only return releases after this date (for incremental scans)
|
last_scan_timestamp: Only return releases after this date (for incremental scans)
|
||||||
If None, uses lookback period setting from database
|
If None, uses lookback period setting from database
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Get all artist albums (albums + singles) - this is rate limited in spotify_client
|
# Build album_type filter from artist configuration
|
||||||
logger.debug(f"Fetching discography for artist {spotify_artist_id}")
|
album_types = []
|
||||||
albums = self.spotify_client.get_artist_albums(spotify_artist_id, album_type='album,single', limit=50)
|
if watchlist_artist.include_albums:
|
||||||
|
album_types.append('album')
|
||||||
|
if watchlist_artist.include_eps:
|
||||||
|
album_types.append('ep')
|
||||||
|
if watchlist_artist.include_singles:
|
||||||
|
album_types.append('single')
|
||||||
|
|
||||||
|
# Fallback to albums only if nothing is selected (shouldn't happen due to validation)
|
||||||
|
if not album_types:
|
||||||
|
logger.warning(f"Artist {watchlist_artist.artist_name} has no album types selected, defaulting to albums only")
|
||||||
|
album_types = ['album']
|
||||||
|
|
||||||
|
album_type_param = ','.join(album_types)
|
||||||
|
logger.info(f"Fetching discography for {watchlist_artist.artist_name} (types: {album_type_param})")
|
||||||
|
|
||||||
|
# Get artist albums with configured types - this is rate limited in spotify_client
|
||||||
|
albums = self.spotify_client.get_artist_albums(watchlist_artist.spotify_artist_id, album_type=album_type_param, limit=50)
|
||||||
|
|
||||||
if not albums:
|
if not albums:
|
||||||
logger.warning(f"No albums found for artist {spotify_artist_id}")
|
logger.warning(f"No albums found for artist {watchlist_artist.artist_name}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# Add small delay after fetching artist discography to be extra safe
|
# Add small delay after fetching artist discography to be extra safe
|
||||||
|
|
@ -402,7 +418,7 @@ class WatchlistScanner:
|
||||||
return albums
|
return albums
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error getting discography for artist {spotify_artist_id}: {e}")
|
logger.error(f"Error getting discography for artist {watchlist_artist.artist_name}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _get_lookback_period_setting(self) -> str:
|
def _get_lookback_period_setting(self) -> str:
|
||||||
|
|
|
||||||
|
|
@ -2590,7 +2590,8 @@ class MusicDatabase:
|
||||||
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT id, spotify_artist_id, artist_name, date_added,
|
SELECT id, spotify_artist_id, artist_name, date_added,
|
||||||
last_scan_timestamp, created_at, updated_at, image_url
|
last_scan_timestamp, created_at, updated_at, image_url,
|
||||||
|
include_albums, include_eps, include_singles
|
||||||
FROM watchlist_artists
|
FROM watchlist_artists
|
||||||
ORDER BY date_added DESC
|
ORDER BY date_added DESC
|
||||||
""")
|
""")
|
||||||
|
|
@ -2605,6 +2606,22 @@ class MusicDatabase:
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
image_url = None
|
image_url = None
|
||||||
|
|
||||||
|
# Try to get album type filter settings, fallback to True (include all) if columns don't exist yet (migration)
|
||||||
|
try:
|
||||||
|
include_albums = bool(row['include_albums'])
|
||||||
|
except (KeyError, IndexError):
|
||||||
|
include_albums = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
include_eps = bool(row['include_eps'])
|
||||||
|
except (KeyError, IndexError):
|
||||||
|
include_eps = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
include_singles = bool(row['include_singles'])
|
||||||
|
except (KeyError, IndexError):
|
||||||
|
include_singles = True
|
||||||
|
|
||||||
watchlist_artists.append(WatchlistArtist(
|
watchlist_artists.append(WatchlistArtist(
|
||||||
id=row['id'],
|
id=row['id'],
|
||||||
spotify_artist_id=row['spotify_artist_id'],
|
spotify_artist_id=row['spotify_artist_id'],
|
||||||
|
|
@ -2613,7 +2630,10 @@ class MusicDatabase:
|
||||||
last_scan_timestamp=datetime.fromisoformat(row['last_scan_timestamp']) if row['last_scan_timestamp'] else None,
|
last_scan_timestamp=datetime.fromisoformat(row['last_scan_timestamp']) if row['last_scan_timestamp'] else None,
|
||||||
created_at=datetime.fromisoformat(row['created_at']) if row['created_at'] else None,
|
created_at=datetime.fromisoformat(row['created_at']) if row['created_at'] else None,
|
||||||
updated_at=datetime.fromisoformat(row['updated_at']) if row['updated_at'] else None,
|
updated_at=datetime.fromisoformat(row['updated_at']) if row['updated_at'] else None,
|
||||||
image_url=image_url
|
image_url=image_url,
|
||||||
|
include_albums=include_albums,
|
||||||
|
include_eps=include_eps,
|
||||||
|
include_singles=include_singles
|
||||||
))
|
))
|
||||||
|
|
||||||
return watchlist_artists
|
return watchlist_artists
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue