sok.file_operations.organize
Organization of a list of files selected in the UI.
This module provides the FileListOrganizerMixin used by the music, book and game file operations. Video has its own implementation, which handles season folders.
FileListOrganizerMixin
class FileListOrganizerMixinMove a list of files into the folder structure of a media item.
Requires the class to provide generate_new_filename(media_item, filename).
Sourcebatch_target
def batch_target( media_item: MediaItem, file_path: Path, alone: bool,) -> Tuple[List[str], str]:Folders and file name of one file of a batch.
Parameters
| Name | Type | Description |
|---|---|---|
media_item | MediaItem | The media item of the file. |
file_path | Path | The file. |
alone | bool | False when the item has other files in the batch, such as the .bin of a .cue. |
Returns
Tuple[List[str], str]The folders under the destination, and the new file name.
get_destination_folders
def get_destination_folders(media_item: Optional[MediaItem]) -> List[str]:Return the folders to create under the destination path.
Parameters
| Name | Type | Description |
|---|---|---|
media_item | Optional[MediaItem] | The selected media item, or None. |
Returns
List[str]Folder names from the destination root to the file location.
organize_files_list
def organize_files_list( files: List[Path], dest_path: str, media_item: Optional[MediaItem], dry_run: bool = False, progress_callback: Optional[Callable[[int, int, str], None]] = None,) -> Dict[str, Any]:Organize a list of files into the media item's folder structure.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
files | List[Path] | List of files to organize. | |
dest_path | str | Destination folder. | |
media_item | Optional[MediaItem] | The selected media item. If None, files are renamed and moved directly into dest_path. | |
dry_run | bool | False | If True, simulate without making changes. |
progress_callback | Optional[Callable[[int, int, str], None]] | None | Function called with (current, total, filename). |
Returns
Dict[str, Any]Organization report.
organize_items_batch
def organize_items_batch( mappings: List[Tuple[Path, MediaItem]], dest_path: str, dry_run: bool = False, progress_callback: Optional[Callable[[int, int, str], None]] = None,) -> Dict[str, Any]:Organize files that each have their own media item.
Each file goes where batch_target() says: by default the folder structure of its item, under the name generate_new_filename() gives. A batch of books, each with its own book, for instance. The files of one item share the same media item object.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
mappings | List[Tuple[Path, MediaItem]] | (file, media item) pairs. | |
dest_path | str | Destination folder. | |
dry_run | bool | False | If True, simulate without making changes. |
progress_callback | Optional[Callable[[int, int, str], None]] | None | Function called with (current, total, filename). |
Returns
Dict[str, Any]Organization report, as organize_files_list() returns.
Attributes
| Name | Value |
|---|---|
logger | logging.getLogger(__name__) |