Skip to content

sok.file_operations.artwork

Posters and covers saved next to the organized files.

The names are the ones Plex, Jellyfin and Kodi read:

  • a movie: "-poster.jpg" next to the file, since a movie has no folder of its own;
  • a series: "poster.jpg" in the series folder;
  • an album or a track: "cover.jpg" in the album folder;
  • a book: "cover.jpg" in the book folder.

Games get none: RAWG gives a screenshot, not a cover. An image already in place is kept, and a failed download never stops a rename.

The module has no Qt dependency, so the desktop app and S.O.K Server share it.

Functions

artwork_targets

def artwork_targets(
item: Any,
moved_files: Iterable[str],
dest_path: str,
) -> Dict[Path, str]:

Where the image of an item goes, for the files just moved.

Parameters

NameTypeDescription
itemAnyThe media item of the files, with its "poster_url".
moved_filesIterable[str]New paths of its files.
dest_pathstrDestination folder of the rename.

Returns

  • Dict[Path, str]The URL to save at each path; empty without an image or for a game.
Source

download_artwork

def download_artwork(targets: Dict[Path, str]) -> Dict[str, List[Any]]:

Download images, keeping those already in place.

Parameters

NameTypeDescription
targetsDict[Path, str]The URL to save at each path (see artwork_targets).

Returns

  • Dict[str, List[Any]]Report with "saved" (paths), "kept" (paths already there) and
  • Dict[str, List[Any]]"errors" ({"file", "error"}).
Source

image_url

def image_url(path: Optional[str]) -> Optional[str]:

Absolute URL of an image of a search result.

Parameters

NameTypeDescription
pathOptional[str]The "poster_path" of a result: a URL, or a TMDB path.

Returns

  • Optional[str]The URL, or None without an image.
Source

save_artwork

def save_artwork(
mappings: Iterable[Any],
moved: Iterable[Dict[str, str]],
dest_path: str,
) -> Dict[str, List[Any]]:

Download the images of the items of a rename.

Parameters

NameTypeDescription
mappingsIterable[Any](source file, media item) pairs of the rename.
movedIterable[Dict[str, str]]The "moved" entries of its report ({"from", "to"}).
dest_pathstrDestination folder of the rename.

Returns

  • Dict[str, List[Any]]The report of download_artwork().
Source

Attributes

NameValue
DOWNLOAD_TIMEOUT15
TMDB_IMAGE_BASE'https://image.tmdb.org/t/p/original'
loggerlogging.getLogger(__name__)
Built with Kiln