/// <summary> /// Tries to read a valid IMDB id from additional .nfo or .txt files. /// </summary> /// <param name="fsra">FileSystemResourceAccessor</param> /// <param name="imdbId">Returns a valid IMDB or <c>null</c></param> /// <returns>true if matched</returns> public static bool TryMatchImdbId(IFileSystemResourceAccessor fsra, out string imdbId) { imdbId = null; if (fsra == null) { return(false); } // First try to find a nfo file that has the same name as our main movie. if (fsra.IsFile) { foreach (string extension in NFO_EXTENSIONS) { string metaFilePath = ResourcePathHelper.ChangeExtension(fsra.CanonicalLocalResourcePath.ToString(), extension); if (TryRead(metaFilePath, out imdbId)) { return(true); } } } // Prepare a list of paths to check: for chained resource path we will also check relative parent paths (like for DVD-ISO files) List <string> pathsToCheck = new List <string> { fsra.CanonicalLocalResourcePath.ToString() }; if (fsra.CanonicalLocalResourcePath.PathSegments.Count > 1) { string canocialPath = fsra.CanonicalLocalResourcePath.ToString(); pathsToCheck.Add(canocialPath.Substring(0, canocialPath.LastIndexOf('>'))); } // Then test for special named files, like "movie.nfo" foreach (string path in pathsToCheck) { foreach (string fileName in NFO_FILENAMES) { string metaFilePath = ResourcePathHelper.GetDirectoryName(path); metaFilePath = ResourcePathHelper.Combine(metaFilePath, fileName); if (TryRead(metaFilePath, out imdbId)) { return(true); } } } // Now check siblings of movie for any IMDB id containing filename. // Morpheus_xx, 2014-01-04: disabled code because it leads to false detections if there are multiple video files in same folder. In this case the first // video with TT-number is wrongly used. // TODO: this part could be reworked based on different ideas: // - Exclude known video extensions from file name matching (this would require a reference to VideoMDE's settings for extension list) // - Only use folder lookup for chained resources, i.e. for a DVD-ISO, where any "TT000000.bla" is located next to it //IFileSystemResourceAccessor directoryFsra = null; //if (!fsra.IsFile) // directoryFsra = fsra.Clone() as IFileSystemResourceAccessor; //if (fsra.IsFile) // directoryFsra = GetContainingDirectory(fsra); //if (directoryFsra == null) // return false; //using (directoryFsra) // foreach (IFileSystemResourceAccessor file in directoryFsra.GetFiles()) // using (file) // if (ImdbIdMatcher.TryMatchImdbId(file.ResourceName, out imdbId)) // return true; return(false); }
/// <summary> /// Tries to read a valid IMDB id from additional .nfo or .txt files. /// </summary> /// <param name="fsra">FileSystemResourceAccessor</param> /// <param name="imdbId">Returns a valid IMDB or <c>null</c></param> /// <returns>true if matched</returns> public static bool TryMatchImdbId(IFileSystemResourceAccessor fsra, out string imdbId) { imdbId = null; if (fsra == null) { return(false); } // First try to find a nfo file that has the same name as our main movie. if (fsra.IsFile) { foreach (string extension in NFO_EXTENSIONS) { string metaFilePath = ResourcePathHelper.ChangeExtension(fsra.CanonicalLocalResourcePath.ToString(), extension); if (TryRead(metaFilePath, out imdbId)) { return(true); } } } // Prepare a list of paths to check: for chained resource path we will also check relative parent paths (like for DVD-ISO files) List <string> pathsToCheck = new List <string> { fsra.CanonicalLocalResourcePath.ToString() }; if (fsra.CanonicalLocalResourcePath.PathSegments.Count > 1) { string canocialPath = fsra.CanonicalLocalResourcePath.ToString(); pathsToCheck.Add(canocialPath.Substring(0, canocialPath.LastIndexOf('>'))); } // Then test for special named files, like "movie.nfo" foreach (string path in pathsToCheck) { foreach (string fileName in NFO_FILENAMES) { string metaFilePath = ResourcePathHelper.GetDirectoryName(path); metaFilePath = ResourcePathHelper.Combine(metaFilePath, fileName); if (TryRead(metaFilePath, out imdbId)) { return(true); } } } // Now check siblings of movie for any IMDB id containing filename. IFileSystemResourceAccessor directoryFsra = null; if (fsra.IsDirectory) { directoryFsra = fsra.Clone() as IFileSystemResourceAccessor; } if (fsra.IsFile) { directoryFsra = GetContainingDirectory(fsra); } if (directoryFsra == null) { return(false); } using (directoryFsra) foreach (IFileSystemResourceAccessor file in directoryFsra.GetFiles()) { using (file) if (ImdbIdMatcher.TryMatchImdbId(file.ResourceName, out imdbId)) { return(true); } } return(false); }