Skip to content

Commit

Permalink
Update episode data gathering from Plex
Browse files Browse the repository at this point in the history
Update PlexInterface to use Plex as an episode data source. Part of #311
  • Loading branch information
CollinHeist committed Mar 22, 2023
1 parent 5bb35dc commit a29ab41
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Empty file modified app/dependencies.py
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions app/models/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def __init__(self) -> None:
self.supported_language_codes = []

self.default_card_type = 'Standard'
self.default_watched_style = 'Unique'
self.default_unwatched_style = 'Unique'
self.default_watched_style = 'unique'
self.default_unwatched_style = 'unique'

self.use_emby = False
self.emby_url = 'http://192.168.0.11:8096/emby' #''
Expand Down
25 changes: 14 additions & 11 deletions modules/PlexInterface2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from re import IGNORECASE, compile as re_compile

from fastapi import HTTPException
from plexapi.exceptions import PlexApiException
from plexapi.server import PlexServer, NotFound, Unauthorized
from requests.exceptions import ReadTimeout, ConnectionError
Expand All @@ -10,9 +11,8 @@
from tqdm import tqdm

from modules.Debug import log, TQDM_KWARGS
import modules.global_objects as global_objects
from modules.EpisodeDataSource import EpisodeDataSource
from modules.EpisodeInfo import EpisodeInfo
from modules.EpisodeInfo2 import EpisodeInfo
from modules.ImageMaker import ImageMaker
from modules.MediaServer import MediaServer
from modules.PersistentDatabase import PersistentDatabase
Expand Down Expand Up @@ -42,8 +42,7 @@ class PlexInterface(EpisodeDataSource, MediaServer, SyncInterface):
def __init__(self, url: str, x_plex_token: str='NA',
verify_ssl: bool=True,
integrate_with_pmm_overlays: bool=False,
filesize_limit: int=10485760, *,
preferences=None) -> None:
filesize_limit: int=10485760) -> None:
"""
Constructs a new instance of a Plex Interface.
Expand All @@ -69,10 +68,16 @@ def __init__(self, url: str, x_plex_token: str='NA',
self.__server = PlexServer(url, x_plex_token, self.__session)
except Unauthorized:
log.critical(f'Invalid Plex Token "{x_plex_token}"')
# exit(1)
raise HTTPException(
status_code=401,
detail=f'Invalid Plex Token',
)
except Exception as e:
log.critical(f'Cannot connect to Plex - returned error: "{e}"')
# exit(1)
raise HTTPException(
status_code=400,
detail=f'Cannot connect to Plex - {e}',
)

# Store integration
self.integrate_with_pmm_overlays = integrate_with_pmm_overlays
Expand Down Expand Up @@ -306,7 +311,7 @@ def get_all_series(self,

@catch_and_log('Error getting all episodes', default=[])
def get_all_episodes(self, library_name: str,
series_info: SeriesInfo) -> list[EpisodeInfo]:
series_info: SeriesInfo) -> list[EpisodeInfo]:
"""
Gets all episode info for the given series. Only episodes that have
already aired are returned.
Expand Down Expand Up @@ -357,15 +362,13 @@ def get_all_episodes(self, library_name: str,
elif 'tmdb://' in guid.id:
ids['tmdb_id'] = guid.id[len('tmdb://'):]

# Create either a new EpisodeInfo or get from the MediaInfoSet
episode_info = self.info_set.get_episode_info(
series_info,
# Create a new EpisodeInfo
episode_info = EpisodeInfo(
plex_episode.title,
plex_episode.parentIndex,
plex_episode.index,
**ids,
airdate=airdate,
title_match=True,
queried_plex=True,
)

Expand Down
4 changes: 2 additions & 2 deletions modules/SyncInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class SyncInterface(ABC):
can be synced (e.g. series can be grabbed) from.
"""

def get_library_paths(self, filter_libraries: list[str]=[]
) -> dict[str, list[str]]:
def get_library_paths(self,
filter_libraries: list[str]=[]) -> dict[str, list[str]]:
"""
Get all libraries and their associated base directories.
Expand Down

0 comments on commit a29ab41

Please sign in to comment.