Skip to content

Commit

Permalink
Minor symlinking and state tweaks (#27)
Browse files Browse the repository at this point in the history
* Minor symlinking tweaks

* deps: remove package-lock.json from .gitignore

---------

Co-authored-by: Gaisberg <none>
Co-authored-by: Ayush Sehrawat <[email protected]>
  • Loading branch information
Gaisberg and AyushSehrawat authored Dec 15, 2023
1 parent 15d674c commit e6b0a46
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 32 deletions.
4 changes: 1 addition & 3 deletions backend/program/content/overseerr.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ def _validate_settings(self):
return response.ok
except ConnectTimeout:
return False
# response = json.loads(response.content)
# return response['response']

def update_items(self, media_items: MediaItemContainer):
"""Fetch media from overseerr and add them to media_items attribute
if they are not already there"""
logger.debug("Getting items...")
items = self._get_items_from_overseerr(1000)
items = self._get_items_from_overseerr(10000)
new_items = [item for item in items if item not in media_items]
container = self.updater.create_items(new_items)
added_items = media_items.extend(container)
Expand Down
1 change: 1 addition & 0 deletions backend/program/libraries/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def update_sections(self, media_items: List[MediaItem]):
or
(item.type == "show" and
any(season for season in item.seasons if season.state is MediaItemState.SYMLINK))
or any(episode for season in item.seasons for episode in season.episodes if episode.state is MediaItemState.SYMLINK)
):
if not section.refreshing:
section.update()
Expand Down
14 changes: 3 additions & 11 deletions backend/program/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def state(self):
return MediaItemState.LIBRARY
if self.symlinked:
return MediaItemState.SYMLINK
if self.is_cached():
if self.is_cached() or self.file:
return MediaItemState.DOWNLOAD
if len(self.streams) > 0:
return MediaItemState.SCRAPE
Expand Down Expand Up @@ -135,12 +135,6 @@ def state(self):
return MediaItemState.LIBRARY
if any(season.state in [MediaItemState.LIBRARY, MediaItemState.LIBRARY_PARTIAL] for season in self.seasons):
return MediaItemState.LIBRARY_PARTIAL
if any(season.state == MediaItemState.SYMLINK for season in self.seasons):
return MediaItemState.SYMLINK
if any(season.state == MediaItemState.DOWNLOAD for season in self.seasons):
return MediaItemState.DOWNLOAD
if any(season.state == MediaItemState.SCRAPE for season in self.seasons):
return MediaItemState.SCRAPE
if any(season.state == MediaItemState.CONTENT for season in self.seasons):
return MediaItemState.CONTENT
return MediaItemState.UNKNOWN
Expand Down Expand Up @@ -172,11 +166,9 @@ def state(self):
return MediaItemState.LIBRARY
if any(episode.state == MediaItemState.LIBRARY for episode in self.episodes):
return MediaItemState.LIBRARY_PARTIAL
if any(episode.state == MediaItemState.SYMLINK for episode in self.episodes):
return MediaItemState.SYMLINK
if self.is_cached() or any(episode.state == MediaItemState.DOWNLOAD for episode in self.episodes):
if self.is_cached():
return MediaItemState.DOWNLOAD
if self.is_scraped() or any(episode.state == MediaItemState.SCRAPE for episode in self.episodes):
if self.is_scraped():
return MediaItemState.SCRAPE
if any(episode.state == MediaItemState.CONTENT for episode in self.episodes):
return MediaItemState.CONTENT
Expand Down
26 changes: 8 additions & 18 deletions backend/program/symlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from utils.settings import settings_manager as settings
from utils.logger import logger
from program.media import MediaItemState
from utils.thread import ThreadRunner


class Symlinker:
Expand All @@ -15,6 +16,7 @@ def __init__(
):
# Symlinking is required
while True:
self.cache = {}
self.settings = settings.get("symlink")
self.mount_path = os.path.abspath(self.settings["mount"])
self.host_path = os.path.abspath(self.settings["host_mount"])
Expand All @@ -26,6 +28,8 @@ def __init__(
os.mkdir(os.path.join(self.symlink_path, "movies"))
if not os.path.exists(os.path.join(self.symlink_path, "shows")):
os.mkdir(os.path.join(self.symlink_path, "shows"))
self.cache_thread = ThreadRunner(self.update_cache, 10)
self.cache_thread.start()
break
logger.error("Rclone mount not found, retrying in 2...")
time.sleep(2)
Expand Down Expand Up @@ -119,23 +123,9 @@ def run(self, media_items):
logger.debug("Done!")

def _find_file(self, filename):
return self.cache.get(filename, None)

def update_cache(self):
for root, _, files in os.walk(os.path.join(self.host_path, "torrents")):
for file in files:
if file == filename:
return os.path.join(root, file)

# class FileWatcher():
# def __init__(self, path):
# self.path = os.path.join(os.path.abspath(path), "torrents")
# self.cache = {}

# def run(self):
# for folder_name, _, filenames in os.walk(self.path):
# folder = folder_name.split("/")[-1]
# for filename in filenames:
# if folder not in self.cache:
# self.cache[folder] = []
# if filename not in self.cache[folder]:
# self.cache[folder].append(filename)
# # Scan every after 5 seconds each cycle...
# time.sleep(5)
self.cache[file] = os.path.join(root, file)

0 comments on commit e6b0a46

Please sign in to comment.