Skip to content

Commit

Permalink
Get plex items from only wanted sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaisberg authored and AyushSehrawat committed Dec 19, 2023
1 parent 27515fb commit 4e508d0
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions backend/program/libraries/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _update_items(self):
processed_sections = set()

for section in sections:
if section.key in processed_sections:
if section.key in processed_sections and not self._is_wanted_section(section):
continue

try:
Expand All @@ -97,7 +97,7 @@ def _update_items(self):
def _update_sections(self):
"""Update plex library section"""
for section in self.plex.library.sections():
if not any(self.library_path in location for location in section.locations):
if not self._is_wanted_section(section):
continue
movie_items = [
item
Expand Down Expand Up @@ -193,31 +193,8 @@ def _update_item(self, item: MediaItem, library_item: MediaItem):
item.set("guid", library_item.guid)
item.set("key", library_item.key)

def _fix_match(self, library_item: MediaItem, item: MediaItem):
"""Internal method to use in match_items method.
It gets plex guid and checks if it matches with plex metadata
for given imdb_id. If it does, it will update the metadata of the plex item."""
section = next(
section
for section in self.plex.library.sections()
if section.type == item.type
)
dummy = section.search(maxresults=1)[0]

if dummy and not section.refreshing:
if item.imdb_id:
try:
match = dummy.matches(agent=section.agent, title=item.imdb_id)[0]
except ReadTimeout:
return False
except IndexError:
return False
if library_item.guid != match.guid:
item_to_update = self.plex.fetchItem(library_item.key)
item_to_update.fixMatch(match)
return True
return False

def _is_wanted_section(self, section):
return any(self.library_path in location for location in section.locations)

def _map_item_from_data(item, item_type):
"""Map Plex API data to MediaItemContainer."""
Expand Down

0 comments on commit 4e508d0

Please sign in to comment.