Skip to content

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 FileListOrganizerMixin

Move a list of files into the folder structure of a media item.

Requires the class to provide generate_new_filename(media_item, filename).

Source

batch_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

NameTypeDescription
media_itemMediaItemThe media item of the file.
file_pathPathThe file.
aloneboolFalse 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.
Source

get_destination_folders

def get_destination_folders(media_item: Optional[MediaItem]) -> List[str]:

Return the folders to create under the destination path.

Parameters

NameTypeDescription
media_itemOptional[MediaItem]The selected media item, or None.

Returns

  • List[str]Folder names from the destination root to the file location.
Source

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

NameTypeDefaultDescription
filesList[Path]List of files to organize.
dest_pathstrDestination folder.
media_itemOptional[MediaItem]The selected media item. If None, files are renamed and moved directly into dest_path.
dry_runboolFalseIf True, simulate without making changes.
progress_callbackOptional[Callable[[int, int, str], None]]NoneFunction called with (current, total, filename).

Returns

  • Dict[str, Any]Organization report.
Source

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

NameTypeDefaultDescription
mappingsList[Tuple[Path, MediaItem]](file, media item) pairs.
dest_pathstrDestination folder.
dry_runboolFalseIf True, simulate without making changes.
progress_callbackOptional[Callable[[int, int, str], None]]NoneFunction called with (current, total, filename).

Returns

  • Dict[str, Any]Organization report, as organize_files_list() returns.
Source

Attributes

NameValue
loggerlogging.getLogger(__name__)
Built with Kiln