Filter by audio format; apply filter changes live behind the dialog
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+31
-13
@@ -13,7 +13,7 @@ import (
|
||||
// empty field means "any". All fields must match the same file; a series
|
||||
// matches when any of its files does.
|
||||
type attrFilter struct {
|
||||
res, codec, hdr, lang string
|
||||
res, codec, hdr, audio, lang string
|
||||
}
|
||||
|
||||
const anyOption = "any"
|
||||
@@ -22,6 +22,8 @@ var (
|
||||
resOptions = []string{"2160p", "1080p", "720p", "SD"}
|
||||
codecOptions = []string{arr.CodecX265, arr.CodecX264, arr.CodecAV1}
|
||||
hdrOptions = []string{"HDR", "DV", "SDR"}
|
||||
audioOptions = []string{arr.AudioAtmos, arr.AudioTrueHD, arr.AudioDTSX, arr.AudioDTSHD, arr.AudioDTS,
|
||||
arr.AudioDDPlus, arr.AudioDD, arr.AudioAAC, arr.AudioFLAC, arr.AudioOpus}
|
||||
)
|
||||
|
||||
func (f attrFilter) active() bool { return f != attrFilter{} }
|
||||
@@ -29,7 +31,7 @@ func (f attrFilter) active() bool { return f != attrFilter{} }
|
||||
// String lists the active criteria for the header, e.g. "1080p x265 DV".
|
||||
func (f attrFilter) String() string {
|
||||
var parts []string
|
||||
for _, p := range []string{f.res, f.codec, f.hdr, f.lang} {
|
||||
for _, p := range []string{f.res, f.codec, f.hdr, f.audio, f.lang} {
|
||||
if p != "" {
|
||||
parts = append(parts, p)
|
||||
}
|
||||
@@ -66,6 +68,9 @@ func (f attrFilter) matchFile(a arr.FileAttrs) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if f.audio != "" && !slices.Contains(a.Audio, f.audio) {
|
||||
return false
|
||||
}
|
||||
if f.lang != "" && !slices.ContainsFunc(a.Languages, func(l string) bool { return strings.EqualFold(l, f.lang) }) {
|
||||
return false
|
||||
}
|
||||
@@ -104,8 +109,10 @@ func indexOf(options []string, v string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// openAttrFilter shows the dialog to pick quality, codec, HDR and language.
|
||||
func (a *App) openAttrFilter(cur attrFilter, languages []string, apply func(attrFilter)) {
|
||||
// openAttrFilter shows the dialog to pick quality, codec, HDR, audio and
|
||||
// language. Every change is passed to set immediately so the list behind the
|
||||
// dialog follows along; Cancel and Esc restore cur.
|
||||
func (a *App) openAttrFilter(cur attrFilter, languages []string, set func(attrFilter)) {
|
||||
if cur.lang != "" && !slices.Contains(languages, cur.lang) {
|
||||
languages = append([]string{cur.lang}, languages...)
|
||||
}
|
||||
@@ -114,12 +121,14 @@ func (a *App) openAttrFilter(cur attrFilter, languages []string, apply func(attr
|
||||
lRes = "Quality"
|
||||
lCodec = "Codec"
|
||||
lHDR = "HDR"
|
||||
lAudio = "Audio"
|
||||
lLang = "Language"
|
||||
)
|
||||
form := tview.NewForm().
|
||||
AddDropDown(lRes, withAny(resOptions), indexOf(resOptions, cur.res), nil).
|
||||
AddDropDown(lCodec, withAny(codecOptions), indexOf(codecOptions, cur.codec), nil).
|
||||
AddDropDown(lHDR, withAny(hdrOptions), indexOf(hdrOptions, cur.hdr), nil).
|
||||
AddDropDown(lAudio, withAny(audioOptions), indexOf(audioOptions, cur.audio), nil).
|
||||
AddDropDown(lLang, withAny(languages), indexOf(languages, cur.lang), nil)
|
||||
|
||||
pick := func(label string, options []string) string {
|
||||
@@ -129,22 +138,31 @@ func (a *App) openAttrFilter(cur attrFilter, languages []string, apply func(attr
|
||||
}
|
||||
return options[i-1]
|
||||
}
|
||||
form.AddButton("Apply", func() {
|
||||
a.closeModal()
|
||||
apply(attrFilter{
|
||||
current := func() attrFilter {
|
||||
return attrFilter{
|
||||
res: pick(lRes, resOptions),
|
||||
codec: pick(lCodec, codecOptions),
|
||||
hdr: pick(lHDR, hdrOptions),
|
||||
audio: pick(lAudio, audioOptions),
|
||||
lang: pick(lLang, languages),
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
for _, label := range []string{lRes, lCodec, lHDR, lAudio, lLang} {
|
||||
form.GetFormItemByLabel(label).(*tview.DropDown).SetSelectedFunc(func(string, int) { set(current()) })
|
||||
}
|
||||
|
||||
cancel := func() {
|
||||
a.closeModal()
|
||||
set(cur)
|
||||
}
|
||||
form.AddButton("Apply", a.closeModal)
|
||||
form.AddButton("Reset", func() {
|
||||
a.closeModal()
|
||||
apply(attrFilter{})
|
||||
set(attrFilter{})
|
||||
})
|
||||
form.AddButton("Cancel", a.closeModal)
|
||||
form.SetCancelFunc(a.closeModal)
|
||||
form.AddButton("Cancel", cancel)
|
||||
form.SetCancelFunc(cancel)
|
||||
arrowNavigation(form)
|
||||
form.SetBorder(true).SetTitle(" Filter by properties ")
|
||||
a.openModal(form, 50, 13)
|
||||
a.openSidePanel(form, 40, 17, "↑↓ move · ←→ change (applies live) · Enter apply · Esc cancel")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user