Skip to content

sok.server.scans

The analyses of S.O.K Server: scan the source folders, sort the files, search them.

An analysis runs in the background, one at a time. The type detector of the desktop home page (MediaTypeDetector) sorts the files of the source folders; each item becomes a row of the table of its media type:

  • one row per movie, track, book or game (the .cue and .bin of a game are one item);
  • one row per series, its episodes being its files, and one per album.

A new analysis keeps the rows it finds again, with the choices made on them (search text, match, destination): a series or an album keeps them when episodes or tracks are added. The rows whose files are gone are removed. The files whose type is a guess are "to check", until the user confirms a type, which the next analyses remember. The files already processed (renamed before, with the same size and date) are left out and counted.

Then the rows not searched yet are searched (Searcher), kind by kind. A missing key or a used quota stops the media types of that service, with the rows sorted; the error of the analysis says which key.

RowDraftdataclass

class RowDraft(
key: str,
kind: ContentType,
title: Optional[str],
files: List[str],
)

A row as an analysis finds it, before the database.

Parameters

NameTypeDescription
keystr
kindContentType
titleOptional[str]
filesList[str]
Source

Attributes

NameType
filesList[str]
keystr
kindContentType
titleOptional[str]

media_typeproperty

str

ScanError

class ScanError(code: str)

Bases: Exception

An analysis that cannot start: already_running, rename_running or no_sources.

Parameters

NameTypeDescription
codestr
Source

Attributes

Name
code

Scans

class Scans(
db: Database,
settings: Settings,
events: EventBus,
searcher: Searcher,
jobs: Jobs,
)

Start the analyses and keep their results in the database.

Parameters

NameTypeDescription
dbDatabase
settingsSettings
eventsEventBus
searcherSearcher
jobsJobs
Source

confirmasync

async def confirm(path: str, kind: ContentType) -> Optional[Dict[str, Any]]:

Give a file to check its type: it joins the rows of that type.

The choice is remembered for the next analyses. A new row is searched at once, as the rows of an analysis.

Parameters

NameTypeDescription
pathstr
kindContentType

Returns

  • Optional[Dict[str, Any]]Why the search stopped (search_error), or None.

Raises

Source

start

def start(auto: bool = False) -> int:

Start an analysis of the source folders, in the background.

Parameters

NameTypeDefaultDescription
autoboolFalseStarted by the automatic sorting (Watcher), not by a click.

Returns

  • intThe id of the analysis.

Raises

  • ScanErroralready_running, rename_running, or no_sources when no source folder is set.
Source

summary

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

The last analysis, the rows per media type and status, the files to check.

Source

UnknownFile

class UnknownFile

Bases: ValueError

A file that is not to check.

Source

Functions

drafts_from_report

def drafts_from_report(report: DetectionReport) -> List[RowDraft]:

The rows of the groups of a detection report.

Parameters

NameTypeDescription
reportDetectionReport
Source

Attributes

NameValue
DONE'done'
FAILED'failed'
GROUP_KINDS(ContentType.EPISODE, ContentType.ALBUM)
INTERRUPTED'interrupted'
MEDIA_TYPE_OF{ContentType.MOVIE: 'movies', ContentType.EPISODE: 'tv', ContentType.ALBUM: 'music', ContentType.TRACK: 'music', ContentType.BOOK: 'books', ContentType.GAME: 'games'}
PENDING'pending'
ROW_STATUSES(PENDING, 'ok', 'ambiguous', 'missing')
RUNNING'running'
loggerlogging.getLogger(__name__)
Built with Kiln