classify

package
v0.1.147 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: GPL-2.0, GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package classify provides subtitle classification (forced/HI) and language resolution utilities consumed by provider sub-packages.

Index

Constants

This section is empty.

Variables

View Source
var ForcedRules = []Rule{
	{"forced", true},
	{"foreign", true},
}

ForcedRules is the declarative table for forced/foreign-parts classification. All entries are positive (any match confirms forced status).

View Source
var HearingImpairedRules = []Rule{

	{"hi remove", false},
	{"non hi", false},
	{"nonhi", false},
	{"non-hi", false},
	{"non-sdh", false},
	{"non sdh", false},
	{"nonsdh", false},
	{"sdh remove", false},

	{"_hi_", true},
	{" hi ", true},
	{".hi.", true},
	{"_cc_", true},
	{" cc ", true},
	{".cc.", true},
	{"sdh", true},
	{"closed caption", true},
}

HearingImpairedRules is the declarative table for HI/SDH/CC classification. Negative entries (Polarity=false) deny HI status and take precedence over positive entries. The first matching entry determines the result.

View Source
var LangNameToISO2 map[string]string

LangNameToISO2 is the reverse of LangRegistry: English name → ISO-2 code. Built once at init time from LangRegistry.

View Source
var LangRegistry = map[string]string{
	"en": "English", "fr": "French", "es": "Spanish", "de": "German",
	"it": "Italian", "pt": "Portuguese", "nl": "Dutch", "ru": "Russian",
	"ar": "Arabic", "ja": "Japanese", "zh": "Chinese", "ko": "Korean",
	"sv": "Swedish", "no": "Norwegian", "da": "Danish", "fi": "Finnish",
	"pl": "Polish", "cs": "Czech", "hu": "Hungarian", "ro": "Romanian",
	"tr": "Turkish", "el": "Greek", "he": "Hebrew", "th": "Thai",
	"vi": "Vietnamese", "id": "Indonesian", "bg": "Bulgarian",
	"hr": "Croatian", "sr": "Serbian", "sl": "Slovenian",
	"sk": "Slovak", "uk": "Ukrainian", "ca": "Catalan",
	"eu": "Basque", "gl": "Galician", "fa": "Persian",
	"ms": "Malay", "sq": "Albanian", "bs": "Bosnian",
	"hy": "Armenian", "az": "Azerbaijani", "bn": "Bengali",
	"mk": "Macedonian", "hi": "Hindi", "ta": "Tamil",
	"te": "Telugu", "ml": "Malayalam", "kn": "Kannada",
	"mr": "Marathi", "ur": "Urdu", "ne": "Nepali",
	"si": "Sinhalese", "af": "Afrikaans", "sw": "Swahili",
	"lt": "Lithuanian", "lv": "Latvian", "et": "Estonian",
	"is": "Icelandic", "ga": "Irish", "cy": "Welsh",
	"ka": "Georgian", "mn": "Mongolian", "km": "Khmer",
	"lo": "Lao", "my": "Burmese", "pb": "Brazilian Portuguese",
}

LangRegistry is the canonical ISO 639-1 → English language name mapping. Provider sub-packages use this as the single source of truth, applying per-provider overrides only for non-standard names (e.g. "Brazillian Portuguese" for SubSource API compat).

Functions

func Alpha2FromAlpha3

func Alpha2FromAlpha3(code string) string

Alpha2FromAlpha3 converts an ISO 639-2/3 code to ISO 639-1. Returns the input unchanged if it is already 2 characters. Returns empty string if the code is unknown.

func IsForced

func IsForced(comment string) bool

IsForced returns true if the comment string indicates a forced or foreign-parts subtitle track.

func IsHearingImpaired

func IsHearingImpaired(commentary, filename string) bool

IsHearingImpaired reports whether commentary or a filename indicates a hearing-impaired / SDH / closed-caption subtitle. A filename containing "_hi_" short-circuits to true regardless of commentary. Negative rules ("non hi", "non sdh", etc.) win over positive ones. The filename is optional: providers without a filename field should pass "".

func LookupLangCode

func LookupLangCode(name string, overrides map[string]string) string

LookupLangCode returns the ISO-2 code for an English language name, applying provider-specific overrides if provided. Returns empty string if the name is unknown.

func LookupLangName

func LookupLangName(code string, overrides map[string]string) string

LookupLangName returns the English language name for an ISO-2 code, applying provider-specific overrides if provided. Returns empty string if the code is unknown.

func SanitizeImdbID

func SanitizeImdbID(id string) string

SanitizeImdbID strips the "tt" prefix and leading zeros from an IMDB ID, returning the bare numeric string expected by most subtitle APIs.

Types

type Rule

type Rule struct {
	Pattern  string
	Polarity bool
}

Rule defines a single subtitle classification entry. Polarity determines the match outcome: true = positive (confirms the classification), false = negative (denies it, overrides positive matches).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL