Skip to content

Commit

Permalink
Improve content fetching logic to limit series episodes in recent items.
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppe99barchetta committed Oct 25, 2024
1 parent 42e6c2f commit 9f99755
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion api_service/services/plex/plex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ async def get_recent_items(self):
params = {
"sort": "viewedAt:desc",
}

if self.library_ids:
params["librarySectionIDs"] = ','.join(self.library_ids)

try:
async with aiohttp.ClientSession() as session:
Expand All @@ -76,12 +79,14 @@ async def get_recent_items(self):
filtered_items = await self.filter_recent_items(metadata)
self.logger.info(f"Returning {len(filtered_items)} filtered recent items.")
return filtered_items

self.logger.error("Failed to retrieve recent items: %d", response.status)
except aiohttp.ClientError as e:
self.logger.error("An error occurred while retrieving recent items: %s", str(e))

return []


async def filter_recent_items(self, metadata):
"""
Filters recent items to avoid duplicates and respects the max content fetch limit.
Expand Down Expand Up @@ -183,4 +188,4 @@ async def get_servers(self):
return None
except aiohttp.ClientError as e:
print(f"Errore durante il recupero dei server Plex: {str(e)}")
return None
return None
10 changes: 5 additions & 5 deletions client/src/api/plexApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ export default {
},
methods: {
toggleLibrarySelection(library) {
const index = this.selectedLibraries.findIndex(l => l.uuid === library.uuid);
const index = this.selectedLibraries.findIndex(l => l.key === library.key);
index > -1 ? this.selectedLibraries.splice(index, 1) : this.selectedLibraries.push(library);
this.updateSelectedLibraries();
},
isSelected(libraryId) {
return this.selectedLibraries.some(library => library.uuid === libraryId);
return this.selectedLibraries.some(library => library.key === libraryId);
},
updateSelectedLibraries() {
const libraryIds = this.selectedLibraries.map(library => library.uuid);
const libraryIds = this.selectedLibraries.map(library => library.key);
this.$emit('update-config', 'PLEX_LIBRARIES', libraryIds);
},
loadSelectedLibraries() {
if (this.config.PLEX_LIBRARIES) {
this.selectedLibraries = this.libraries.filter(library =>
this.config.PLEX_LIBRARIES.includes(library.uuid)
this.config.PLEX_LIBRARIES.includes(library.key)
);
}
},
Expand Down Expand Up @@ -147,4 +147,4 @@ export default {
this.fetchPlexServers(authToken);
}
},
};
};

0 comments on commit 9f99755

Please sign in to comment.