Skip to content

sok.server.renames

The renames of S.O.K Server: the Ready rows of a tab go to their folder.

A rename takes the rows of one tab, all those that are Ready (or picked by hand) or a list of them, and runs in the background like an analysis, never at the same time as one. The file operations of the desktop batches move them, with the file mode, the behavior settings, the subtitles and the posters of the settings; the whole rename is one operation of the history.

With hard links, every source and destination of the rename are tested first: if one pair cannot be linked, nothing is renamed and the error says which folders. A copy, or a move to another disk, needs room: if a disk would keep less than the free_space_margin_gb setting, nothing is renamed either (not_enough_space). A video converted to MKV (convert_to_mkv, copy or move mode) is a new file: it needs its size even on the same disk. The files renamed leave the table; a file that fails (a conversion too), or is skipped as a duplicate, stays on its row with why.

In copy or move mode, the MKV videos renamed get the languages the user gave their tracks without one, and with fill_track_languages those S.O.K is sure of (track_languages.py); the history notes them. A video whose languages cannot be written stays renamed, with a warning.

With write_metadata, in copy or move mode too, the MKV and MP4 videos get the information of their movie or episode and its poster (metadata.py, file_metadata.py): a movie's details are fetched once, before the files move. A video whose information cannot be written stays renamed, with a warning.

RenameError

class RenameError(code: str, **details: str)

Bases: Exception

A rename that cannot start: unknown_type, nothing_to_rename, no_destination, scan_running, already_running, a hard link problem (different_drives, no_hard_links, missing_folder) with the folders, or not_enough_space with the destination, and the bytes needed and free.

Parameters

NameTypeDescription
codestr
**detailsstr
Source

Attributes

Name
code
details

detail

def detail() -> Dict[str, str]:
Source

Renamer

class Renamer(
db: Database,
config: ConfigManager,
events: EventBus,
searcher: Searcher,
history: History,
jobs: Jobs,
notifier: Optional[Notifier] = None,
settings: Optional[Settings] = None,
)

Start the renames and keep their results in the database.

Parameters

NameTypeDefaultDescription
dbDatabase
configConfigManager
eventsEventBus
searcherSearcher
historyHistory
jobsJobs
notifierOptional[Notifier]None
settingsOptional[Settings]None
Source

current

def current() -> Dict[str, Any]:

The last rename, with its result once done.

Source

start

def start(
media_type: str,
row_ids: Optional[List[int]] = None,
auto: bool = False,
) -> int:

Start renaming the Ready rows of a tab, in the background.

Parameters

NameTypeDefaultDescription
media_typestrThe tab: movies, tv, music, books or games.
row_idsOptional[List[int]]NoneOnly these rows; all the Ready rows of the tab when None. The rows not Ready are left out.
autoboolFalseStarted by the automatic sorting (Watcher), not by a click.

Returns

  • intThe id of the rename.

Raises

Source

Functions

def link_problem(file: str, folder: str) -> Optional[str]:

Why a file cannot be hard linked into a folder, or None.

Parameters

NameTypeDescription
filestr
folderstr
Source

Attributes

NameValue
ALREADY_EXISTS'already_exists'
COVERS3
DONE'done'
FAILED'failed'
GB1000 ** 3
INTERRUPTED'interrupted'
NOT_ENOUGH_SPACE'not_enough_space'
RENAME_FAILED'failed'
RUNNING'running'
loggerlogging.getLogger(__name__)
Built with Kiln