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
| Name | Type | Description |
|---|---|---|
item | Any | The media item of the files, with its "poster_url". |
moved_files | Iterable[str] | New paths of its files. |
dest_path | str | Destination folder of the rename. |
Returns
Dict[Path, str]The URL to save at each path; empty without an image or for a game.
download_artwork
def download_artwork(targets: Dict[Path, str]) -> Dict[str, List[Any]]:Download images, keeping those already in place.
Parameters
| Name | Type | Description |
|---|---|---|
targets | Dict[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) andDict[str, List[Any]]"errors" ({"file", "error"}).
image_url
def image_url(path: Optional[str]) -> Optional[str]:Absolute URL of an image of a search result.
Parameters
| Name | Type | Description |
|---|---|---|
path | Optional[str] | The "poster_path" of a result: a URL, or a TMDB path. |
Returns
Optional[str]The URL, or None without an image.
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
| Name | Type | Description |
|---|---|---|
mappings | Iterable[Any] | (source file, media item) pairs of the rename. |
moved | Iterable[Dict[str, str]] | The "moved" entries of its report ({"from", "to"}). |
dest_path | str | Destination folder of the rename. |
Returns
Dict[str, List[Any]]The report of download_artwork().
Attributes
| Name | Value |
|---|---|
DOWNLOAD_TIMEOUT | 15 |
TMDB_IMAGE_BASE | 'https://image.tmdb.org/t/p/original' |
logger | logging.getLogger(__name__) |