toktokkie.metadata.base package

Submodules

toktokkie.metadata.base.IdHelper module

class toktokkie.metadata.base.IdHelper.IdHelper

Bases: object

Class that contains static methoids that help with ID operations

static fill_ids(ids: Dict[toktokkie.enums.IdType, List[str]], valid_ids: List[toktokkie.enums.IdType], _parent_ids: Optional[Dict[toktokkie.enums.IdType, List[str]]] = None) → Dict[toktokkie.enums.IdType, List[str]]

Fills in any missing id type key for an ID dictionary :param ids: The ID dictionary to fill :param valid_ids: Any valid ID types :param _parent_ids: Optionally provided dictionary of parent IDs.

The values of this dictionary will be entered into the filled dictionary if they aren’t defined already.

Returns

The filled dictionary

static generate_url_for_id(id_type: toktokkie.enums.IdType, media_type: toktokkie.enums.MediaType, _id: str) → str

Generates a URL for an ID :param id_type: The ID Type :param media_type: The media type :param _id: The ID :return: The template pattern

static int_id_types() → List[toktokkie.enums.IdType]
Returns

A list of ID types that are required to be integers

static literature_media_types() → List[toktokkie.enums.MediaType]
Returns

A list of literature media types

static minimize_ids(ids: Dict[toktokkie.enums.IdType, List[str]], _parent_ids: Optional[Dict[toktokkie.enums.IdType, List[str]]] = None) → Dict[toktokkie.enums.IdType, List[str]]

Removes redundant and empty IDs from a dictionary of IDs :param ids: The dictionary to minimize :param _parent_ids: Optionally provide a parent’s IDs. These IDs will

be removed from the child dictionary if the values are the same

Returns

The minimized dictionary

static objectify_ids(ids: Dict[str, List[str]]) → Dict[toktokkie.enums.IdType, List[str]]

Converts the keys in an ID dictionary using string keys to IdType objects :param ids: The ID dictionary to convert :return: The converted ID dictionary

static stringify_ids(ids: Dict[toktokkie.enums.IdType, List[str]]) → Dict[str, List[str]]

Converts the keys in an ID dictionary to strings :param ids: The ID dictionary to convert :return: The converted ID dictionary

static theme_song_id_types() → List[toktokkie.enums.IdType]
Returns

A list of ID types that can apply to theme songs

toktokkie.metadata.base.Metadata module

class toktokkie.metadata.base.Metadata.Metadata(directory_path: str, json_data: Optional[Dict[str, Any]] = None, no_validation: bool = False)

Bases: toktokkie.metadata.base.Renamer.Renamer, toktokkie.metadata.base.Validator.Validator, toktokkie.metadata.base.Prompter.Prompter, abc.ABC

Class that combines the various Metadata classes and defines a constructor

__init__(directory_path: str, json_data: Optional[Dict[str, Any]] = None, no_validation: bool = False)

Inititalizes the metadata object using JSON data :param directory_path: The directory of the media for which to

generate the metadata

Parameters
  • json_data – Optional metadata JSON. Will be used instead of info.json metadata if provided

  • no_validation – Skips JSON validation if True

Raises

InvalidMetadataException – if the metadata could not be parsed correctly

directory_path: str

The path to the directory this metadata describes

classmethod from_prompt(directory_path: str)toktokkie.metadata.base.Metadata.Metadata

Generates a metadata object based on interactive user input :return: The generated metadata

json: Dict[str, Any]

toktokkie.metadata.base.MetadataBase module

class toktokkie.metadata.base.MetadataBase.MetadataBase

Bases: toktokkie.metadata.base.IdHelper.IdHelper, abc.ABC

Base class for all metadata classes. Specifies most of the methods required by Metadata classes.

directory_path: str

The path to the directory this metadata describes

get_icon_file(name: str) → Optional[str]

Retrieves the path to an icon file, if it exists :param name: The name of the icon. :return: The path to the icon file or None, if the file does not exist

property icon_directory
Returns

The path to the the icon directory

property ids
Returns

A dictionary containing lists of IDs mapped to ID types

json: Dict[str, Any]
logger = <Logger toktokkie.metadata.base.MetadataBase (WARNING)>

Logger for the metadata class

classmethod media_type()toktokkie.enums.MediaType
Returns

The media type of the Metadata class

property metadata_file
Returns

The path to the metadata file

property name
Returns

The name of the media

print_folder_icon_source()

Prints a message with a URL for possible folder icons on deviantart :return: None

classmethod required_id_types() → List[toktokkie.enums.IdType]
Returns

Required ID types for the metadata

set_ids(id_type: toktokkie.enums.IdType, ids: List[str])

Sets IDs for one ID type to the metadata :param id_type: The id type :param ids: The IDs to set :return: None

property tags
Returns

A list of tags

property urls

Generates URLs for the stored ID types of this metadata object :return: The URLs mapped to their respective id types

classmethod valid_id_types() → List[toktokkie.enums.IdType]
Returns

Valid ID types for the metadata

write()

Writes the metadata to the metadata file :return: None

toktokkie.metadata.base.Prompter module

class toktokkie.metadata.base.Prompter.Prompter

Bases: toktokkie.metadata.base.MetadataBase.MetadataBase, abc.ABC

Class that’s responsible for defining the metadata creation prompts

classmethod create_id_fetcher(directory: str)toktokkie.utils.IdFetcher.IdFetcher

Creates an ID fetcher :param directory: The directory for which to generate the ID fetcher :return: The generated ID fetcher

directory_path: str

The path to the directory this metadata describes

id_prompt_order = [<IdType.TVDB: 'tvdb'>, <IdType.IMDB: 'imdb'>, <IdType.ISBN: 'isbn'>, <IdType.VNDB: 'vndb'>, <IdType.MUSICBRAINZ_ARTIST: 'musicbrainz_artist'>, <IdType.MUSICBRAINZ_RELEASE: 'musicbrainz_release'>, <IdType.MUSICBRAINZ_RECORDING: 'musicbrainz_recording'>, <IdType.MYANIMELIST: 'myanimelist'>, <IdType.ANILIST: 'anilist'>, <IdType.KITSU: 'kitsu'>, <IdType.MANGADEX: 'mangadex'>]

The order in which ID types should be prompted

json: Dict[str, Any]
classmethod pre_prompt_check(directory_path: str)

Performs checks before prompting :return: None

classmethod prompt(directory_path: str) → Dict[str, Any]

Generates a new Metadata object using prompts for a directory :param directory_path: The path to the directory for which to generate

the metadata object

Returns

The generated metadata object

classmethod prompt_component_ids(valid_ids: List[toktokkie.enums.IdType], previous_ids: Dict[str, List[str]], id_fetcher: toktokkie.utils.IdFetcher.IdFetcher) → Dict[str, List[str]]

Prompts for IDs for a component (for example, a season of a tv series) Strips away any IDs that are the same as the root metadata ids :param valid_ids: ID Types that are valid for the kind of metadata :param previous_ids: The IDs previously aquired :param id_fetcher: An ID fetcher :return: The prompted IDs, mapped to id type strings

classmethod prompt_ids(valid_ids: List[toktokkie.enums.IdType], required_ids: List[toktokkie.enums.IdType], defaults: Dict[str, List[str]], id_fetcher: toktokkie.utils.IdFetcher.IdFetcher, mincount: int = 1) → Dict[str, List[str]]

Prompts the user for any valid IDs the metadata may contain :param valid_ids: IDs that are valid for the prompt :param required_ids: IDs that are required to be provided :param defaults: Any potential default values for the IDs :param id_fetcher: An ID fetcher :param mincount: Minimal amount of IDs that the user needs to provide :return: The IDs in a dictionary mapping the ID names to their IDs

toktokkie.metadata.base.Renamer module

class toktokkie.metadata.base.Renamer.Renamer

Bases: toktokkie.metadata.base.MetadataBase.MetadataBase, abc.ABC

Class that’s responsible to define renaming functionality

create_rename_operations() → List[toktokkie.metadata.base.components.RenameOperation.RenameOperation]

Performs rename operations on the content referenced by this metadata object :return: The rename operations for this metadata

directory_path: str

The path to the directory this metadata describes

json: Dict[str, Any]
static load_anilist_title_and_year(anilist_ids: List[str], _media_type: toktokkie.enums.MediaType) → Optional[Tuple[str, int]]

Loads the title and year of an item using anilist IDs :param anilist_ids: The anilist IDs to use :param _media_type: The media type to use :return: The title of the item and the year as a tuple

static load_imdb_title_and_year(imdb_ids: List[str]) → Optional[Tuple[str, int]]

Loads the title and year of an item using IMDB IDs :parameter imdb_ids: The IMDB IDs :return: The title of the item and the year as a tuple

load_title_and_year(id_type_priority: List[toktokkie.enums.IdType], id_override: Optional[Dict[toktokkie.enums.IdType, List[str]]] = None) → Tuple[str, Optional[int]]

Loads the title and year based on a custom order of id types

rename(noconfirm: bool = False, skip_title: bool = False)

Renames the contained files according to the naming schema. :param noconfirm: Skips the confirmation phase if True :param skip_title: If True, will skip title renaming :return: None

resolve_title_name() → str

If possible, will fetch the appropriate name for the metadata based on IDs, falling back to the directory name if this is not possible or supported.

toktokkie.metadata.base.Validator module

class toktokkie.metadata.base.Validator.Validator

Bases: toktokkie.metadata.base.MetadataBase.MetadataBase, abc.ABC

Class that handles validation of metadata

classmethod build_schema() → Dict[str, Any]

Generates the JSON schema :return: The JSON schema

directory_path: str

The path to the directory this metadata describes

json: Dict[str, Any]
validate()

Validates the JSON data to make sure everything has valid values :raises InvalidMetadataException: If any errors were encountered :return: None

Module contents