package wareztb import ( "testing" "git.0x0001f346.de/andreas/utils" ) func TestGetComparableWarezString(t *testing.T) { data := map[string]string{ "8.Mile.2002.German.DL.1080p.BluRay.x264-DEFUSED.mkv": "8.mile.2002", "Krieg.der.Welten.2005.German.DL.1080p.BluRay.x264.iNTERNAL-VideoStar.mkv": "krieg.der.welten.2005", "28.Weeks.Later.2007.German.DTS.DL.1080p.BluRay.x264-c0nFuSed.mkv": "28.weeks.later.2007", "Aliens.3.1992.Special.Edition.GERMAN.DL.DTS.1080p.BluRay.x264-MOViESTARS.mkv": "aliens.3.1992", "Die.Frau.Im.Nebel.2023.German.1080p.BluRay.x264-DSFM.mkv": "die.frau.im.nebel.2023", "Stargate: Kommando SG-1 (1997)": "stargate.kommando.sg-1.1997", "Severance (2022)": "severance.2022", "Little Britain (2003)": "little.britain.2003", "Sons of Anarchy (2008)": "sons.of.anarchy.2008", "Love, Death & Robots (2019)": "love.death.robots.2019", "...Jahr 2022... die überleben wollen... (1973)": "jahr.2022.die.ueberleben.wollen.1973", } for d, expectedResult := range data { result, _ := GetComparableWarezString(d) if result != expectedResult { t.Errorf("\ngot: %q\nwanted: %q\nfor: %q", result, expectedResult, d) } } } func TestGetTitleAndYearFromWarezString(t *testing.T) { type tResult struct { Filename string Title string Year int64 } data := []tResult{ { Filename: "John.Wick.Kapitel.4.2023.mkv", Title: "John.Wick.Kapitel.4", Year: 2023, }, { Filename: "The.Boogeyman.2023.German.DL.1080p.WEB.h264-JAJA.mkv", Title: "The.Boogeyman", Year: 2023, }, { Filename: "Black.Panther.2018.German.DL.720p.BluRay.x264-COiNCiDENCE.mkv", Title: "Black.Panther", Year: 2018, }, { Filename: "Sharknado.2.2014.German.DL.1080p.BluRay.x264-FRACTAL.mkv", Title: "Sharknado.2", Year: 2014, }, { Filename: "Armee.der.Finsternis.1992.GERMAN.AAC.1080p.BluRay.x265-w00t.mkv", Title: "Armee.der.Finsternis", Year: 1992, }, { Filename: "Flucht.von.Alcatraz.1979.German.1080p.WEB.H264.iNTERNAL-SunDry.mkv", Title: "Flucht.von.Alcatraz", Year: 1979, }, { Filename: "Departed.Unter.Feinden.2006.GERMAN.AC3.1080p.BluRay.x265-w00t.mkv", Title: "Departed.Unter.Feinden", Year: 2006, }, { Filename: "Sieben (1995).mkv", Title: "Sieben", Year: 1995, }, { Filename: "Forrest Gump (1994).mkv", Title: "Forrest.Gump", Year: 1994, }, { Filename: "Inception (2010).mkv", Title: "Inception", Year: 2010, }, { Filename: "Fight Club (1999).mkv", Title: "Fight.Club", Year: 1999, }, { Filename: "Chihiros Reise ins Zauberland (2001).avi", Title: "Chihiros.Reise.ins.Zauberland", Year: 2001, }, { Filename: "Human Centipede - Der menschliche Tausendfüßler (2009).avi", Title: "Human.Centipede.Der.menschliche.Tausendfuessler", Year: 2009, }, } for _, d := range data { resultTitle, resultYear, _ := GetTitleAndYearFromWarezString(d.Filename) if resultTitle != d.Title || resultYear != d.Year { t.Errorf("\ngot: %+v\nwanted: %+v\nfor: %q", tResult{Filename: d.Filename, Title: resultTitle, Year: resultYear}, d, d.Filename) } } } func TestGetTitleFromWarezString(t *testing.T) { data := map[string]string{ "Der.Super.Mario.Bros.Film.2023.GERMAN.DL.2160P.UHD.BLURAY.X265-WATCHABLE.mkv": "Der.Super.Mario.Bros.Film", "Top.Gun.Maverick.2022.German.DL.HDR.2160p.WEB.h265-W4K.mkv": "Top.Gun.Maverick", "Rot.2022.German.DL.1080p.BluRay.x265-PaTrol.mkv": "Rot", "Superbad.2007.German.EAC3D.DL.2160p.WebHD.h265.iNTERNAL-iNNOVATiV.mkv": "Superbad", "Matrix.1999.Remastered.German.AC3.1080p.BluRay.x265-GTF.mkv": "Matrix", "Mark.of.the.Vampire.1935.1080p.BluRay.x264-USURY.mkv": "Mark.of.the.Vampire", "1984.1984.German.DL.1080p.BluRay.AVC-SAViOURHD.mkv": "1984", "1917.2020.German.DL.2160p.UHD.BluRay.HEVC-HOVAC.mkv": "1917", "Meine Frau, die Spartaner und ich (2008).avi": "Meine.Frau.die.Spartaner.und.ich", "Bang Boom Bang - Ein todsicheres Ding (1999).avi": "Bang.Boom.Bang.Ein.todsicheres.Ding", "Titane (2021).mkv": "Titane", "Der Glöckner von Notre Dame (1996).mpeg": "Der.Gloeckner.von.Notre.Dame", "Tremors - Im Land der Raketenwürmer (1990).avi": "Tremors.Im.Land.der.Raketenwuermer", "John Wick: Kapitel 4 (2023).mkv": "John.Wick.Kapitel.4", } for d, expectedResult := range data { sanitized := SanitizeStringForWarezUsage(d) year, err := getYearFromWarezString(sanitized) if err != nil { continue } result, _ := getTitleFromWarezString(sanitized, year) if result != expectedResult { t.Errorf("\ngot: %s\nwanted: %s\nfor: %q", result, expectedResult, d) } } } func TestGetYearFromWarezString(t *testing.T) { data := map[string]int64{ "Der.Super.Mario.Bros.Film.2023.GERMAN.DL.2160P.UHD.BLURAY.X265-WATCHABLE.mkv": 2023, "Top.Gun.Maverick.2022.German.DL.HDR.2160p.WEB.h265-W4K.mkv": 2022, "Rot.2022.German.DL.1080p.BluRay.x265-PaTrol.mkv": 2022, "Superbad.2007.German.EAC3D.DL.2160p.WebHD.h265.iNTERNAL-iNNOVATiV.mkv": 2007, "Matrix.1999.Remastered.German.AC3.1080p.BluRay.x265-GTF.mkv": 1999, "Mark.of.the.Vampire.1935.1080p.BluRay.x264-USURY.mkv": 1935, "1984.1984.German.DL.1080p.BluRay.AVC-SAViOURHD.mkv": 1984, "1917.2020.German.DL.2160p.UHD.BluRay.HEVC-HOVAC.mkv": 2020, "Meine Frau, die Spartaner und ich (2008).avi": 2008, "Bang Boom Bang - Ein todsicheres Ding (1999).avi": 1999, "Titane (2021).mkv": 2021, "Der Glöckner von Notre Dame (1996).mpeg": 1996, "Tremors - Im Land der Raketenwürmer (1990).avi": 1990, "John Wick: Kapitel 4 (2023).mkv": 2023, "Die Verurteilten.mkv": 0, "Der Pate.mkv": 0, "Der Pate 2.mkv": 0, "The Dark Knight.mkv": 0, "Pulp Fiction.mkv": 0, } for d, expectedResult := range data { result, _ := getYearFromWarezString(SanitizeStringForWarezUsage(d)) if result != expectedResult { t.Errorf("\ngot: %d\nwanted: %d\nfor: %q", result, expectedResult, d) } } } func TestIsValidYear(t *testing.T) { data := map[int64]bool{ 1080: false, 1899: false, 1900: true, 1999: true, utils.GetCurrentYear(): true, utils.GetCurrentYear() + 1: true, utils.GetCurrentYear() + 2: true, utils.GetCurrentYear() + 3: true, utils.GetCurrentYear() + 4: false, utils.GetCurrentYear() + 1000: false, } for d, expectedResult := range data { result := isValidYear(d) if result != expectedResult { t.Errorf("\ngot: %t\nwanted: %t\nfor: %q", result, expectedResult, d) } } } func TestSanitizeStringForWarezUsage(t *testing.T) { data := map[string]string{ "John Wick: Kapitel 4 (2023)": "John.Wick.Kapitel.4.2023", "2-Headed Shark Attack (2012)": "2-Headed.Shark.Attack.2012", "Alien - Das unheimliche Wesen aus einer fremden Welt (1979)": "Alien.Das.unheimliche.Wesen.aus.einer.fremden.Welt.1979", "Beverly Hills Cop - Ich lös' den Fall auf jeden Fall (1984)": "Beverly.Hills.Cop.Ich.loes.den.Fall.auf.jeden.Fall.1984", "Und täglich grüßt das Murmeltier (1993)": "Und.taeglich.gruesst.das.Murmeltier.1993", "Adams Äpfel (2005)": "Adams.Aepfel.2005", "50/50 Freunde fürs (Über)Leben (2011)": "50.50.Freunde.fuers.UeberLeben.2011", } for d, expectedResult := range data { result := SanitizeStringForWarezUsage(d) if result != expectedResult { t.Errorf("\ngot: %q\nwanted: %q\nfor: %q", result, expectedResult, d) } } }