Skip to content

Commit

Permalink
fix: audio and subtitles codec were not matching correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ratoaq2 committed Feb 8, 2023
1 parent 63d2e72 commit cd58670
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
43 changes: 30 additions & 13 deletions plexy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ def __repr__(self):
class Criteria:

def __init__(self,
libraries: typing.List[str],
titles: typing.List[Title],
newer_than: typing.Optional[str],
older_than: typing.Optional[str],
skip_watching: bool):
self.libraries = libraries
self.titles = titles
libraries: typing.Optional[typing.Iterable[str]] = None,
titles: typing.Optional[typing.Iterable[Title]] = None,
newer_than: typing.Optional[str] = None,
older_than: typing.Optional[str] = None,
skip_watching=False):
self.libraries = list(libraries or [])
self.titles = list(titles or [])
self.newer_than = newer_than
self.older_than = older_than
self.skip_watching = skip_watching
Expand Down Expand Up @@ -264,6 +264,14 @@ def save_preferences(self, preferences: Preferences):

return changes

def __eq__(self, other):
if isinstance(other, Video):
return self.video == other.video
return NotImplemented

def __hash__(self):
return hash(tuple(sorted(self.__dict__.items())))

def __str__(self):
return f'{self.title}'

Expand Down Expand Up @@ -319,11 +327,13 @@ def default(self):

@property
def codec(self):
return self.stream.codec
if self.stream.codec:
return AudioCodec(self.stream.codec)

@property
def format(self):
return self.subtitle_stream.format if self.subtitle_stream else None
if self.subtitle_stream and self.subtitle_stream.format:
return SubtitleCodec(self.subtitle_stream.format)

@property
def audio_stream(self):
Expand Down Expand Up @@ -514,16 +524,23 @@ def __repr__(self):
class Plex:

def __init__(self, settings: Settings):
self.plex = plexapi.server.PlexServer(baseurl=settings.url, token=settings.token)
logger.debug('Connected to %s', settings.url)
self.settings = settings
self._plex: typing.Optional[plexapi.server.PlexServer] = None

@property
def server(self):
if self._plex is None:
logger.debug('Connected to %s', self.settings.url)
self._plex = plexapi.server.PlexServer(baseurl=self.settings.url, token=self.settings.token)
return self._plex

def __find_sections(self, criteria: Criteria):
if not criteria.libraries:
return self.plex.library.sections()
return self.server.library.sections()

sections: typing.List[plexapi.library.LibrarySection] = []
for library in criteria.libraries:
sections.append(self.plex.library.section(library))
sections.append(self.server.library.section(library))

return sections

Expand Down
4 changes: 2 additions & 2 deletions plexy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def convert(self, value: typing.Any, param: typing.Optional[click.Parameter], ct

class AgeParamType(click.ParamType):
name = 'age'
language_re = re.compile(r'^(?:(?P<weeks>\d+?)w)?(?:(?P<days>\d+?)d)?(?:(?P<hours>\d+?)h)?$')
age_re = re.compile(r'^(?:(?P<weeks>\d+?)w)?(?:(?P<days>\d+?)d)?(?:(?P<hours>\d+?)h)?$')

def convert(self, value: typing.Any, param: typing.Optional[click.Parameter], ctx: typing.Optional[click.Context]):
match = self.language_re.match(value)
match = self.age_re.match(value)
if not match:
self.fail(f"{click.style(f'{value}', bold=True)} is not a valid age")

Expand Down

0 comments on commit cd58670

Please sign in to comment.