pub struct FileInfo {
pub name: String,
pub relative_path: String,
pub full_path: PathBuf,
pub directory: String,
pub depth: usize,
pub language: Option<LanguageInfo>,
}Expand description
Extended file information structure with metadata for intelligent matching.
This structure contains comprehensive information about discovered files, including path relationships, language detection results, and contextual metadata that enables sophisticated matching algorithms.
§Purpose
FileInfo serves as the primary data structure for file representation
in the matching system. It normalizes file information from different
sources and provides a consistent interface for matching algorithms.
§Path Relationships
The structure maintains three different path representations:
name: Just the filename for display and basic comparisonrelative_path: Path relative to search root for organizationfull_path: Absolute path for file system operations
§Language Detection
Language information is automatically detected from:
- Filename patterns (e.g., “movie.en.srt”, “film.zh-tw.ass”)
- Directory structure (e.g., “English/”, “Chinese/”)
- File content analysis for subtitle files
§Examples
use subx_cli::core::matcher::FileInfo;
use std::path::PathBuf;
let root = PathBuf::from("/media/movies");
let file_path = PathBuf::from("/media/movies/Action/movie.en.srt");
let file_info = FileInfo::new(&file_path, &root)?;
assert_eq!(file_info.name, "movie.en.srt");
assert_eq!(file_info.relative_path, "Action/movie.en.srt");
assert_eq!(file_info.directory, "Action");
assert_eq!(file_info.depth, 1);
if let Some(lang) = &file_info.language {
println!("Detected language: {}", lang.code);
}Fields§
§name: StringFile name without directory path for display and comparison.
This is the base filename including extension, useful for pattern matching and user-friendly display.
relative_path: StringPath relative to the search root directory for organization.
Maintains the directory structure context while being independent of the absolute filesystem location.
full_path: PathBufAbsolute file system path for file operations.
Used for actual file reading, writing, and metadata access.
directory: StringName of the immediate parent directory containing the file.
Useful for organization-based matching and language detection from directory names.
depth: usizeDirectory depth relative to the root search path.
Indicates how many subdirectory levels deep the file is located. Depth 0 means the file is directly in the root directory.
language: Option<LanguageInfo>Detected language information from filename or content analysis.
Contains language code, confidence level, and detection method.
May be None if no language could be reliably detected.
Implementations§
Source§impl FileInfo
impl FileInfo
Sourcepub fn new(full_path: PathBuf, root_path: &Path) -> Result<Self>
pub fn new(full_path: PathBuf, root_path: &Path) -> Result<Self>
Construct a new FileInfo from a file path and search root directory.
This method performs comprehensive analysis of the file location, extracting path relationships, directory structure, and attempting automatic language detection from the filename and path.
§Arguments
full_path- Absolute path to the media or subtitle fileroot_path- Root directory for file discovery (used to compute relative paths)
§Returns
Returns a FileInfo struct with all metadata populated, including
optional language detection results.
§Errors
Returns SubXError::Other if:
- The file path cannot be made relative to the root path
- Path contains invalid Unicode characters
- File system access issues occur during analysis
§Examples
use subx_cli::core::matcher::FileInfo;
use std::path::PathBuf;
// Simple file in root directory
let root = PathBuf::from("/media/videos");
let file_path = root.join("movie.mp4");
let info = FileInfo::new(file_path, &root)?;
assert_eq!(info.name, "movie.mp4");
assert_eq!(info.relative_path, "movie.mp4");
assert_eq!(info.depth, 0);
// File in subdirectory with language
let sub_file = root.join("English").join("movie.en.srt");
let sub_info = FileInfo::new(sub_file, &root)?;
assert_eq!(sub_info.name, "movie.en.srt");
assert_eq!(sub_info.relative_path, "English/movie.en.srt");
assert_eq!(sub_info.directory, "English");
assert_eq!(sub_info.depth, 1);
assert!(sub_info.language.is_some());§Implementation Details
- Path separators are normalized to Unix style (/) for consistency
- Directory depth is calculated based on relative path components
- Language detection runs automatically using multiple detection methods
- All path operations are Unicode-safe with fallback to empty strings
Sourcepub fn is_in_root(&self) -> bool
pub fn is_in_root(&self) -> bool
Check if this file is in the root directory (depth 0).
Returns true if the file is directly in the search root,
false if it’s in a subdirectory.
Sourcepub fn has_language(&self) -> bool
pub fn has_language(&self) -> bool
Check if this file has detected language information.
Returns true if language detection was successful and
confidence is above the detection threshold.
Sourcepub fn language_code(&self) -> Option<&str>
pub fn language_code(&self) -> Option<&str>
Sourcepub fn normalized_name(&self) -> String
pub fn normalized_name(&self) -> String
Create a normalized version of the filename for comparison.
Applies various normalization rules to make filenames more comparable during matching operations:
- Converts to lowercase
- Removes common separators and special characters
- Standardizes whitespace
- Removes quality indicators and release group tags
§Returns
A normalized filename string suitable for fuzzy matching.
§Examples
// "Movie.Name.2023.1080p.BluRay.x264-GROUP.mkv"
// becomes "movie name 2023"
let normalized = file_info.normalized_name();