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
| Name | Type | Description |
|---|---|---|
key | str | |
kind | ContentType | |
title | Optional[str] | |
files | List[str] |
Attributes
| Name | Type |
|---|---|
files | List[str] |
key | str |
kind | ContentType |
title | Optional[str] |
media_typeproperty
str
ScanError
class ScanError(code: str)Bases: Exception
An analysis that cannot start: already_running, rename_running or no_sources.
Parameters
| Name | Type | Description |
|---|---|---|
code | str |
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.
Sourceconfirmasync
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
| Name | Type | Description |
|---|---|---|
path | str | |
kind | ContentType |
Returns
Optional[Dict[str, Any]]Why the search stopped (search_error), or None.
Raises
UnknownFileThe file is not to check.
start
def start(auto: bool = False) -> int:Start an analysis of the source folders, in the background.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
auto | bool | False | Started 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.
summary
def summary() -> Dict[str, Any]:The last analysis, the rows per media type and status, the files to check.
SourceUnknownFile
class UnknownFileBases: ValueError
A file that is not to check.
SourceFunctions
drafts_from_report
def drafts_from_report(report: DetectionReport) -> List[RowDraft]:The rows of the groups of a detection report.
Parameters
| Name | Type | Description |
|---|---|---|
report | DetectionReport |
Attributes
| Name | Value |
|---|---|
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' |
logger | logging.getLogger(__name__) |