MovieFilenameScanner { public static MovieFileNameDTO scan(File file) { return new MovieFilenameScanner(file).getDto(); } private  MovieFilenameScanner(File file); static Pattern getTokenDelimitersMatchPattern(); static Pattern iwpatt(String regex); static Pattern wpatt(String regex); static String determineLanguage(String language); static String getLanguageList(String language); static MovieFileNameDTO scan(File file); static String[] getSkipKeywords(); static void setSkipKeywords(String[] skipKeywords, boolean caseSensitive); static String[] getSkipRegexKeywords(); static void setSkipRegexKeywords(String[] skipRegexKeywords, boolean caseSensitive); static String[] getExtrasKeywords(); static void setExtrasKeywords(String[] extrasKeywords); static String[] getMovieVersionKeywords(); static void setMovieVersionKeywords(String[] movieVersionKeywords); static boolean isLanguageDetection(); static void setLanguageDetection(boolean languageDetection); MovieFileNameDTO getDto(); File getFile(); String getFilename(); static void clearLanguages(); static void addLanguage(String key, String strictPattern, String loosePattern); static void setSourceKeywords(List<String> keywords, Map<String, String> keywordMap);  }
@Test public void testNoSpaceBeforeBracket() { LOG.info("NoSpaceBeforeBracket"); MovieFileNameDTO d = scan("Aliens(1986).avi"); assertEquals("Aliens", d.getTitle()); assertEquals(1986, d.getYear()); }
@Test public void testTrailer() { LOG.info("Trailer"); MovieFileNameDTO d = scan("Gladiator[PART1].[TRAILER-gladiator_480_sv2].mov"); assertEquals("Gladiator", d.getTitle()); assertEquals("TRAILER-gladiator_480_sv2", d.getPartTitle()); d = scan("Gladiator[PART1] - Movie .[TRAILER-gladiator_480_sv2].mov"); assertEquals("Gladiator", d.getTitle()); assertEquals("TRAILER-gladiator_480_sv2", d.getPartTitle()); }
@Test public void testNaming() { LOG.info("Naming"); MovieFileNameDTO d = scan("Aime ton Père (2002) [Jacob Berger, Gérard Depardieu, Guillaume Depardieu, Sylvie Testud].ISO"); assertEquals("Aime ton Père", d.getTitle()); assertEquals(2002, d.getYear()); }
@Test public void testDate() { LOG.info("Date"); MovieFileNameDTO d = scan("Time masters (Laloux Moebius) (1982) Eng.Hun.Fra.De.Ru.mkv"); assertEquals(1982, d.getYear()); d = scan("Role Models [2008]"); assertEquals(2008, d.getYear()); d = scan("se7en se7en [1995]"); assertEquals(1995, d.getYear()); d = scan("se7en (1995)"); assertEquals(1995, d.getYear()); d = scan("Role Models (2008)"); assertEquals(2008, d.getYear()); }
@Test public void testSkipKeywords() { LOG.info("SkipKeywords"); MovieFileNameDTO d = scan("Blood Diamond.mkv"); assertEquals("Blood Diamond", d.getTitle()); d = scan("Blood DiAMOND ccc.mkv"); assertEquals("Blood", d.getTitle()); }
@Test public void testScan() { LOG.info("Scan"); int iResult; MovieFileNameDTO d = scan("Desperate Housewives S04E01E02E03E06.iso"); assertEquals("Desperate Housewives", d.getTitle()); assertEquals("iso", d.getExtension()); assertEquals("ISO", d.getContainer()); assertEquals(4, d.getSeason()); assertEquals(Arrays.asList(new Integer[]{1, 2, 3, 6}), d.getEpisodes()); d = scan("The.Matrix.[Trailer-Unrated].avi"); assertEquals("The Matrix", d.getTitle()); assertEquals("avi", d.getExtension()); assertEquals("AVI", d.getContainer()); assertTrue(d.isExtra()); assertEquals("Trailer-Unrated", d.getPartTitle()); d = scan("The.Matrix 720P - Unrated Trailer.avi"); assertEquals("The Matrix", d.getTitle()); assertFalse(d.isExtra()); assertEquals("720p", d.getHdResolution()); d = scan("The.Trailer[ccc][Rated Trailer][XXX] TRAILER.p23.avi"); assertTrue(d.isExtra()); assertEquals("Rated Trailer", d.getPartTitle()); assertEquals(23, d.getFps()); d = scan("Postal 2 720x400.iso"); assertEquals(-1, d.getSeason()); assertEquals(0, d.getEpisodes().size()); assertNull(d.getAudioCodec()); d = scan("House 3x101x19x3.avi"); assertEquals(3, d.getSeason()); assertEquals(Arrays.asList(new Integer[]{101, 19, 3}), d.getEpisodes()); d = scan("Dinner.Game.(Diner.De.Cons).1998.FRENCH.720p.BluRay.x264-zzz.ts"); assertEquals(1998, d.getYear()); assertEquals("Dinner Game (Diner De Cons)", d.getTitle()); assertEquals(1, d.getLanguages().size()); d = scan("The.French.Connection.mkv"); assertEquals("The French Connection", d.getTitle()); assertEquals(0, d.getLanguages().size()); d = scan("Burn-E.[2008].[Pixar.Short].[BDrip.720p.x264].mkv"); assertEquals(2008, d.getYear()); assertEquals("Burn-E", d.getTitle()); d = scan("shrek.avi"); assertEquals("shrek", d.getTitle()); d = scan("shrek_2.avi"); assertEquals("shrek 2", d.getTitle()); d = scan("Paprika (DVDRip XviD 768x432 24fps AC3 5.1ch).avi"); assertEquals("Paprika", d.getTitle()); d = scan("Stargate.SG1.S04E16 - 2010.avi"); assertEquals("Stargate SG1", d.getTitle()); assertEquals(4, d.getSeason()); assertEquals(1, d.getEpisodes().size()); iResult = d.getEpisodes().get(0); assertEquals(16, iResult); assertEquals("2010", d.getEpisodeTitle()); d = scan("The Sopranos - S03E01 DVDrip.XviD-SMB.avi"); assertEquals("The Sopranos", d.getTitle()); assertEquals(3, d.getSeason()); assertEquals(1, d.getEpisodes().size()); iResult = d.getEpisodes().get(0); assertEquals(1, iResult); assertEquals(null, d.getEpisodeTitle()); d = scan("final_fantasy_VII_Advent_Children_1080p_RUS_ENG.mkv"); assertEquals("final fantasy VII Advent Children", d.getTitle()); assertEquals("1080p", d.getHdResolution()); assertEquals(2, d.getLanguages().size()); d = scan("Chasseurs.De.Dragons.FRENCH.720p.BluRay.x264-HDClub.mkv"); assertEquals("Chasseurs De Dragons", d.getTitle()); assertEquals("720p", d.getHdResolution()); assertEquals("BluRay", d.getVideoSource()); assertEquals("H.264", d.getVideoCodec()); assertEquals(1, d.getLanguages().size()); assertEquals("French", d.getLanguages().get(0)); d = scan("Steamboy_(2004)_[720p,BluRay,x264,DTS]_-_THORA.mkv"); assertEquals(2004, d.getYear()); assertEquals("Steamboy", d.getTitle()); assertEquals("720p", d.getHdResolution()); assertEquals("BluRay", d.getVideoSource()); assertEquals("H.264", d.getVideoCodec()); d = scan("Rush hour 2 DVD"); assertEquals(0, d.getSets().size()); assertEquals("Rush hour 2", d.getTitle()); d = scan("21 DVD-RIP"); assertEquals("21", d.getTitle()); assertEquals("DVD", d.getVideoSource()); d = scan("1408 DVD"); assertEquals("DVD", d.getVideoSource()); assertEquals("1408", d.getTitle()); d = scan("[KB]_Cowboy_Bebop_Remastered_07.DVD_(H264.AC3_5.1).mkv"); assertEquals("Cowboy Bebop", d.getTitle()); assertEquals(7, d.getPart()); assertNull(d.getPartTitle()); d = scan("Air.Force.One.1997.720p.BluRay.DD5.1.x264.avi"); assertEquals("Air Force One", d.getTitle()); assertEquals(1997, d.getYear()); assertEquals("720p", d.getHdResolution()); assertEquals("This should be -1 as it is not a TV Show", -1, d.getSeason()); d = scan("Le Seigneur des anneaux le retour du roi [SET Le seigneur des anneaux-3] - 720p.bluray.x264.mkv"); LOG.info("Sets: {}", d.getSets()); }
@Test public void testScanSets() { LOG.info("ScanSets"); MovieFileNameDTO d = scan("X-Men 3 [SET X-Men - 99].avi"); assertEquals(1, d.getSets().size()); assertEquals(99, d.getSets().get(0).getIndex()); assertEquals("X-Men", d.getSets().get(0).getTitle()); assertEquals("X-Men 3", d.getTitle()); d = scan("Spider-Man 2.1.720p[SET Spiderman-2].ts"); assertEquals(1, d.getSets().size()); assertEquals("Spiderman", d.getSets().get(0).getTitle()); assertEquals(2, d.getSets().get(0).getIndex()); d = scan("[SET Alien Collection] Alien vs Predator.mkv"); assertEquals(1, d.getSets().size()); assertEquals("Alien Collection", d.getSets().get(0).getTitle()); assertEquals("Alien vs Predator", d.getTitle()); d = scan("Alien vs Predator [SET Alien Collection 2][SET Predator-3].mkv"); assertEquals(2, d.getSets().size()); assertEquals("Alien Collection 2", d.getSets().get(0).getTitle()); assertEquals(-1, d.getSets().get(0).getIndex()); assertEquals("Predator", d.getSets().get(1).getTitle()); assertEquals(3, d.getSets().get(1).getIndex()); d = scan("Le Seigneur des anneaux le retour du roi [SET Le seigneur des anneaux-3] - 720p.bluray.x264.mkv"); assertEquals(1, d.getSets().size()); assertEquals("Le seigneur des anneaux", d.getSets().get(0).getTitle()); assertEquals(3, d.getSets().get(0).getIndex()); }
@Test public void testScanLanguages() { LOG.info("ScanLanguages"); int iResult; MovieFileNameDTO d = scan("Time masters (Laloux Moebius) (1982) Eng.Hun.Fra.De.Ru.mkv"); assertEquals(1982, d.getYear()); assertEquals("Time masters (Laloux Moebius)", d.getTitle()); assertEquals(5, d.getLanguages().size()); assertTrue(d.getLanguages().contains("English")); assertTrue(d.getLanguages().contains("Hungarian")); assertTrue(d.getLanguages().contains("French")); assertTrue(d.getLanguages().contains("German")); assertTrue(d.getLanguages().contains("Russian")); d = scan("The_IT_Crowd.S02E03.rus.lostfilm - Moss and the German.avi"); assertEquals("The IT Crowd", d.getTitle()); assertEquals(2, d.getSeason()); assertEquals(1, d.getEpisodes().size()); iResult = d.getEpisodes().get(0); assertEquals(3, iResult); assertEquals(1, d.getLanguages().size()); assertEquals("Russian", d.getLanguages().get(0)); assertEquals("Moss and the German", d.getEpisodeTitle()); d = scan("Misery.1990[German]DTS.720p.BluRay.x264.mkv"); assertEquals("Misery", d.getTitle()); assertEquals(1990, d.getYear()); assertEquals(1, d.getLanguages().size()); assertTrue(d.getLanguages().contains("German")); d = scan("The.Good.German.2006.720p.BluRay.x264.ts"); assertEquals("The Good German", d.getTitle()); assertEquals(2006, d.getYear()); assertEquals(0, d.getLanguages().size()); }
@Test public void testScanSeries() { LOG.info("ScanSeries"); int iResult; MovieFileNameDTO d = scan("Formula.1.S2008E1.avi"); assertEquals("Formula 1", d.getTitle()); assertEquals(2008, d.getSeason()); assertEquals(1, d.getEpisodes().size()); iResult = d.getEpisodes().get(0); assertEquals(1, iResult); d = scan("Horizon.S2009E03.avi"); assertEquals(2009, d.getSeason()); assertEquals(1, d.getEpisodes().size()); iResult = d.getEpisodes().get(0); assertEquals(3, iResult); d = scan("World.Series.Of.Poker.S2008E11E12E13.avi.avi"); assertEquals("World Series Of Poker", d.getTitle()); assertEquals("Invalid season", 2008, d.getSeason()); assertEquals("Incorrect size", 3, d.getEpisodes().size()); iResult = d.getEpisodes().get(0); assertEquals("Incorrect first episode", 11, iResult); iResult = d.getEpisodes().get(1); assertEquals("Incorrect second episode", 12, iResult); iResult = d.getEpisodes().get(2); assertEquals("Incorrect third episode", 13, iResult); d = scan("House.S03E14.HDTV.XviD-XOR.avi"); assertEquals("House", d.getTitle()); assertEquals(3, d.getSeason()); assertEquals(1, d.getEpisodes().size()); assertEquals(null, d.getPartTitle()); assertEquals(null, d.getEpisodeTitle()); d = scan("Dead_Like_Me_S02E12 - Forget Me Not.HDTV.XviD-vfua.avi"); assertEquals("Dead Like Me", d.getTitle()); assertEquals(2, d.getSeason()); assertEquals(1, d.getEpisodes().size()); assertEquals("HDTV", d.getVideoSource()); assertEquals("XviD", d.getVideoCodec()); assertNull(d.getPartTitle()); assertEquals("Forget Me Not", d.getEpisodeTitle()); }
@Test public void testScanVersion() { LOG.info("ScanVersion"); MovieFileNameDTO d = scan("Ghost Rider.2007.Extended.Cut.720p.BluRay.x264.mkv"); assertEquals("Ghost Rider", d.getTitle()); assertEquals(2007, d.getYear()); d = scan("Dark.City.1998.directors.cut.dvdrip.xvid-nodlabs.avi"); assertEquals("Dark City", d.getTitle()); assertEquals(1998, d.getYear()); d = scan("Troy.Directors.Cut.HDDVDRip.720p.x264.HANSMER.mkv"); assertEquals("Troy", d.getTitle()); }
@Test public void testScanParts() { LOG.info("ScanParts"); MovieFileNameDTO d = scan("How Music Works - part 1 of 4 - Melody.avi"); assertEquals(-1, d.getSeason()); assertEquals(-1, d.getPart()); d = scan("File (5 DVD)aac.avi"); assertEquals(-1, d.getSeason()); assertEquals(5, d.getPart()); assertEquals("AAC", d.getAudioCodec()); assertEquals("File", d.getTitle()); d = scan("The File [cd3]h.264.avi"); assertEquals(-1, d.getSeason()); assertEquals(3, d.getPart()); assertEquals("H.264", d.getVideoCodec()); d = scan("The File 60p part66 - The File Strikes Back.avi"); assertEquals(-1, d.getSeason()); assertEquals(66, d.getPart()); assertEquals(60, d.getFps()); assertEquals("The File", d.getTitle()); assertEquals("The File Strikes Back", d.getPartTitle()); }
@Test public void testRussian() { LOG.info("Russian"); MovieFileNameDTO d = scan("Воображариум доктора Парнаса.mkv"); assertEquals("Воображариум доктора Парнаса", d.getTitle()); d = scan("You Don't Mess with the Zohan.2008.Rus.DVDRip.avi"); assertEquals("You Don't Mess with the Zohan", d.getTitle()); assertEquals(2008, d.getYear()); assertEquals(1, d.getLanguages().size()); assertEquals("Russian", d.getLanguages().get(0)); }
@Test public void testParentFolderName() { LOG.info("ParentFolderName"); MovieFileNameDTO d = scan("Гора самоцветов 1 Рубин", "Part1 - Шейдулла-лентяй.avi"); assertEquals("Гора самоцветов 1 Рубин", d.getTitle()); assertEquals(1, d.getPart()); assertEquals("Шейдулла-лентяй", d.getPartTitle()); }
@Test public void testIssue1835() { LOG.info("Issue1835"); MovieFileNameDTO d = scan("Tropa de Elite.[2007].BRRip.x264.PCMKV.mkv"); assertEquals("Tropa de Elite", d.getTitle()); assertEquals(2007, d.getYear()); d = scan("Tropa de Elite 2.[2010].BDRip.XviD-ZMG.avi"); assertEquals("Tropa de Elite 2", d.getTitle()); assertEquals(2010, d.getYear()); }
@Test public void testIssue1946() { LOG.info("Issue1946"); int iResult; MovieFileNameDTO d = scan("y:" + File.separator + "test" + File.separator + "South Park - S14E05 - 200 (1).avi"); assertEquals("200 (1)", d.getEpisodeTitle()); assertEquals(14, d.getSeason()); assertEquals(-1, d.getYear()); assertEquals(1, d.getEpisodes().size()); iResult = d.getEpisodes().get(0); assertEquals(5, iResult); assertEquals("South Park", d.getTitle()); }