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
| Name | Type | Description |
|---|---|---|
code | str | |
**details | str |
Attributes
| Name |
|---|
code |
details |
detail
def detail() -> Dict[str, str]: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
| Name | Type | Default | Description |
|---|---|---|---|
db | Database | ||
config | ConfigManager | ||
events | EventBus | ||
searcher | Searcher | ||
history | History | ||
jobs | Jobs | ||
notifier | Optional[Notifier] | None | |
settings | Optional[Settings] | None |
current
def current() -> Dict[str, Any]:The last rename, with its result once done.
Sourcestart
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
| Name | Type | Default | Description |
|---|---|---|---|
media_type | str | The tab: movies, tv, music, books or games. | |
row_ids | Optional[List[int]] | None | Only these rows; all the Ready rows of the tab when None. The rows not Ready are left out. |
auto | bool | False | Started by the automatic sorting (Watcher), not by a click. |
Returns
intThe id of the rename.
Raises
RenameErrorSee its codes.
Functions
link_problem
def link_problem(file: str, folder: str) -> Optional[str]:Why a file cannot be hard linked into a folder, or None.
Parameters
| Name | Type | Description |
|---|---|---|
file | str | |
folder | str |
Attributes
| Name | Value |
|---|---|
ALREADY_EXISTS | 'already_exists' |
COVERS | 3 |
DONE | 'done' |
FAILED | 'failed' |
GB | 1000 ** 3 |
INTERRUPTED | 'interrupted' |
NOT_ENOUGH_SPACE | 'not_enough_space' |
RENAME_FAILED | 'failed' |
RUNNING | 'running' |
logger | logging.getLogger(__name__) |