Documentation
¶
Overview ¶
Package quality implements quality profiles ("Quality profiles (custom formats, TRaSH-Guides-inspired sane defaults shipped out of the box)"). A profile ranks known quality tiers from worst to best, decides whether a given release is acceptable at all, and whether one release is an upgrade over another (for the missing/upgrade hunting loop in internal/automation).
Index ¶
- Constants
- Variables
- func PresetKeys() []string
- func PresetName(key string) (string, bool)
- func Presets() map[string]Profile
- func Rank(t Tier) int
- func SizePlausible(t Tier, size int64, episodes int) bool
- type LanguageFit
- type Preferred
- type Profile
- func (p Profile) AcceptedBy(title string) (by Profile, fallback, ok bool)
- func (p Profile) Accepts(r parser.Release) bool
- func (p Profile) AcceptsTitle(title string) bool
- func (p Profile) AllowsTier(t Tier) bool
- func (p Profile) Chain() []Profile
- func (p Profile) IsUpgrade(current, candidate parser.Release) bool
- func (p Profile) IsUpgradeOverTier(currentTier Tier, candidate parser.Release) bool
- func (p Profile) LanguageOK(r parser.Release) bool
- func (p Profile) LanguageRank(r parser.Release) int
- func (p Profile) LanguageReason(r parser.Release) string
- func (p Profile) OnFallback(t Tier) bool
- func (p Profile) ReachedCutoff(r parser.Release) bool
- func (p Profile) ReachedCutoffTier(t Tier) bool
- func (p Profile) Score(title string) int
- func (p Profile) SizeAllowed(size int64) bool
- func (p Profile) TitleAllowed(title string) (bool, string)
- type Repo
- func (r *Repo) Create(p Profile) (Profile, error)
- func (r *Repo) Delete(id, defaultID int64) error
- func (r *Repo) Get(id int64) (Profile, error)
- func (r *Repo) List() ([]Profile, error)
- func (r *Repo) SeedPresets(seeded int) ([]Profile, error)
- func (r *Repo) Update(p Profile) (Profile, error)
- func (r *Repo) Usage() (map[int64]int, error)
- type Tier
Constants ¶
const ( PresetCinema = "cinema" PresetAny = "any" Preset720p = "720p" Preset1080p = "1080p" Preset4K = "4k" // DefaultPreset is the preset a fresh install uses for every item that has // no profile of its own. DefaultPreset = Preset1080p )
Keys of the built-in presets returned by Presets.
const DefaultLanguage = parser.English
DefaultLanguage is the audio language wanted when none has been chosen.
const PresetsVersion = 4
PresetsVersion is the revision of the built-in preset set. The caller stores the version it last seeded (a settings key) and passes it back to SeedPresets, so each revision is applied exactly once:
1: "Up to 1080p", "Ultra-HD (up to 2160p)", "Any" 2: "Any", "720p", "1080p", "4K & over" (1080p and 4K with a fallback) 3: the same four, each resolution preset strict to its own resolution 4: adds "Cinema recordings" (CAM/TeleSync only)
const SeasonPack = -1
SeasonPack is the episode count to pass for a whole-season release whose episodes are not listed. It counts as three episodes, which is safe for any real season.
Variables ¶
var ErrInUse = errors.New("quality profile is in use")
ErrInUse is returned when deleting a profile that is still the default or assigned to library items.
var ErrInvalid = errors.New("invalid quality profile")
ErrInvalid wraps validation failures (bad name, unknown tier, cutoff not in the allowed list) so the API can report them as user errors.
Functions ¶
func PresetKeys ¶
func PresetKeys() []string
PresetKeys lists the built-in presets in the order they are created (and so listed): from lowest to best, then "Any".
func PresetName ¶
PresetName returns the display name of the preset a key stands for: a current key ("1080p") or one from the old single global setting ("any-1080p", "ultra-hd"), which map to their current equivalent.
func Presets ¶
Presets ships TRaSH-Guides-inspired sane defaults so most users never need to hand-build a profile. Every preset starts with the search for better versions switched off (UpgradeAllowed false): a title is downloaded once and left alone, and the person turns upgrades on for the profiles where they want them. Titles that were only downloaded because of a fallback profile are still searched for a replacement.
"Cinema recordings" is the only preset that takes CAM/TeleSync copies, and takes nothing else: it is meant as an opt-in fallback for a film that is still only in cinemas, so the normal upgrade hunt of the title's own profile replaces it once a proper release appears.
Each resolution preset accepts only its own resolution, so what it says is what you get: "1080p" never settles for 720p and "4K & over" never settles for 1080p. A title with no release at that resolution waits until one appears; "Any" is the preset that takes whatever exists.
Remux tiers are deliberately left out of "1080p": a 1080p remux is an untouched copy of the disc, typically 20-40 GB per movie, several times the size of a Bluray encode that looks the same on most screens. Someone who wants remuxes is choosing large files on purpose and can build a profile for it; the everyday default should not fill a disk by surprise. "4K & over" does include Remux-2160p, but its cutoff (Bluray-2160p) means a remux is only grabbed when it is the best release found, never hunted as an upgrade.
Types ¶
type LanguageFit ¶
type LanguageFit struct {
// Rank orders acceptable releases, higher is better: 3 is the wanted
// language alone (or nothing tagged when English is wanted), 2 is the
// wanted language together with another one, 1 is a multi-language
// release that does not say it holds the wanted language. Rejected
// releases have rank 0.
Rank int
// Accepted is false for a release that is clearly in another language
// only (ITALIAN, GERMAN, FRENCH... with nothing that includes the wanted
// language). Automation never takes such a release; a manual grab is
// still allowed.
Accepted bool
// Label names the languages the release says it has, in words for the
// release list: "Italian + English", "Multi", "English". Empty when the
// release carries no language tag at all.
Label string
}
LanguageFit says how well a release's audio language suits the language the person wants.
func FitLanguage ¶
func FitLanguage(r parser.Release, preferred string) LanguageFit
FitLanguage judges a release for a person who wants preferred audio. An empty preferred language accepts everything. A release with no language tag is taken to be in English, the language nearly everything untagged is in.
type Profile ¶
type Profile struct {
ID int64 // 0 for a profile that isn't stored (the built-in presets in tests)
Name string
Allowed []Tier
Cutoff Tier
// UpgradeAllowed is false for "grab once and stop": a downloaded item is
// never searched again for a better release.
UpgradeAllowed bool
// Release restrictions, matched case-insensitively against the release
// title (dots, underscores and dashes count as spaces). A release must
// contain at least one MustContain term (when any are set) and none of
// the MustNotContain terms.
MustContain []string
MustNotContain []string
// Preferred terms add their score to a matching release; among releases
// of the same quality tier the highest total score wins.
Preferred []Preferred
// MaxSizeGB is the largest release this profile accepts, in GB (0 = no
// limit). See SizeAllowed.
MaxSizeGB float64
// Fallback lists other profiles (by id) that an automatic search tries,
// in this order, when nothing it found is acceptable to this profile.
// Only this profile's own list is used (a fallback's fallbacks are not
// followed). Empty means no fallback.
Fallback []int64
// FallbackProfiles is Fallback resolved to the profiles themselves, filled
// in by whoever loads the profile for a decision; it is not stored.
FallbackProfiles []Profile
// Language is the audio language wanted, filled in by whoever loads the
// profile for a decision from the "Preferred audio language" setting; it
// is not stored with the profile. A release clearly in another language
// only is not accepted (see FitLanguage). Empty means any language.
Language string
}
Profile is a named allow-list of tiers plus a cutoff — once a movie has a file at or above the cutoff, the hunting loop stops looking for upgrades.
func Validate ¶
Validate checks a profile is coherent: named, at least one allowed tier, every tier real ("Unknown" is valid: it means releases whose names carry no recognisable quality), and the cutoff one of the allowed tiers. It returns the profile with tiers de-duplicated and ordered worst-to-best.
func (Profile) AcceptedBy ¶
AcceptedBy returns the first profile in the chain (this profile, then its fallbacks in order) that accepts a release title, and whether it is a fallback. ok is false when none does.
func (Profile) Accepts ¶
Accepts reports whether a release's tier is in this profile's allow-list at all (regardless of whether it's an upgrade over anything) and its audio language is not clearly another one than the wanted language.
func (Profile) AcceptsTitle ¶
AcceptsTitle reports whether a release title passes both this profile's quality allow-list and its release restrictions.
func (Profile) AllowsTier ¶
AllowsTier reports whether a quality tier is in this profile's allow-list.
func (Profile) Chain ¶
Chain is the profile followed by its resolved fallbacks, in the order an automatic search tries them.
func (Profile) IsUpgrade ¶
IsUpgrade reports whether candidate is a better (and still profile- accepted) quality than current, and current hasn't already reached the cutoff.
func (Profile) IsUpgradeOverTier ¶
IsUpgradeOverTier is IsUpgrade for call sites that only have a previously-classified tier on hand (e.g. the automation hunt loop re-checking an already-downloaded movie) rather than a fresh parser.Release for "current".
A current file that is there only because of a fallback (see OnFallback) is never "at the cutoff": any release this profile accepts replaces it.
func (Profile) LanguageOK ¶
LanguageOK reports whether a release's audio language suits the language this profile was loaded with (Language). It is true when none is set.
func (Profile) LanguageRank ¶
LanguageRank is FitLanguage(r, p.Language).Rank.
func (Profile) LanguageReason ¶
LanguageReason explains, in plain words, why a release was turned down for its language, or "" when it was not.
func (Profile) OnFallback ¶
OnFallback reports whether a file of tier t is there only because of a fallback: this profile does not allow t but one of its fallbacks does. Such a file is always replaced by a release this profile accepts, whatever its rank, the cutoff or the upgrade switch.
func (Profile) ReachedCutoff ¶
ReachedCutoff reports whether a release already meets or exceeds this profile's cutoff — the hunting loop should stop upgrading past this.
func (Profile) ReachedCutoffTier ¶
ReachedCutoffTier is ReachedCutoff for a tier that's already on hand (e.g. a stored movie's quality column) rather than a fresh release to classify.
func (Profile) SizeAllowed ¶ added in v1.4.0
SizeAllowed reports whether size bytes is within the profile's largest size. No limit (0) or an unknown size (0) always passes.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo stores user-editable profiles.
func (*Repo) Delete ¶
Delete removes a profile that nothing references. defaultID is the currently-default profile, which cannot be deleted.
func (*Repo) SeedPresets ¶
SeedPresets brings the built-in presets up to PresetsVersion and returns all profiles. seeded is the version applied last time (0 if never).
- Up to date: nothing changes.
- Empty table (first start): the current presets are created.
- Older install: each old built-in preset that is still exactly as it was shipped is redefined in place as its new equivalent ("Up to 1080p" becomes "1080p", "Ultra-HD (up to 2160p)" becomes "4K & over", "Any" keeps its name with the new definition; revision 2's "1080p" and "4K & over" lose their lower-resolution fallback). Keeping the row keeps its id, so items assigned to it, and the default profile setting, follow it. A preset the user edited is left alone. Then every current preset newer than the seeded version that is still missing by name is created (a preset the install already had is not recreated).
Presets are ordinary rows afterwards: users can edit or delete them like any other profile, and a deleted preset is not brought back on a later start.
type Tier ¶
type Tier string
Tier is one recognized quality level, ordered worst-to-best. This mirrors the widely-used TRaSH-Guides quality ladder (resolution + source combined, since a 1080p WEBRip and a 1080p Bluray are not equivalent quality despite sharing a resolution).
const ( TierUnknown Tier = "Unknown" TierPreRelease Tier = "CAM/TeleSync" // cinema recordings and screeners, whatever resolution they claim TierSDTV Tier = "SDTV" TierDVD Tier = "DVD" TierWebDL480p Tier = "WEBDL-480p" TierHDTV720p Tier = "HDTV-720p" TierWebDL720p Tier = "WEBDL-720p" TierBluray720p Tier = "Bluray-720p" TierHDTV1080p Tier = "HDTV-1080p" TierWebDL1080p Tier = "WEBDL-1080p" TierBluray1080p Tier = "Bluray-1080p" TierRemux1080p Tier = "Remux-1080p" TierHDTV2160p Tier = "HDTV-2160p" TierWebDL2160p Tier = "WEBDL-2160p" TierBluray2160p Tier = "Bluray-2160p" TierRemux2160p Tier = "Remux-2160p" )