Added exclusion in get rootfolder functions for the ones that aren't used by any series/movies. #1413

pull/1420/head v0.9.6-beta.14
morpheus65535 4 years ago
parent 7b9c19d7c0
commit b2b9795810

@ -6,7 +6,7 @@ import logging
from config import settings, url_sonarr, url_radarr from config import settings, url_sonarr, url_radarr
from helper import path_mappings from helper import path_mappings
from database import TableShowsRootfolder, TableMoviesRootfolder from database import TableShowsRootfolder, TableMoviesRootfolder, TableShows, TableMovies
headers = {"User-Agent": os.environ["SZ_USER_AGENT"]} headers = {"User-Agent": os.environ["SZ_USER_AGENT"]}
@ -30,8 +30,10 @@ def get_sonarr_rootfolder():
logging.exception("BAZARR Error trying to get rootfolder from Sonarr.") logging.exception("BAZARR Error trying to get rootfolder from Sonarr.")
return [] return []
else: else:
sonarr_movies_paths = list(TableShows.select(TableShows.path).dicts())
for folder in rootfolder.json(): for folder in rootfolder.json():
sonarr_rootfolder.append({'id': folder['id'], 'path': folder['path']}) if any(item['path'].startswith(folder['path']) for item in sonarr_movies_paths):
sonarr_rootfolder.append({'id': folder['id'], 'path': folder['path']})
db_rootfolder = TableShowsRootfolder.select(TableShowsRootfolder.id, TableShowsRootfolder.path).dicts() db_rootfolder = TableShowsRootfolder.select(TableShowsRootfolder.id, TableShowsRootfolder.path).dicts()
rootfolder_to_remove = [x for x in db_rootfolder if not rootfolder_to_remove = [x for x in db_rootfolder if not
next((item for item in sonarr_rootfolder if item['id'] == x['id']), False)] next((item for item in sonarr_rootfolder if item['id'] == x['id']), False)]
@ -93,8 +95,10 @@ def get_radarr_rootfolder():
logging.exception("BAZARR Error trying to get rootfolder from Radarr.") logging.exception("BAZARR Error trying to get rootfolder from Radarr.")
return [] return []
else: else:
radarr_movies_paths = list(TableMovies.select(TableMovies.path).dicts())
for folder in rootfolder.json(): for folder in rootfolder.json():
radarr_rootfolder.append({'id': folder['id'], 'path': folder['path']}) if any(item['path'].startswith(folder['path']) for item in radarr_movies_paths):
radarr_rootfolder.append({'id': folder['id'], 'path': folder['path']})
db_rootfolder = TableMoviesRootfolder.select(TableMoviesRootfolder.id, TableMoviesRootfolder.path).dicts() db_rootfolder = TableMoviesRootfolder.select(TableMoviesRootfolder.id, TableMoviesRootfolder.path).dicts()
rootfolder_to_remove = [x for x in db_rootfolder if not rootfolder_to_remove = [x for x in db_rootfolder if not
next((item for item in radarr_rootfolder if item['id'] == x['id']), False)] next((item for item in radarr_rootfolder if item['id'] == x['id']), False)]

Loading…
Cancel
Save