/// <summary> /// Gets a value indicating wether the path validates for the current video format /// </summary> /// <param name="path">path to validate</param> /// <returns>True if the given validates for this video format</returns> public static bool Validate(this VideoFormat self, string path) { switch (self) { case VideoFormat.Bluray: case VideoFormat.DVD: case VideoFormat.HDDVD: case VideoFormat.SVCD: return(path.EndsWith(self.PathEndsWith(), StringComparison.OrdinalIgnoreCase)); case VideoFormat.Unknown: return(Utility.IsImageFile(path)); case VideoFormat.File: try { if (Utility.IsMediaPortalVideoFile(path)) { FileInfo fileInfo = new FileInfo(path); string ext = fileInfo.Extension.ToLower(); string name = fileInfo.Name.ToLower();; // DVD: Non-Standalone content is invalid if (ext == ".vob" && Regex.Match(name, @"(video_ts|vts_).+", RegexOptions.IgnoreCase).Success) { return(false); } // Bluray: the only valid bluray file would already passed the method, we filter the rest if (ext == ".bdmv") { return(false); } // HD-DVD/(S)VCD: .dat files other than discid.dat should be ignored if (ext == ".dat" && name != "discid.dat") { return(false); } string dirName = fileInfo.Directory.Name; // DVD: Filter ifo's that are not called video_ts.ifo and sit in the video_ts folder // but allow them when we don't have a video_ts.ifo if (ext == ".ifo" && name != "video_ts.ifo") { if (dirName.Equals("video_ts", StringComparison.OrdinalIgnoreCase) || !File.Exists(path) || File.Exists(path.ToLower().Replace(name, "video_ts.ifo"))) { return(false); } } // Bluray: m2ts files sitting in a stream folder are part of a bluray disc if (ext == ".m2ts" && dirName.Equals("stream", StringComparison.OrdinalIgnoreCase)) { return(false); } // Bluray: mpls files sitting in a playlist folder are part of a bluray disc if (ext == ".mpls" && dirName.Equals("playlist", StringComparison.OrdinalIgnoreCase)) { return(false); } // HD-DVD: evo files sitting in a hvdvd_ts folder are part of a hddvd disc if (ext == ".evo" && dirName.Equals("hvdvd_ts", StringComparison.OrdinalIgnoreCase)) { return(false); } // if we made it this far we have a winner return(true); } } catch (Exception e) { if (e is ThreadAbortException) { throw e; } logger.ErrorException("An error occured while validating '" + path + "' as a video file.", e); } return(false); default: return(false); } }
/// <summary> /// Generates the full path to the video file on the specified drive. /// </summary> /// <param name="driveletter">the drive to use in the generated path</param> /// <returns>Full path to the entry file</returns> public static string GenerateVideoPathOnDrive(this VideoFormat self, string driveletter) { return(driveletter.PathToDriveletter() + self.PathEndsWith()); }