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§
- E621
Config - 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.