Skip to content

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 MetadataError

Bases: OSError

The information could not be written; the video is as it was.

Source

VideoInfodataclass

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

NameTypeDefaultDescription
titlestr
yearOptional[int]None
dateOptional[str]None
directorsList[str]list()
genresList[str]list()
summarystr''
seriesOptional[str]None
seasonOptional[int]None
episodeOptional[int]None
episode_titlestr''
coverOptional[str]None
Source

Attributes

NameType
coverOptional[str]
dateOptional[str]
directorsList[str]
episodeOptional[int]
episode_titlestr
genresList[str]
seasonOptional[int]
seriesOptional[str]
summarystr
titlestr
yearOptional[int]

is_episodeproperty

bool

display_title

def display_title() -> str:

The title of the file: "Dune", or "Severance - S01E02 - Half Loop".

Source

fields

def fields() -> List[str]:

The information it holds, in the order the history shows them.

Source

Functions

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

NameTypeDescription
pathOptional[str]
Source

download_cover

def download_cover(poster_path: Optional[str], folder: str) -> Optional[str]:

Download the poster of a search result into a folder.

Parameters

NameTypeDescription
poster_pathOptional[str]
folderstr

Returns

  • Optional[str]The image file, None without a poster or when it fails: the video
  • Optional[str]then gets its information without its poster.
Source

mkv_tags

def mkv_tags(info: VideoInfo) -> str:

The global tags of an MKV, as the XML mkvpropedit reads.

Parameters

NameTypeDescription
infoVideoInfo
Source

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

NameTypeDescription
pathstr
Source

write_metadata

def write_metadata(path: str, info: VideoInfo) -> List[str]:

Write the information of a movie or an episode into its video.

Parameters

NameTypeDescription
pathstrThe video: an MKV or an MP4.
infoVideoInfoWhat to write.

Returns

  • List[str]The fields written (VideoInfo.fields); empty for a format that has
  • List[str]none (AVI, TS).

Raises

  • MetadataErrorThe tool is missing, failed, or the video does not read as expected afterwards.
Source

Attributes

NameValue
COLLECTION70
COVER_NAME'cover'
DOWNLOAD_TIMEOUT15
DURATION_MARGIN0.5
EPISODE50
MAX_COVER_BYTES10 * 1024 * 1024
MOVIE50
MP4_EXTENSIONS('.mp4', '.m4v')
SEASON60
SHORT_SUMMARY255
STIK_EPISODE10
STIK_MOVIE9
TIMEOUT120
TMDB_COVER_BASE'https://image.tmdb.org/t/p/w780'
loggerlogging.getLogger(__name__)
Built with Kiln