sok.file_operations.file_metadata
The information of a movie or an episode, written inside its video.
What the music files have with their tags and covers, for the videos: a player, Windows Explorer or Finder show the real title, the year, the poster and the summary instead of the name of the release ("Dune.2021.1080p-GRP").
- a movie gets its title, year, director, genres, summary and poster;
- an episode gets its series, season, number and title, and the poster of its series.
An MKV gets them with mkvpropedit (MKVToolNix): the title of the file, the global tags (Matroska names: TITLE, DATE_RELEASED, DIRECTOR, GENRE, SUMMARY; PART_NUMBER for the season and the episode) and the poster as the "cover.jpg" attachment. Only the header changes, the file is not written again. An MP4 or M4V gets the iTunes tags with mutagen, poster included.
S.O.K replaces the information it writes: the title of a release is often wrong. The global tags of an MKV are all replaced, the tags of its tracks are kept. Afterwards the file is read again: an MKV must have its title and its poster, an MP4 its title and the same duration, else MetadataError.
Never with hard links (the file is the torrent's): S.O.K Server writes them only in copy or move mode, when the write_metadata setting is on.
MetadataError
class MetadataErrorBases: OSError
The information could not be written; the video is as it was.
SourceVideoInfodataclass
class VideoInfo( title: str, year: Optional[int] = None, date: Optional[str] = None, directors: List[str] = list(), genres: List[str] = list(), summary: str = '', series: Optional[str] = None, season: Optional[int] = None, episode: Optional[int] = None, episode_title: str = '', cover: Optional[str] = None,)What S.O.K writes into a video: a movie, or an episode of a series.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
title | str | ||
year | Optional[int] | None | |
date | Optional[str] | None | |
directors | List[str] | list() | |
genres | List[str] | list() | |
summary | str | '' | |
series | Optional[str] | None | |
season | Optional[int] | None | |
episode | Optional[int] | None | |
episode_title | str | '' | |
cover | Optional[str] | None |
Attributes
| Name | Type |
|---|---|
cover | Optional[str] |
date | Optional[str] |
directors | List[str] |
episode | Optional[int] |
episode_title | str |
genres | List[str] |
season | Optional[int] |
series | Optional[str] |
summary | str |
title | str |
year | Optional[int] |
is_episodeproperty
bool
display_title
def display_title() -> str:The title of the file: "Dune", or "Severance - S01E02 - Half Loop".
Sourcefields
def fields() -> List[str]:The information it holds, in the order the history shows them.
SourceFunctions
cover_url
def cover_url(path: Optional[str]) -> Optional[str]:The URL of the poster of a search result, at the size of a cover.
Parameters
| Name | Type | Description |
|---|---|---|
path | Optional[str] |
download_cover
def download_cover(poster_path: Optional[str], folder: str) -> Optional[str]:Download the poster of a search result into a folder.
Parameters
| Name | Type | Description |
|---|---|---|
poster_path | Optional[str] | |
folder | str |
Returns
Optional[str]The image file, None without a poster or when it fails: the videoOptional[str]then gets its information without its poster.
mkv_tags
def mkv_tags(info: VideoInfo) -> str:The global tags of an MKV, as the XML mkvpropedit reads.
Parameters
| Name | Type | Description |
|---|---|---|
info | VideoInfo |
writable
def writable(path: str) -> bool:Whether S.O.K can write the information of a video: an MKV with mkvpropedit, or an MP4.
Parameters
| Name | Type | Description |
|---|---|---|
path | str |
write_metadata
def write_metadata(path: str, info: VideoInfo) -> List[str]:Write the information of a movie or an episode into its video.
Parameters
| Name | Type | Description |
|---|---|---|
path | str | The video: an MKV or an MP4. |
info | VideoInfo | What to write. |
Returns
List[str]The fields written (VideoInfo.fields); empty for a format that hasList[str]none (AVI, TS).
Raises
MetadataErrorThe tool is missing, failed, or the video does not read as expected afterwards.
Attributes
| Name | Value |
|---|---|
COLLECTION | 70 |
COVER_NAME | 'cover' |
DOWNLOAD_TIMEOUT | 15 |
DURATION_MARGIN | 0.5 |
EPISODE | 50 |
MAX_COVER_BYTES | 10 * 1024 * 1024 |
MOVIE | 50 |
MP4_EXTENSIONS | ('.mp4', '.m4v') |
SEASON | 60 |
SHORT_SUMMARY | 255 |
STIK_EPISODE | 10 |
STIK_MOVIE | 9 |
TIMEOUT | 120 |
TMDB_COVER_BASE | 'https://image.tmdb.org/t/p/w780' |
logger | logging.getLogger(__name__) |