Extract PlexAudioCodec class to own file
MODIFY
plextraktsync/factory.py
plextraktsync/factory.py
@@ -132,7 +132,7 @@ def walk_config(self):
@cached_property
def plex_audio_codec(self):
- from plextraktsync.plex_api import PlexAudioCodec
+ from plextraktsync.plex.PlexAudioCodec import PlexAudioCodec
return PlexAudioCodec()

ADD
plextraktsync/plex/PlexAudioCodec.py
+from __future__ import annotations
+
+import re
+
+from plextraktsync.decorators.cached_property import cached_property
+
+
+class PlexAudioCodec:
+ def match(self, codec):
+ for key, regex in self.audio_codecs.items():
+ if key == codec:
+ return key
+
+ if regex and regex.match(codec):
+ return key
+
+ return None
+
+ @cached_property
+ def audio_codecs(self):
+ codecs = {
+ "lpcm": "pcm",
+ "mp3": None,
+ "aac": None,
+ "ogg": "vorbis",
+ "wma": None,
+ "dts": "(dca|dta)",
+ "dts_ma": "dtsma",
+ "dolby_prologic": "dolby.?pro",
+ "dolby_digital": "ac.?3",
+ "dolby_digital_plus": "eac.?3",
+ "dolby_truehd": "truehd",
+ }
+
+ # compile patterns
+ for k, v in codecs.items():
+ if v is None:
+ continue
+
+ try:
+ codecs[k] = re.compile(v, re.IGNORECASE)
+ except Exception:
+ raise RuntimeError(
+ "Unable to compile regex pattern: %r", v, exc_info=True
+ )
+ return codecs

MODIFY
plextraktsync/plex_api.py
plextraktsync/plex_api.py
from __future__ import annotations
import datetime
-import re
from typing import Dict, List, Optional, Union
import plexapi
@@ -92,47 +91,6 @@ def __str__(self):
return f"<PlexGuid:{self.guid}>"
-class PlexAudioCodec:
- def match(self, codec):
- for key, regex in self.audio_codecs.items():
- if key == codec:
- return key
-
- if regex and regex.match(codec):
- return key
-
- return None
-
- @cached_property
- def audio_codecs(self):
- codecs = {
- "lpcm": "pcm",
- "mp3": None,
- "aac": None,
- "ogg": "vorbis",
- "wma": None,
- "dts": "(dca|dta)",
- "dts_ma": "dtsma",
- "dolby_prologic": "dolby.?pro",
- "dolby_digital": "ac.?3",
- "dolby_digital_plus": "eac.?3",
- "dolby_truehd": "truehd",
- }
-
- # compile patterns
- for k, v in codecs.items():
- if v is None:
- continue
-
- try:
- codecs[k] = re.compile(v, re.IGNORECASE)
- except Exception:
- raise RuntimeError(
- "Unable to compile regex pattern: %r", v, exc_info=True
- )
- return codecs
-
-
class PlexLibraryItem:
def __init__(self, item: Union[Movie, Show, Episode], plex: PlexApi = None):
self.item = item
@@ -735,5 +693,6 @@ def reset_show(self, show, reset_date):
self.mark_unwatched(ep)
reset_count += 1
else:
- logger.debug(f"{show.title} {ep.seasonEpisode} watched at {ep.lastViewedAt} after reset date {reset_date}")
+ logger.debug(
+ f"{show.title} {ep.seasonEpisode} watched at {ep.lastViewedAt} after reset date {reset_date}")
logger.debug(f"{show.title}: {reset_count} Plex episode(s) marked as unwatched.")

Extract PlexAudioCodec class to own file