added 'snapshot_id' to decide whether process a playlist or not
This commit is contained in:
@@ -32,6 +32,7 @@ class Playlist(db.Model):
|
||||
jellyfin_id = db.Column(db.String(120), nullable=True)
|
||||
last_updated = db.Column(db.DateTime )
|
||||
last_changed = db.Column(db.DateTime )
|
||||
snapshot_id = db.Column(db.String(120), nullable=True)
|
||||
# Many-to-Many relationship with JellyfinUser
|
||||
users = db.relationship('JellyfinUser', secondary=user_playlists, back_populates='playlists')
|
||||
|
||||
|
||||
10
app/tasks.py
10
app/tasks.py
@@ -203,14 +203,20 @@ def check_for_playlist_updates(self):
|
||||
processed_playlists = 0
|
||||
|
||||
for playlist in playlists:
|
||||
app.logger.info(f'Checking updates for playlist: {playlist.name}')
|
||||
playlist.last_updated = datetime.now( timezone.utc)
|
||||
sp_playlist = sp.playlist(playlist.spotify_playlist_id)
|
||||
|
||||
app.logger.info(f'Checking updates for playlist: {playlist.name}, s_snapshot = {sp_playlist['snapshot_id']}')
|
||||
db.session.commit()
|
||||
if sp_playlist['snapshot_id'] == playlist.snapshot_id:
|
||||
app.logger.info(f'playlist: {playlist.name} , no changes detected, snapshot_id {sp_playlist['snapshot_id']}')
|
||||
continue
|
||||
try:
|
||||
#region Check for updates
|
||||
# Fetch all playlist data from Spotify
|
||||
spotify_tracks = {}
|
||||
offset = 0
|
||||
playlist.snapshot_id = sp_playlist['snapshot_id']
|
||||
while True:
|
||||
playlist_data = sp.playlist_items(playlist.spotify_playlist_id, offset=offset, limit=100)
|
||||
items = playlist_data['items']
|
||||
@@ -267,7 +273,7 @@ def check_for_playlist_updates(self):
|
||||
#endregion
|
||||
|
||||
#region Update Playlist Items and Metadata
|
||||
functions.update_playlist_metadata(playlist, sp.playlist(playlist.spotify_playlist_id))
|
||||
functions.update_playlist_metadata(playlist, sp_playlist)
|
||||
ordered_tracks = db.session.execute(
|
||||
db.select(Track, playlist_tracks.c.track_order)
|
||||
.join(playlist_tracks, playlist_tracks.c.track_id == Track.id)
|
||||
|
||||
Reference in New Issue
Block a user