One self-hosted app for your shows, movies and music.
HolyArrs 1.0.5 (#173)
CoderLuii43fbe7b33cec
diff --git a/.github/readme/README.ar.md b/.github/readme/README.ar.mdindex df948e2..fc99052 100644--- a/.github/readme/README.ar.md+++ b/.github/readme/README.ar.md@@ -202,7 +202,7 @@ docker compose up -d| الوسم | استخدمه لـ || :----: | --- || `latest` | أحدث إصدار. |-| `1.0.4` | إصدار واحد بعينه. لا يتحرك أبدًا. |+| `1.0.5` | إصدار واحد بعينه. لا يتحرك أبدًا. |## الاستخدامdiff --git a/.github/readme/README.de.md b/.github/readme/README.de.mdindex 4d84e06..4f45157 100644--- a/.github/readme/README.de.md+++ b/.github/readme/README.de.md@@ -200,7 +200,7 @@ Die Images liegen auf Docker Hub als [`holyarrs/holyarrs`](https://hub.docker.co| Tag | Dafür nutzen || :----: | --- || `latest` | Die neueste Version. |-| `1.0.4` | Eine genaue Version. Sie ändert sich nie. |+| `1.0.5` | Eine genaue Version. Sie ändert sich nie. |## Verwendungdiff --git a/.github/readme/README.es.md b/.github/readme/README.es.mdindex e837c71..1e9cbab 100644--- a/.github/readme/README.es.md+++ b/.github/readme/README.es.md@@ -200,7 +200,7 @@ Las imágenes están en Docker Hub como [`holyarrs/holyarrs`](https://hub.docker| Etiqueta | Para qué sirve || :----: | --- || `latest` | La versión más reciente. |-| `1.0.4` | Una versión exacta. Nunca se mueve. |+| `1.0.5` | Una versión exacta. Nunca se mueve. |## Usodiff --git a/.github/readme/README.fr.md b/.github/readme/README.fr.mdindex 23fb20d..933530a 100644--- a/.github/readme/README.fr.md+++ b/.github/readme/README.fr.md@@ -200,7 +200,7 @@ Les images sont sur Docker Hub sous le nom [`holyarrs/holyarrs`](https://hub.doc| Étiquette | À utiliser pour || :----: | --- || `latest` | La version la plus récente. |-| `1.0.4` | Une version précise. Elle ne bouge jamais. |+| `1.0.5` | Une version précise. Elle ne bouge jamais. |## Utilisationdiff --git a/.github/readme/README.hi.md b/.github/readme/README.hi.mdindex e2f15c7..807d301 100644--- a/.github/readme/README.hi.md+++ b/.github/readme/README.hi.md@@ -200,7 +200,7 @@ NAS पर चला रहे हैं? देखिए [Unraid, Synology औ| टैग | किसके लिए || :----: | --- || `latest` | नवीनतम रिलीज़। |-| `1.0.4` | एक तय वर्ज़न। यह कभी नहीं बदलता। |+| `1.0.5` | एक तय वर्ज़न। यह कभी नहीं बदलता। |## इस्तेमालdiff --git a/.github/readme/README.ja.md b/.github/readme/README.ja.mdindex b0214f3..275531d 100644--- a/.github/readme/README.ja.md+++ b/.github/readme/README.ja.md@@ -200,7 +200,7 @@ NAS をお使いですか。[Unraid、Synology などの NAS](https://docs.HolyA| タグ | 用途 || :----: | --- || `latest` | 最新のリリース。 |-| `1.0.4` | 特定の1つのバージョンです。動くことはありません。 |+| `1.0.5` | 特定の1つのバージョンです。動くことはありません。 |## 使い方diff --git a/.github/readme/README.ko.md b/.github/readme/README.ko.mdindex fd7cb4b..541bda5 100644--- a/.github/readme/README.ko.md+++ b/.github/readme/README.ko.md@@ -200,7 +200,7 @@ NAS를 쓰세요? [Unraid, Synology 및 기타 NAS](https://docs.HolyArrs.com/ru| 태그 | 용도 || :----: | --- || `latest` | 최신 릴리스. |-| `1.0.4` | 정확히 한 버전이에요. 절대 움직이지 않아요. |+| `1.0.5` | 정확히 한 버전이에요. 절대 움직이지 않아요. |## 사용법diff --git a/.github/readme/README.pt-BR.md b/.github/readme/README.pt-BR.mdindex 339f5c2..342dba2 100644--- a/.github/readme/README.pt-BR.md+++ b/.github/readme/README.pt-BR.md@@ -200,7 +200,7 @@ As imagens ficam no Docker Hub como [`holyarrs/holyarrs`](https://hub.docker.com| Tag | Use para || :----: | --- || `latest` | A versão mais recente. |-| `1.0.4` | Uma versão exata. Nunca muda. |+| `1.0.5` | Uma versão exata. Nunca muda. |## Usodiff --git a/.github/readme/README.ru.md b/.github/readme/README.ru.mdindex b24931d..317f3b7 100644--- a/.github/readme/README.ru.md+++ b/.github/readme/README.ru.md@@ -200,7 +200,7 @@ HolyArrs только читает ваши старые приложения и| Тег | Для чего || :----: | --- || `latest` | Самая новая версия. |-| `1.0.4` | Одна точная версия. Никогда не сдвигается. |+| `1.0.5` | Одна точная версия. Никогда не сдвигается. |## Использованиеdiff --git a/.github/readme/README.zh-CN.md b/.github/readme/README.zh-CN.mdindex ffba734..ead6889 100644--- a/.github/readme/README.zh-CN.md+++ b/.github/readme/README.zh-CN.md@@ -200,7 +200,7 @@ HolyArrs 只读取你的旧应用,不会改动它们里面的任何东西,| 标签 | 用途 || :----: | --- || `latest` | 最新版本。 |-| `1.0.4` | 固定的某一个版本,永远不会变。 |+| `1.0.5` | 固定的某一个版本,永远不会变。 |## 用法diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 79514cd..f226c91 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,15 @@All notable changes to HolyArrs are listed here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow [Semantic Versioning](https://semver.org/).+## 1.0.5++### Fixed++- Movies moved over from Radarr keep their real quality: `WEBDL-1080p` and `Bluray-720p` names are read right. ([#171](https://github.com/HolyArrs/HolyArrs/issues/171))+- Words in titles, like "Charlotte's Web" or "Cam", are no longer read as quality. ([#171](https://github.com/HolyArrs/HolyArrs/issues/171))+- Episodes moved over from Sonarr with no quality in their names are judged by the file's own resolution, so they stop asking for a better copy. ([#171](https://github.com/HolyArrs/HolyArrs/issues/171))+- Libraries moved over before this version are checked again once after the update. ([#171](https://github.com/HolyArrs/HolyArrs/issues/171))+## 1.0.4### Changeddiff --git a/README.md b/README.mdindex bf96342..27fad46 100644--- a/README.md+++ b/README.md@@ -200,7 +200,7 @@ Images live on Docker Hub as [`holyarrs/holyarrs`](https://hub.docker.com/r/holy| Tag | Use it for || :----: | --- || `latest` | The newest release. |-| `1.0.4` | One exact version. It never moves. |+| `1.0.5` | One exact version. It never moves. |## Usagediff --git a/VERSION b/VERSIONindex ee90284..90a27f9 100644--- a/VERSION+++ b/VERSION@@ -1 +1 @@-1.0.4+1.0.5diff --git a/app/backend/cmd/holyarrs/main.go b/app/backend/cmd/holyarrs/main.goindex 5327a68..e027bc7 100644--- a/app/backend/cmd/holyarrs/main.go+++ b/app/backend/cmd/holyarrs/main.go@@ -478,6 +478,13 @@ func serve(ctx context.Context, c config, o runOpts) error {if n, err := lib.HealServerPlaceholders(ctx); err != nil || n > 0 {log.Printf("artwork: %d placeholder pictures removed, error %v", n, err)}+ // Once per install, in the background: files moved over from the old apps+ // get their quality read again, so good copies stop asking for a better one.+ go func() {+ if _, err := lib.RejudgeAdopted(ctx); err != nil {+ log.Printf("library: reading moved-over quality again: %v", err)+ }+ }()// Artists still without a picture get one soon after start, apart from// the slower MusicBrainz refresh.if _, _, err := q.Enqueue(ctx, library.KindArtistPictures, nil, map[string]any{"startup": true}, library.KindArtistPictures, domain.System); err != nil {diff --git a/app/backend/internal/core/releasename/oldapp_names_test.go b/app/backend/internal/core/releasename/oldapp_names_test.gonew file mode 100644index 0000000..c7d6e9d--- /dev/null+++ b/app/backend/internal/core/releasename/oldapp_names_test.go@@ -0,0 +1,39 @@+package releasename++import "testing"++// Library files named by the old apps: their quality word ("WEBDL-1080p")+// is quality, not a group; title words before a bracketed year and episode+// titles after " - " are never read as tags.+func TestOldAppLibraryNames(t *testing.T) {+ for _, c := range []struct {+ name string+ show bool+ res int+ source string+ group string+ }{+ {"The Matrix (1999) WEBDL-1080p", false, 1080, "web_dl", ""},+ {"The Matrix (1999) WEBDL-720p", false, 720, "web_dl", ""},+ {"The Matrix (1999) WEBRip-2160p", false, 2160, "web_rip", ""},+ {"The Matrix (1999) Bluray-720p", false, 720, "bluray", ""},+ {"The Matrix (1999) Remux-2160p", false, 2160, "remux", ""},+ {"The Matrix (1999) Bluray-1080p Proper", false, 1080, "bluray", ""},+ {"The Matrix (1999) HDTV-720p", false, 720, "tv", ""},+ {"Charlotte's Web (1973) Bluray-1080p", false, 1080, "bluray", ""},+ {"Cam (2018) WEBRip-1080p", false, 1080, "web_rip", ""},+ {"Gossip Girl - S01E03 - Charlotte's Web", true, 0, "", ""},+ {"Show - S01E05 - Cam Girl", true, 0, "", ""},+ {"Show - S01E02 - Title WEBDL-1080p", true, 1080, "web_dl", ""},+ {"Show (2018) - S01E02 - Title HDTV-720p", true, 720, "tv", ""},+ // Scene names keep reading as before.+ {"Show.S01E02.1080p.WEB-DL.DDP5.1.H.264-NTb", true, 1080, "web_dl", "NTb"},+ {"Movie.2020.1080p.BluRay.x264-SPARKS", false, 1080, "bluray", "SPARKS"},+ {"Movie.2020.720p.WEB-DL.DD5.1.H264-FGT", false, 720, "web_dl", "FGT"},+ } {+ r := Parse(c.name, Hints{Show: c.show})+ if r.Resolution.Value != c.res || r.Source.Value != c.source || r.Group.Value != c.group {+ t.Errorf("%q: got resolution %d, source %q, group %q; want %d, %q, %q", c.name, r.Resolution.Value, r.Source.Value, r.Group.Value, c.res, c.source, c.group)+ }+ }+}diff --git a/app/backend/internal/core/releasename/parse.go b/app/backend/internal/core/releasename/parse.goindex 0b4c2b3..ed13c54 100644--- a/app/backend/internal/core/releasename/parse.go+++ b/app/backend/internal/core/releasename/parse.go@@ -39,6 +39,7 @@ var (reLeadBrack = regexp.MustCompile(`^\[([^\[\]]+)\]\s*`) // a group name may hold spaces: [Lab Fansub]reResWord = regexp.MustCompile(`^(480|576|720|1080|2160)[pi]$`)reYear = regexp.MustCompile(`^(19|20)\d\d$`)+ reParenYear = regexp.MustCompile(`\s\((19|20)\d\d\)(\s|$)`)reChannels = regexp.MustCompile(`(?:^|[^0-9])([1-9]) ([01])(?:$|[^0-9])`)reH26x = regexp.MustCompile(`\b[hx] ?26([45])\b`)reFix = regexp.MustCompile(`^(proper|repack|rerip)(\d)?$`)@@ -247,7 +248,9 @@ func Parse(name string, h Hints) Result {for _, t := range after[1:] {allTags = allTags && isTag(t)}- if !compound && allTags && after[0] != "" {+ // "WEBDL-1080p", the old apps' quality word at the end of a Library+ // file name: the part after the hyphen is a tag, not a group.+ if !compound && allTags && after[0] != "" && !isTag(after[0]) {r.Group = sure(after[0])trailing = after[1:]s = s[:i]@@ -288,12 +291,20 @@ func Parse(name string, h Hints) Result {toks := reSeparators.Split(strings.TrimSpace(s), -1)toks = slices.DeleteFunc(toks, func(t string) bool { return t == "" })- toks = append(toks, trailing...)+ toks = append(splitTagPairs(toks), trailing...)- // Anchor: the first tag, and the last year before it.+ // Anchor: the first tag, and the last year before it. A year in+ // brackets, as the old apps name Library folders and files+ // ("Charlotte's Web (1973) Bluray-1080p"), ends the title, so title+ // words before it are never read as tags.+ titleUpTo := 0+ if m := reParenYear.FindStringIndex(s); m != nil {+ pre := reSeparators.Split(strings.TrimSpace(s[:m[0]]), -1)+ titleUpTo = len(slices.DeleteFunc(pre, func(t string) bool { return t == "" }))+ }first := len(toks)for i, t := range toks {- if i > 0 && isTag(t) {+ if i > titleUpTo && isTag(t) {first = ibreak}@@ -377,6 +388,29 @@ func setOf(words ...string) map[string]bool {return m}+// splitTagPairs splits a word like "WEBDL-1080p" or "Bluray-720p" (the+// old apps' quality word) into its two tags; other words stay as they are.+func splitTagPairs(toks []string) []string {+ out := make([]string, 0, len(toks))+ for _, t := range toks {+ if a, b, ok := strings.Cut(t, "-"); ok && a != "" && b != "" && !tagWords[strings.ToLower(t)] && (isTag(a) || isOldAppSource(a)) && isTag(b) {+ out = append(out, a, b)+ continue+ }+ out = append(out, t)+ }+ return out+}++// isOldAppSource is a source word only the old apps' quality names use.+func isOldAppSource(tok string) bool {+ switch strings.ToLower(tok) {+ case "webdl", "bluray", "remux", "hdtv", "sdtv", "webrip":+ return true+ }+ return false+}+func isTag(tok string) bool {t := strings.ToLower(tok)if tagWords[t] || reResWord.MatchString(t) || reDDP.MatchString(t) || reFix.MatchString(t) {diff --git a/app/backend/internal/core/releasename/show.go b/app/backend/internal/core/releasename/show.goindex 9438be6..e9f754c 100644--- a/app/backend/internal/core/releasename/show.go+++ b/app/backend/internal/core/releasename/show.go@@ -188,7 +188,13 @@ func parseShow(r *Result, h showHit, pre, post string, trailing []string, animetitle = m[2] + " " + m[1]}r.Title = sure(title)- tags := reSeparators.Split(strings.TrimSpace(post), -1)+ // " - Episode Title" after the episode number is how the old apps name+ // Library files. Its words are the episode's title ("Charlotte's Web",+ // "TS-19"), not tags, unless a resolution says the name ends in quality.+ if strings.HasPrefix(post, " - ") && !slices.ContainsFunc(splitTagPairs(reSeparators.Split(post, -1)), func(t string) bool { return reResWord.MatchString(strings.ToLower(t)) }) {+ post = ""+ }+ tags := splitTagPairs(reSeparators.Split(strings.TrimSpace(post), -1))tags = slices.DeleteFunc(tags, func(t string) bool { return t == "" || t == "-" })tags = append(tags, trailing...)readTags(r, tags, flags, hints)diff --git a/app/backend/internal/library/edit.go b/app/backend/internal/library/edit.goindex 3df909e..97403da 100644--- a/app/backend/internal/library/edit.go+++ b/app/backend/internal/library/edit.go@@ -239,7 +239,7 @@ func goodEnoughTx(ctx context.Context, tx *sql.Tx, v mediafiles.Version, keep boif f.ReleaseName != nil && *f.ReleaseName != "" {name = *f.ReleaseName}- ge := mediafiles.ReachesGoodEnough(name, pr.Body) && fileMeetsVersionChoices(v, f)+ ge := mediafiles.OwnedReachesGoodEnough(name, f.MediaInfo, pr.Body) && fileMeetsVersionChoices(v, f)to := sl.Stateswitch {case sl.State == mediafiles.SlotInLibrary && !ge && keep && v.KeepUpToDate:diff --git a/app/backend/internal/library/library.go b/app/backend/internal/library/library.goindex 173e491..af0bd4b 100644--- a/app/backend/internal/library/library.go+++ b/app/backend/internal/library/library.go@@ -396,7 +396,8 @@ func SortName(n string) string {func adoptFile(ctx context.Context, tx *sql.Tx, a Adoption, slotID, versionID, pickRulesID int64, keep bool, now time.Time, by domain.Actor) error {ext := path.Ext(a.File)release := strings.TrimSuffix(path.Base(a.File), ext)- p := releasename.Parse(release, releasename.Hints{Size: a.Size})+ judge := mediafiles.JudgeName(release, a.MediaInfo)+ p := releasename.Parse(judge, releasename.Hints{Size: a.Size})f := &mediafiles.File{SlotIDs: []int64{slotID}, VersionID: versionID, RelativePath: a.File, Size: a.Size, AddedAt: now,Quality: mediafiles.Quality{Resolution: p.Resolution.Value, Source: p.Source.Value, Codec: p.Codec.Value, HDR: p.HDR.Value},Languages: InspectedLanguages(a.MediaInfo), MediaInfo: map[string]any{"step": mediafiles.StepFor(p)}, ReleaseName: &release, Origin: "adopted",@@ -418,7 +419,7 @@ func adoptFile(ctx context.Context, tx *sql.Tx, a Adoption, slotID, versionID, pif err := database.Get(ctx, tx, "pick_rules", pickRulesID, &pr); err != nil {return err}- ge := mediafiles.ReachesGoodEnough(release, pr.Body)+ ge := mediafiles.OwnedReachesGoodEnough(release, a.MediaInfo, pr.Body)if _, err := tx.Exec("UPDATE slots SET file_id = ?, good_enough = ? WHERE id = ?", fileID, ge, slotID); err != nil {return err}diff --git a/app/backend/internal/library/rejudge.go b/app/backend/internal/library/rejudge.gonew file mode 100644index 0000000..8a66c29--- /dev/null+++ b/app/backend/internal/library/rejudge.go@@ -0,0 +1,94 @@+package library++import (+ "context"+ "database/sql"+ "log"+ "time"++ "github.com/HolyArrs/holyarrs/app/backend/internal/core/database"+ domain "github.com/HolyArrs/holyarrs/app/backend/internal/core/model"+ "github.com/HolyArrs/holyarrs/app/backend/internal/core/releasename"+ "github.com/HolyArrs/holyarrs/app/backend/internal/mediafiles"+)++const rejudgedSetting = "adopted_quality_rejudged"++// RejudgeAdopted runs once per install. Files moved over from the old apps+// were judged by a name reader that took "WEBDL-1080p" for a release group+// and ignored the resolution the file inspection read, so many good copies+// were marked "better copy wanted". It reads each adopted file's quality+// again and lets each Version's Slots swap to match. It returns how many+// Slots changed.+func (s *Service) RejudgeAdopted(ctx context.Context) (int, error) {+ if database.SettingOr(ctx, s.Store.Read(), "this_app", rejudgedSetting, "") != "" {+ return 0, nil+ }+ versionIDs, err := mediafiles.AdoptedVersionIDs(ctx, s.Store.Read())+ if err != nil {+ return 0, err+ }+ by := domain.System+ changed := 0+ // Small writes, so the app stays responsive on a large Library.+ for start := 0; start < len(versionIDs); start += 50 {+ batch := versionIDs[start:min(start+50, len(versionIDs))]+ err := s.Store.Write(ctx, func(tx *sql.Tx) error {+ for _, id := range batch {+ n, err := rejudgeVersionTx(ctx, tx, id, by)+ if err != nil {+ return err+ }+ changed += n+ }+ return nil+ })+ if err != nil {+ return changed, err+ }+ }+ err = s.Store.Write(ctx, func(tx *sql.Tx) error {+ return database.PutSetting(tx, "this_app", rejudgedSetting, time.Now().UTC().Format(time.RFC3339), by, time.Now())+ })+ if changed > 0 {+ log.Printf("library: read the quality of moved-over files again; %d slots changed", changed)+ }+ return changed, err+}++// rejudgeVersionTx stores the quality read again from each adopted file of+// a Version, then swaps its Slots' states to match.+func rejudgeVersionTx(ctx context.Context, tx *sql.Tx, versionID int64, by domain.Actor) (int, error) {+ var v mediafiles.Version+ if err := database.Get(ctx, tx, "versions", versionID, &v); err != nil {+ return 0, nil+ }+ var t mediafiles.Title+ if err := database.Get(ctx, tx, "titles", v.TitleID, &t); err != nil {+ return 0, nil+ }+ files, err := database.Select[mediafiles.File](ctx, tx, "files", "version_id = ?", versionID)+ if err != nil {+ return 0, err+ }+ for _, f := range files {+ if f.Origin != "adopted" || f.State != "present" || f.ReleaseName == nil || *f.ReleaseName == "" {+ continue+ }+ p := releasename.Parse(mediafiles.JudgeName(*f.ReleaseName, f.MediaInfo), releasename.Hints{Size: f.Size, Show: t.Kind == "show"})+ q := mediafiles.Quality{Resolution: p.Resolution.Value, Source: p.Source.Value, Codec: p.Codec.Value, HDR: p.HDR.Value, Audio: f.Quality.Audio}+ if q.Resolution == f.Quality.Resolution && q.Source == f.Quality.Source && q.Codec == f.Quality.Codec {+ continue+ }+ f.Quality = q+ if f.MediaInfo == nil {+ f.MediaInfo = map[string]any{}+ }+ f.MediaInfo["step"] = mediafiles.StepFor(p)+ if err := database.Update(tx, "files", &f, by); err != nil {+ return 0, err+ }+ }+ ch, err := goodEnoughTx(ctx, tx, v, t.KeepUpToDate && v.KeepUpToDate, by)+ return len(ch), err+}diff --git a/app/backend/internal/mediafiles/judge_name.go b/app/backend/internal/mediafiles/judge_name.gonew file mode 100644index 0000000..20da6ec--- /dev/null+++ b/app/backend/internal/mediafiles/judge_name.go@@ -0,0 +1,58 @@+package mediafiles++import (+ "regexp"+ "strings"++ "github.com/HolyArrs/holyarrs/app/backend/internal/core/releasename"+)++var inspectedRes = regexp.MustCompile(`^\d{3,4}p$`)++// JudgeName is the name a File's quality is judged by: its release name,+// plus the resolution the file inspection read when the name gives none.+// Files moved over from the old apps are often named without quality+// ("Show - S01E02 - Title"); without this they always looked below good+// enough and a better copy was sought for each.+func JudgeName(name string, mediaInfo map[string]any) string {+ r, _ := mediaInfo["resolution"].(string)+ if !inspectedRes.MatchString(r) || releasename.Parse(name, releasename.Hints{}).Resolution.Value > 0 {+ return name+ }+ return name + " " + r+}++// OwnedReachesGoodEnough is ReachesGoodEnough for a file already in the+// Library. It reads the name with the inspected resolution (JudgeName). A+// file whose name says nothing about its source (web, Blu-ray, TV), as the+// old apps name episodes, gets the benefit of the doubt: it counts as good+// enough when its resolution reaches the good-enough step's, so moving a+// Library over never asks for a better copy of every file.+func OwnedReachesGoodEnough(name string, mediaInfo map[string]any, rules PickRulesBody) bool {+ judge := JudgeName(name, mediaInfo)+ if ReachesGoodEnough(judge, rules) {+ return true+ }+ p := releasename.Parse(judge, hintsFor(rules))+ if p.Music != nil || p.Source.Value != "" || p.Resolution.Value == 0 {+ return false+ }+ need := stepResolution(rules.GoodEnoughAt)+ return need > 0 && p.Resolution.Value >= need+}++// stepResolution is the resolution a video ladder step stands for+// ("1080p_web" is 1080; the SD steps are 480), 0 when it has none.+func stepResolution(step string) int {+ switch {+ case strings.HasPrefix(step, "2160p"):+ return 2160+ case strings.HasPrefix(step, "1080p"):+ return 1080+ case strings.HasPrefix(step, "720p"):+ return 720+ case strings.HasPrefix(step, "sd_"):+ return 480+ }+ return 0+}diff --git a/app/backend/internal/mediafiles/judge_name_test.go b/app/backend/internal/mediafiles/judge_name_test.gonew file mode 100644index 0000000..1ac687b--- /dev/null+++ b/app/backend/internal/mediafiles/judge_name_test.go@@ -0,0 +1,37 @@+package mediafiles++import "testing"++func TestJudgeNameAddsInspectedResolution(t *testing.T) {+ info := map[string]any{"resolution": "1080p"}+ if got := JudgeName("The Rookie - S01E02 - Title", info); got != "The Rookie - S01E02 - Title 1080p" {+ t.Fatalf("no resolution in the name: got %q", got)+ }+ if got := JudgeName("The Matrix (1999) Bluray-720p", info); got != "The Matrix (1999) Bluray-720p" {+ t.Fatalf("the name's own resolution wins: got %q", got)+ }+ if got := JudgeName("Show - S01E02 - Title", nil); got != "Show - S01E02 - Title" {+ t.Fatalf("no inspection: got %q", got)+ }+ if got := JudgeName("Show - S01E02 - Title", map[string]any{"resolution": "odd"}); got != "Show - S01E02 - Title" {+ t.Fatalf("odd inspection value: got %q", got)+ }+}++func TestOwnedFileWithoutSourceGetsTheBenefitOfTheDoubt(t *testing.T) {+ rules := GoodEveryday()+ at1080 := map[string]any{"resolution": "1080p"}+ at720 := map[string]any{"resolution": "720p"}+ if !OwnedReachesGoodEnough("The Rookie - S01E02 - Crash Course", at1080, rules) {+ t.Fatal("a 1080p episode with no source in its name should count as good enough")+ }+ if OwnedReachesGoodEnough("The Rookie - S01E02 - Crash Course", at720, rules) {+ t.Fatal("a 720p episode is below a 1080p good-enough step")+ }+ if OwnedReachesGoodEnough("The Matrix (1999) HDTV-1080p", at1080, rules) {+ t.Fatal("a file whose name names its source is judged as named")+ }+ if !OwnedReachesGoodEnough("The Matrix (1999) WEBDL-1080p", at1080, rules) {+ t.Fatal("a named web 1080p file reaches good enough")+ }+}diff --git a/app/backend/internal/mediafiles/store_adopted.go b/app/backend/internal/mediafiles/store_adopted.gonew file mode 100644index 0000000..15432d0--- /dev/null+++ b/app/backend/internal/mediafiles/store_adopted.go@@ -0,0 +1,26 @@+package mediafiles++import (+ "context"++ "github.com/HolyArrs/holyarrs/app/backend/internal/core/database"+)++// AdoptedVersionIDs lists the Versions that hold at least one present File+// moved over from another app or adopted from disk.+func AdoptedVersionIDs(ctx context.Context, q database.Lister) ([]int64, error) {+ rows, err := q.QueryContext(ctx, "SELECT DISTINCT version_id FROM files WHERE origin = 'adopted' AND state = 'present'")+ if err != nil {+ return nil, err+ }+ defer rows.Close()+ var ids []int64+ for rows.Next() {+ var id int64+ if err := rows.Scan(&id); err != nil {+ return nil, err+ }+ ids = append(ids, id)+ }+ return ids, rows.Err()+}diff --git a/app/backend/internal/shows/adopt.go b/app/backend/internal/shows/adopt.goindex 18e0aa1..bff765b 100644--- a/app/backend/internal/shows/adopt.go+++ b/app/backend/internal/shows/adopt.go@@ -321,6 +321,11 @@ func adoptEpisodesTx(ctx context.Context, tx *sql.Tx, titleID, versionID, pickRuif inspected, ok := library.InspectLibraryVideo(a.LibraryPath, af.Path, info, false); ok {info = inspected}+ judge := mediafiles.JudgeName(release, info)+ if judge != release {+ p = releasename.Parse(judge, releasename.Hints{Size: af.Size, Show: true})+ info["step"] = mediafiles.StepFor(p)+ }f := &mediafiles.File{SlotIDs: slotIDs, VersionID: versionID, RelativePath: af.Path, Size: af.Size, AddedAt: now,Quality: mediafiles.Quality{Resolution: p.Resolution.Value, Source: p.Source.Value, Codec: p.Codec.Value, HDR: p.HDR.Value},Languages: library.InspectedLanguages(info), MediaInfo: info, ReleaseName: &release, Origin: "adopted",@@ -335,7 +340,7 @@ func adoptEpisodesTx(ctx context.Context, tx *sql.Tx, titleID, versionID, pickRuif err != nil {return err}- ge := mediafiles.ReachesGoodEnough(release, pr.Body)+ ge := mediafiles.OwnedReachesGoodEnough(release, info, pr.Body)state, why := mediafiles.SlotInLibrary, "adopted from "+a.FolderNameif !ge && keep {state, why = mediafiles.SlotBetterWanted, "adopted below good enough, so a better copy is sought"diff --git a/app/backend/internal/sources/search_shows.go b/app/backend/internal/sources/search_shows.goindex 9e9d490..ef391b6 100644--- a/app/backend/internal/sources/search_shows.go+++ b/app/backend/internal/sources/search_shows.go@@ -92,7 +92,7 @@ func currentOf(ctx context.Context, db *sql.DB, sl mediafiles.Slot, pr mediafileif f.ReleaseName != nil && *f.ReleaseName != "" {name = *f.ReleaseName}- if cur := mediafiles.CurrentOf(name, f.AddedAt, pr.Body); cur.Step != "" {+ if cur := mediafiles.CurrentOf(mediafiles.JudgeName(name, f.MediaInfo), f.AddedAt, pr.Body); cur.Step != "" {return &cur}if mediafiles.IsMusicRules(pr.Body) {