5rahim / seanime

Open-source media server for anime and manga.
https://seanime.rahim.app
MIT License
385 stars 29 forks source link

bug: Autodownloader removes season when matching `Comparison title`, cannot match Oshi no ko s2, erai-raws #134

Closed sin3point14 closed 2 weeks ago

sin3point14 commented 1 month ago

Checklist

Bug Severity

Usability is affected

Bug Area

Other

Bug Description / Steps to Reproduce

I have the following setting in autodownloader image But unfortunately it didn't download an episode. After digging into the code I figured out that this test reproduces the issue

diff --git a/internal/library/autodownloader/autodownloader_test.go b/internal/library/autodownloader/autodownloader_test.go
new file mode 100644
index 00000000..42d59d8f
--- /dev/null
+++ b/internal/library/autodownloader/autodownloader_test.go
@@ -0,0 +1,41 @@
+package autodownloader
+
+import (
+       "encoding/json"
+       "fmt"
+       "seanime/internal/api/anilist"
+       "seanime/internal/library/anime"
+       seanime_parser "seanime/seanime-parser"
+       "testing"
+
+       "github.com/stretchr/testify/assert"
+)
+
+func TestOshiNoKoS2(t *testing.T) {
+       ad := AutoDownloader{}
+       name1 := "[Oshi no Ko] 2nd Season"
+       name2 := "Oshi no Ko Season 2"
+       aniListEntry := anilist.MediaListEntry{
+               Media: &anilist.BaseAnime{
+                       Title: &anilist.BaseAnime_Title{
+                               Romaji: &name1,
+                       },
+                       Synonyms: []*string{&name2},
+               },
+       }
+
+       // fill comparisonTitle later
+       ruleJson := `{"dbId":3,"enabled":true,"mediaId":166531,"releaseGroups":["SubsPlease","Erai-raws"],"resolutions":["1080p"],"comparisonTitle":"","titleComparisonType":"likely","episodeType":"recent","destination":"/data/seanime/library/[Oshi no Ko] 2nd Season"}`
+       rule := anime.AutoDownloaderRule{}
+       err := json.Unmarshal([]byte(ruleJson), &rule)
+       assert.NoError(t, err)
+
+       rule.ComparisonTitle = "Oshi no Ko 2nd Season"
+
+       p := seanime_parser.Parse("[Erai-raws] Oshi no Ko 2nd Season - 11 [720p][Multiple Subtitle] [ENG][FRE]")
+       // json marshal p
+       jsonP, err := json.Marshal(p)
+       assert.NoError(t, err)
+       fmt.Printf("%s\n", string(jsonP))
+       assert.True(t, ad.isTitleMatch(p.Title, &rule, &aniListEntry))
+}

changing it to

diff --git a/internal/library/autodownloader/autodownloader_test.go b/internal/library/autodownloader/autodownloader_test.go
index 42d59d8f..5a07b696 100644
--- a/internal/library/autodownloader/autodownloader_test.go
+++ b/internal/library/autodownloader/autodownloader_test.go
@@ -30,7 +30,7 @@ func TestOshiNoKoS2(t *testing.T) {
        err := json.Unmarshal([]byte(ruleJson), &rule)
        assert.NoError(t, err)

-       rule.ComparisonTitle = "Oshi no Ko 2nd Season"
+       rule.ComparisonTitle = "Oshi no Ko"

        p := seanime_parser.Parse("[Erai-raws] Oshi no Ko 2nd Season - 11 [720p][Multiple Subtitle] [ENG][FRE]")
        // json marshal p

fixes the test. The reason probably is that seanime_parser.Parse("[Erai-raws] Oshi no Ko 2nd Season - 11 [720p][Multiple Subtitle] [ENG][FRE]") stores Oshi no Ko in Title field of seanime_parser.Metadata struct and stores "2" in SeasonNumber. However the anilist entry for this https://anilist.co/anime/166531 shows [Oshi no Ko] 2nd Season and Oshi no Ko Season 2, both contain the season, hence string matching fails. This is the torrent I hoped it would match https://animetosho.org/view/erai-raws-oshi-no-ko-2nd-season-11.n1875103

Expected Behavior

IMO Oshi no Ko 2nd Season should have matched since the torrent title contained that string.

Though using Oshi no ko instead of Oshi no ko 2nd Season isn't a dealbraker for me, things can get weird when a special air along with the main season. I think I've seen that happen several times like, recently, with Sousou no frieren https://anilist.co/anime/154587/Sousou-no-Frieren/ and https://anilist.co/anime/170068/Sousou-no-Frieren--no-Mahou/. Lets say if this was s2, Sousou no frieren could match both these shows and autodownloader may pick the wrong one. Though in frieren's case this wouldn't have happened since specials are 13 eps and main season was 28 eps, so main season ep count would always be ahead of specials. This may not be the case when frieren s2 drops.

I see several options here:

Screenshots

No response

Logs

I included a test, I think that should be enough for reproduction.

Debugging Checklist

App Version

v2.1.1

Operating System

Linux

5rahim commented 1 month ago

changing to Oshi no Ko somehow downloaded the correct ep from SubsPlease as well :O. That's like magic! I'm curious as to how you achieve this, if, you can explain!

The episode number is normalized if an absolute number is detected.

if listEntry.GetMedia().GetCurrentEpisodeCount() != -1 && episode > listEntry.GetMedia().GetCurrentEpisodeCount() {
  ad.mu.Lock()
  animeMetadata, err := ad.metadataProvider.GetAnimeMetadata(metadata.AnilistPlatform, listEntry.GetMedia().GetID())
  if err == nil && animeMetadata.GetOffset() > 0 {
    episode = episode - animeMetadata.GetOffset()
  }
  ad.mu.Unlock()
}
sin3point14 commented 1 month ago

Thanks for the answer, but I found another issue that is probably related to the previous one.

I tried to download konosuba s1, s2, s3 and i think a similar issue happened here. The library parser ended up assigning all eps of s1, s2 to s1 in library and episodes of s3 to s2 in library image

image

The s2 ep1 is also marked as s1 ep1 image

The s2 scan errors because s2 only has 10 eps and s3 has 11 eps, so it doesn't know what to assign s3 ep11 file to image

image

I will attach the full scan logs 2024-09-20_01-47-10-scan.log

I will manually resolve them for now but I have a gut feeling that it is probably due to the title matcher ignoring "season" again

5rahim commented 1 month ago

Btw thanks for the sponsor.

Here's an explanation: The library scanner does not ignore seasons. The code explicitly generates multiple variations containing seasons (e.g. Season 3, S3, 3rd season) when a season is parsed--which in this case, it was in all instances. You can see that, with the filename Kono ... Shukufuku S3 - 11.mkv, the matcher found a distance of 1 when comparing it with the media title Kono ... Shukufuku wo! 3 using Levenshtein. i.e., "S" was the only difference. The issue is that Sorensen-Dice was used as a final threshold and it picked the wrong season. The same thing happened with season 2 being matched to season 1.

The auto-downloader on the other hand behaves differently from the library scanner when comparing titles as it just compares 2 titles. The issue is, as you figured out, the parsed torrent title omits the season, which causes the comparison to fail because the distance is greater. ABC Season 2 as a comparison title will fail because ABC is shorter since Season 2 was omitted. Which is why removing Season 2 from the comparison title fixed it. This is a simple fix if like you said, the seasons are matched separately.