Fix Code Duplication 4: Create media utilities module
- Created src/server/utils/media.py with reusable media file functions - Functions: check_media_files(), get_media_file_paths(), has_all_images(), count_video_files(), has_video_files() - Defined standard filename constants: POSTER_FILENAME, LOGO_FILENAME, FANART_FILENAME, NFO_FILENAME - Defined VIDEO_EXTENSIONS set for media player compatibility - Refactored src/server/api/nfo.py (7 locations) to use utility functions - Refactored src/server/services/background_loader_service.py to use utility - Functions accept both str and Path for compatibility - Marked Code Duplications 1, 3, 4 as RESOLVED in instructions.md - Updated Further Considerations as RESOLVED (addressed in Issues 7, 9, 10)
This commit is contained in:
@@ -234,6 +234,7 @@ class BackgroundLoaderService:
|
||||
|
||||
# Check database for series info
|
||||
from src.server.database.service import AnimeSeriesService
|
||||
from src.server.utils.media import check_media_files
|
||||
|
||||
series_db = await AnimeSeriesService.get_by_key(db, key)
|
||||
if not series_db:
|
||||
@@ -244,19 +245,25 @@ class BackgroundLoaderService:
|
||||
# Check episodes
|
||||
missing["episodes"] = not series_db.episodes_loaded
|
||||
|
||||
# Check files using utility function
|
||||
folder_path = Path(anime_directory) / folder
|
||||
media_status = check_media_files(
|
||||
folder_path,
|
||||
check_poster=True,
|
||||
check_logo=True,
|
||||
check_fanart=True,
|
||||
check_nfo=True
|
||||
)
|
||||
|
||||
# Check NFO file
|
||||
nfo_path = Path(anime_directory) / folder / "tvshow.nfo"
|
||||
missing["nfo"] = not nfo_path.exists() or not series_db.has_nfo
|
||||
missing["nfo"] = not media_status.get("nfo", False) or not series_db.has_nfo
|
||||
|
||||
# Check logo
|
||||
logo_path = Path(anime_directory) / folder / "logo.png"
|
||||
missing["logo"] = not logo_path.exists() or not series_db.logo_loaded
|
||||
missing["logo"] = not media_status.get("logo", False) or not series_db.logo_loaded
|
||||
|
||||
# Check images (poster and fanart)
|
||||
poster_path = Path(anime_directory) / folder / "poster.jpg"
|
||||
fanart_path = Path(anime_directory) / folder / "fanart.jpg"
|
||||
missing["images"] = (
|
||||
not (poster_path.exists() and fanart_path.exists())
|
||||
not (media_status.get("poster", False) and media_status.get("fanart", False))
|
||||
or not series_db.images_loaded
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user