Release list: filter by quality, codec, HDR, DV and language
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+19
-16
@@ -63,22 +63,12 @@ func (f MediaFile) Attrs() FileAttrs {
|
||||
}
|
||||
}
|
||||
|
||||
codec := f.MediaInfo.VideoCodec + " " + names
|
||||
switch {
|
||||
case re265.MatchString(f.MediaInfo.VideoCodec):
|
||||
a.Codec = CodecX265
|
||||
case re264.MatchString(f.MediaInfo.VideoCodec):
|
||||
a.Codec = CodecX264
|
||||
case reAV1.MatchString(f.MediaInfo.VideoCodec):
|
||||
a.Codec = CodecAV1
|
||||
case f.MediaInfo.VideoCodec != "":
|
||||
// A codec we do not offer as a filter (VC-1, MPEG-2...): do not guess from the name.
|
||||
case re265.MatchString(codec):
|
||||
a.Codec = CodecX265
|
||||
case re264.MatchString(codec):
|
||||
a.Codec = CodecX264
|
||||
case reAV1.MatchString(codec):
|
||||
a.Codec = CodecAV1
|
||||
if f.MediaInfo.VideoCodec != "" {
|
||||
// A codec we do not offer as a filter (VC-1, MPEG-2...) stays empty
|
||||
// rather than being guessed from the name.
|
||||
a.Codec = codecOf(f.MediaInfo.VideoCodec)
|
||||
} else {
|
||||
a.Codec = codecOf(names)
|
||||
}
|
||||
|
||||
dr := f.MediaInfo.VideoDynamicRangeType + " " + f.MediaInfo.VideoDynamicRange
|
||||
@@ -101,3 +91,16 @@ func atoi(s string) (n int) {
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// codecOf finds a codec we offer as a filter in free text ("x265", "H.264", "HEVC"...).
|
||||
func codecOf(s string) string {
|
||||
switch {
|
||||
case re265.MatchString(s):
|
||||
return CodecX265
|
||||
case re264.MatchString(s):
|
||||
return CodecX264
|
||||
case reAV1.MatchString(s):
|
||||
return CodecAV1
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -47,3 +47,27 @@ func TestAttrsVariants(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReleaseAttrs(t *testing.T) {
|
||||
var r Release
|
||||
raw := `{"title":"Dune.2021.2160p.UHD.BluRay.DV.HDR10.x265-GRP","quality":{"quality":{"name":"Bluray-2160p","resolution":2160}},
|
||||
"languages":[{"name":"English"}],"customFormats":[{"name":"HDR"}]}`
|
||||
if err := json.Unmarshal([]byte(raw), &r); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := FileAttrs{Resolution: 2160, Codec: CodecX265, HDR: true, DV: true, Languages: []string{"English"}}
|
||||
if got := r.Attrs(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("got %+v, want %+v", got, want)
|
||||
}
|
||||
|
||||
// Resolution from the title when the quality carries none; codec spelled H.264.
|
||||
r = Release{Title: "Show.S01E01.720p.WEB.H.264-GRP"}
|
||||
if got := r.Attrs(); got.Resolution != 720 || got.Codec != CodecX264 || got.HDR || got.DV {
|
||||
t.Errorf("got %+v", got)
|
||||
}
|
||||
// "HDTV" and "HDRip" are not HDR.
|
||||
r = Release{Title: "Show.S01E01.HDTV.x264-GRP"}
|
||||
if got := r.Attrs(); got.HDR || got.DV {
|
||||
t.Errorf("HDTV detected as HDR: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
+31
-1
@@ -27,12 +27,16 @@ type Release struct {
|
||||
FullSeason bool `json:"fullSeason"`
|
||||
Quality struct {
|
||||
Quality struct {
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name"`
|
||||
Resolution int `json:"resolution"`
|
||||
} `json:"quality"`
|
||||
} `json:"quality"`
|
||||
Languages []struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"languages"`
|
||||
CustomFormats []struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"customFormats"`
|
||||
}
|
||||
|
||||
// QualityName returns the release's quality, e.g. "Bluray-1080p".
|
||||
@@ -64,3 +68,29 @@ func (c *Client) Grab(ctx context.Context, r Release) error {
|
||||
body := map[string]any{"guid": r.GUID, "indexerId": r.IndexerID}
|
||||
return c.Do(ctx, http.MethodPost, "release", nil, body, nil)
|
||||
}
|
||||
|
||||
// Attrs derives the filterable properties from what the release announces:
|
||||
// its title, quality, custom formats and languages. Codec and HDR only show up
|
||||
// when the uploader put them into the title.
|
||||
func (r Release) Attrs() FileAttrs {
|
||||
names := []string{r.Title, r.Quality.Quality.Name}
|
||||
for _, cf := range r.CustomFormats {
|
||||
names = append(names, cf.Name)
|
||||
}
|
||||
text := strings.Join(names, " ")
|
||||
|
||||
a := FileAttrs{Resolution: r.Quality.Quality.Resolution, Codec: codecOf(text)}
|
||||
if a.Resolution == 0 {
|
||||
if m := reRes.FindStringSubmatch(text); m != nil {
|
||||
a.Resolution = atoi(m[1])
|
||||
}
|
||||
}
|
||||
a.DV = reDV.MatchString(text)
|
||||
a.HDR = reHDR.MatchString(text)
|
||||
for _, l := range r.Languages {
|
||||
if l.Name != "" {
|
||||
a.Languages = append(a.Languages, l.Name)
|
||||
}
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ const helpText = `[yellow]Global[-]
|
||||
Enter, g grab the selected release
|
||||
s cycle sort (best, size, age)
|
||||
f hide rejected releases
|
||||
F filter by quality, codec, HDR / DV, language (read from the
|
||||
release title, quality and custom formats)
|
||||
|
||||
[yellow]Downloads[-]
|
||||
p pause / resume the SABnzbd queue
|
||||
|
||||
@@ -145,6 +145,6 @@ func (a *App) openAttrFilter(cur attrFilter, languages []string, apply func(attr
|
||||
form.AddButton("Cancel", a.closeModal)
|
||||
form.SetCancelFunc(a.closeModal)
|
||||
arrowNavigation(form)
|
||||
form.SetBorder(true).SetTitle(" Filter by file properties ")
|
||||
form.SetBorder(true).SetTitle(" Filter by properties ")
|
||||
a.openModal(form, 50, 13)
|
||||
}
|
||||
|
||||
+32
-4
@@ -42,6 +42,7 @@ type releasesView struct {
|
||||
searched bool // the indexer search has finished
|
||||
sortMode int
|
||||
hideRejected bool
|
||||
attr attrFilter
|
||||
}
|
||||
|
||||
// openReleases starts an interactive search and shows the results as they arrive.
|
||||
@@ -71,6 +72,11 @@ func (a *App) openReleases(title string, fetch func(context.Context) ([]arr.Rele
|
||||
case ev.Key() == tcell.KeyRune && ev.Rune() == 's':
|
||||
v.sortMode = (v.sortMode + 1) % numSortModes
|
||||
v.render()
|
||||
case ev.Key() == tcell.KeyRune && ev.Rune() == 'F':
|
||||
v.app.openAttrFilter(v.attr, releaseLanguages(v.all), func(f attrFilter) {
|
||||
v.attr = f
|
||||
v.render()
|
||||
})
|
||||
case ev.Key() == tcell.KeyRune && ev.Rune() == 'f':
|
||||
v.hideRejected = !v.hideRejected
|
||||
v.render()
|
||||
@@ -83,7 +89,7 @@ func (a *App) openReleases(title string, fetch func(context.Context) ([]arr.Rele
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
||||
v.cancel = cancel
|
||||
v.render() // shows the "searching" placeholder
|
||||
a.openFull(v.root, "Enter/g grab · s sort · f hide rejected · Esc back", v.cancel)
|
||||
a.openFull(v.root, "Enter/g grab · s sort · f hide rejected · F filter · Esc back", v.cancel)
|
||||
|
||||
go func() {
|
||||
releases, err := fetch(ctx)
|
||||
@@ -125,7 +131,7 @@ func (v *releasesView) render() {
|
||||
if r, ok := v.selected(); ok {
|
||||
selGUID = r.GUID
|
||||
}
|
||||
v.shown = visibleReleases(v.all, v.hideRejected, v.sortMode)
|
||||
v.shown = visibleReleases(v.all, v.hideRejected, v.sortMode, v.attr)
|
||||
|
||||
v.table.Clear()
|
||||
for i, c := range []string{"", "Title", "Quality", "Size", "Age", "Indexer", "Score"} {
|
||||
@@ -158,7 +164,7 @@ func (v *releasesView) render() {
|
||||
case len(v.shown) == 0:
|
||||
msg := "No releases found. Are indexers configured?"
|
||||
if len(v.all) > 0 {
|
||||
msg = "All releases are hidden by the filter (f)"
|
||||
msg = "All releases are hidden by the filters (f, F)"
|
||||
}
|
||||
v.table.SetCell(1, 1, tview.NewTableCell("[gray]"+msg).SetSelectable(false))
|
||||
}
|
||||
@@ -187,6 +193,9 @@ func (v *releasesView) renderHeader() {
|
||||
if v.hideRejected {
|
||||
s += " · [yellow]rejected hidden[-]"
|
||||
}
|
||||
if v.attr.active() {
|
||||
s += " · [yellow]" + v.attr.String() + "[-]"
|
||||
}
|
||||
if v.torrents > 0 {
|
||||
s += fmt.Sprintf(" · [gray]%d torrent release%s hidden[-]", v.torrents, plural(v.torrents))
|
||||
}
|
||||
@@ -265,12 +274,15 @@ func (v *releasesView) doGrab(r arr.Release) {
|
||||
}
|
||||
|
||||
// visibleReleases applies the filter and sort order, returning a new slice.
|
||||
func visibleReleases(all []arr.Release, hideRejected bool, mode int) []arr.Release {
|
||||
func visibleReleases(all []arr.Release, hideRejected bool, mode int, af attrFilter) []arr.Release {
|
||||
out := make([]arr.Release, 0, len(all))
|
||||
for _, r := range all {
|
||||
if hideRejected && isRejected(r) {
|
||||
continue
|
||||
}
|
||||
if af.active() && !af.matchFile(r.Attrs()) {
|
||||
continue
|
||||
}
|
||||
out = append(out, r)
|
||||
}
|
||||
slices.SortStableFunc(out, func(a, b arr.Release) int {
|
||||
@@ -336,3 +348,19 @@ func formatReleaseAge(minutes float64) string {
|
||||
}
|
||||
return fmt.Sprintf("%dd", int(minutes/(24*60)))
|
||||
}
|
||||
|
||||
// releaseLanguages lists the languages the releases announce, sorted.
|
||||
func releaseLanguages(all []arr.Release) []string {
|
||||
seen := map[string]bool{}
|
||||
var out []string
|
||||
for _, r := range all {
|
||||
for _, l := range r.Attrs().Languages {
|
||||
if !seen[l] {
|
||||
seen[l] = true
|
||||
out = append(out, l)
|
||||
}
|
||||
}
|
||||
}
|
||||
slices.Sort(out)
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestVisibleReleasesSort(t *testing.T) {
|
||||
{"hide rejected", true, sortBest, []string{"ok-1080-score", "ok-1080", "ok-720"}},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
if got := guids(visibleReleases(all, tc.hide, tc.mode)); !equal(got, tc.want) {
|
||||
if got := guids(visibleReleases(all, tc.hide, tc.mode, attrFilter{})); !equal(got, tc.want) {
|
||||
t.Errorf("%s: got %v, want %v", tc.name, got, tc.want)
|
||||
}
|
||||
}
|
||||
@@ -108,3 +108,20 @@ func TestSummarizeSeasons(t *testing.T) {
|
||||
t.Error("seasonLabel")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVisibleReleasesAttrFilter(t *testing.T) {
|
||||
rel := func(guid, title string) arr.Release { return arr.Release{GUID: guid, Title: title} }
|
||||
all := []arr.Release{
|
||||
rel("a", "Movie.2160p.DV.x265-G"),
|
||||
rel("b", "Movie.1080p.x264-G"),
|
||||
rel("c", "Movie.1080p.x265-G"),
|
||||
}
|
||||
got := guids(visibleReleases(all, false, sortBest, attrFilter{res: "1080p", codec: "x265"}))
|
||||
if !equal(got, []string{"c"}) {
|
||||
t.Errorf("1080p x265 = %v", got)
|
||||
}
|
||||
got = guids(visibleReleases(all, false, sortBest, attrFilter{hdr: "DV"}))
|
||||
if !equal(got, []string{"a"}) {
|
||||
t.Errorf("DV = %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user