Module caption

Module caption 

Source
Expand description

Caption processing module for handling both JSON and plain text caption files.

This module provides functionality to process caption files in different formats:

  • JSON files containing caption data either as direct strings or objects with a “caption” field
  • Plain text files containing raw caption text

§Example

use std::path::Path;
use dset::caption::process_file;

async fn example() -> anyhow::Result<()> {
    let path = Path::new("captions/example.json");
    process_file(&path).await?;
    Ok(())
}

The module handles file reading asynchronously and provides error handling for various failure scenarios including file I/O errors and JSON parsing failures.

Structs§

E621Config
Configuration for e621 caption processing.

Constants§

IGNORED_E621_TAGS
Patterns of tags to be ignored during e621 tag processing.

Functions§

caption_file_exists_and_not_empty
Checks if a caption file exists and contains non-whitespace content.
format_text_content
Formats text content by removing excessive whitespace and newlines.
json_to_text
Converts a JSON value into plain text by extracting the caption content.
process_e621_json_data
Processes JSON data from e621 and creates a caption file.
process_e621_json_file
Process an e621 JSON file and generate caption files.
process_e621_tags
Processes and formats e621 tags from the JSON data.
process_file
Processes a caption file by reading its contents and interpreting them as either JSON or plain text.
replace_special_chars
Replaces special characters with their keyboard-friendly versions in a file.
replace_string
Replaces all instances of a search string with a replacement string in a file.
should_ignore_e621_tag
Checks if a tag should be ignored based on predefined patterns.