Skip to content

Commit

Permalink
[36] Download imported Cards as Source Images and Cards
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinHeist committed Sep 5, 2024
1 parent 7bcc09b commit 2edff1d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
31 changes: 22 additions & 9 deletions app/routers/imports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from logging import Logger
from pathlib import Path
from shutil import copyfile
from shutil import copyfile, move as move_file
from typing import Literal, Optional

from fastapi import (
Expand All @@ -11,7 +11,7 @@
HTTPException,
Query,
Request,
UploadFile
UploadFile,
)
from pydantic.error_wrappers import ValidationError
from sqlalchemy.orm import Session
Expand All @@ -35,12 +35,12 @@
parse_sonarr,
parse_syncs,
parse_templates,
parse_tmdb
parse_tmdb,
)
from app.internal.series import (
download_series_poster,
load_series_title_cards,
set_series_database_ids
set_series_database_ids,
)
from app.internal.sources import download_series_logo
from app import models
Expand All @@ -50,7 +50,7 @@
ImportCardDirectory,
ImportYaml,
KometaYaml,
MultiCardImport
MultiCardImport,
)
from app.schemas.preferences import Preferences
from app.schemas.series import Series, Template
Expand Down Expand Up @@ -491,9 +491,22 @@ def _download_image(url: str, /) -> Optional[Path]:
log.debug(f'Skipping {episode.index_str} - has Cards')
continue

# Episode exists, download and add to card list
if (card := _download_image(episode_yaml.url_poster)):
cards.append((episode, card))
# Episode exists, download image
if not (card := _download_image(episode_yaml.url_poster)):
continue

# If textless import, then download as Source Image
if textless:
if (source := episode.get_source_file('unique')).exists():
log.debug(f'{episode} Source Image exists - replacing')
try:
move_file(card, source)
except OSError:
log.exception('Error occurred while moving Card file')
continue

# Add to list to import
cards.append((episode, card))

# Import content into all specified libraries
log.debug(f'Identified {len(cards)} Cards to import')
Expand Down Expand Up @@ -575,7 +588,7 @@ def import_card_directory_for_series(
def import_cards_for_multiple_series(
request: Request,
card_import: MultiCardImport = Body(...),
db: Session = Depends(get_database)
db: Session = Depends(get_database),
) -> None:
"""
Import any existing Title Cards for all the given Series. This finds
Expand Down
2 changes: 1 addition & 1 deletion modules/ref/version_webui
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0-alpha.12.0-webui35
v2.0-alpha.12.0-webui36

0 comments on commit 2edff1d

Please sign in to comment.