private string GetStringFromAudio(string pattern, AudioInfo ai) { if (string.IsNullOrEmpty(pattern)) { return(null); } pattern = pattern.ReplaceCode("%Audio_Format%", ai.Format); pattern = pattern.ReplaceCode("%Audio_%Format%", ai.Format); pattern = pattern.ReplaceCode("%Audio_Bitrate%", ai.Bitrate); pattern = pattern.ReplaceCode("%Audio_BitrateMode%", ai.BitrateMode); pattern = pattern.ReplaceCode("%Audio_Channels%", ai.Channels); pattern = pattern.ReplaceCode("%Audio_SamplingRate%", ai.SamplingRate); pattern = pattern.ReplaceCode("%Audio_Resolution%", ai.Resolution); pattern = TorrentInfo.Media.Info.ReplacePatternAudio(ai.Index, pattern); return(pattern); }
private string GetAudioInfo(string pattern, MediaFile mf) { if (string.IsNullOrEmpty(pattern)) { return(null); } StringBuilder sbAudio = new StringBuilder(); for (int i = 0; i < mf.Audio.Count; i++) { string info = pattern; AudioInfo ai = mf.Audio[i]; info = info.ReplaceCode("%AudioID%", (i + 1).ToString()); info = GetStringFromAudio(info, ai); sbAudio.AppendLine(info); } return(sbAudio.ToString()); }
/// <summary> /// Returns a Publish layout of Media Info that has Audio and Video /// </summary> /// <returns></returns> public string ToStringPublish(PublishOptionsPacket pop) { int fontSizeHeading3 = (int)(Program.Settings.PreText && Program.Settings.LargerPreText == true ? Program.Settings.FontSizeHeading3 + Program.Settings.FontSizeIncr : Program.Settings.FontSizeHeading3); int fontSizeBody = (int)(Program.Settings.PreText && Program.Settings.LargerPreText == true ? Program.Settings.FontSizeBody + Program.Settings.FontSizeIncr : Program.Settings.FontSizeBody); StringBuilder sbBody = new StringBuilder(); //********************* //* General //********************* StringBuilder sbGeneral = new StringBuilder(); sbBody.AppendLine(BbCode.Size(fontSizeHeading3, BbCode.BoldItalic("General:"))); sbBody.AppendLine(); // Format sbGeneral.Append(string.Format(" [u]Format:[/u] {0}", this.Format)); if (!string.IsNullOrEmpty(this.FormatInfo)) { sbGeneral.Append(string.Format(" ({0})", this.FormatInfo)); } sbGeneral.Append(Environment.NewLine); // File Size sbGeneral.AppendLine(string.Format(" [u]File Size:[/u] {0}", this.FileSizeString)); // Duration sbGeneral.AppendLine(string.Format(" [u]Duration:[/u] {0}", this.DurationString2)); // Bitrate sbGeneral.AppendLine(string.Format(" [u]Bitrate:[/u] {0}", this.BitrateOverall)); // Subtitles if (!string.IsNullOrEmpty(this.Subtitles)) { sbGeneral.AppendLine(string.Format(" [u]Subtitles:[/u] {0}", this.Subtitles)); } sbBody.AppendLine(BbCode.Size(fontSizeBody, sbGeneral.ToString())); if (this.Thumbnailer != null) { string ss = this.GetScreenshotString(pop); if (ss.Length > 0) { sbBody.AppendLine(this.GetScreenshotString(pop)); } } //********************* //* Video //********************* VideoInfo vi = this.Video; sbBody.AppendLine(); sbBody.AppendLine(BbCode.Size(fontSizeHeading3, BbCode.BoldItalic("Video:"))); sbBody.AppendLine(); StringBuilder sbVideo = new StringBuilder(); // Format sbVideo.Append(string.Format(" [u]Format:[/u] {0}", this.Video.Format)); if (!string.IsNullOrEmpty(this.Video.FormatVersion)) { sbVideo.Append(string.Format(" {0}", this.Video.FormatVersion)); } sbVideo.Append(Environment.NewLine); // Codec if (!string.IsNullOrEmpty(vi.Codec)) { sbVideo.AppendLine(string.Format(" [u]Codec:[/u] {0}", vi.Codec)); } // Bitrate sbVideo.AppendLine(string.Format(" [u]Bitrate:[/u] {0}", this.Video.Bitrate)); // Standard if (!string.IsNullOrEmpty(vi.Standard)) { sbVideo.AppendLine(string.Format(" [u]Standard:[/u] {0}", this.Video.Standard)); } // Frame Rate sbVideo.AppendLine(string.Format(" [u]Frame Rate:[/u] {0}", vi.FrameRate)); // Scan Type sbVideo.AppendLine(string.Format(" [u]Scan Type:[/u] {0}", vi.ScanType)); sbVideo.AppendLine(string.Format(" [u]Bits/(Pixel*Frame):[/u] {0}", vi.BitsPerPixelXFrame)); sbVideo.AppendLine(string.Format("[u]Display Aspect Ratio:[/u] {0}", vi.DisplayAspectRatio)); // Resolution sbVideo.AppendLine(string.Format(" [u]Resolution:[/u] {0}x{1}", vi.Width, vi.Height)); sbBody.Append(BbCode.Size(fontSizeBody, sbVideo.ToString())); //********************* //* Audio //********************* int audioCount = this.Audio.Count; for (int a = 0; a < audioCount; a++) { AudioInfo ai = this.Audio[a]; sbBody.AppendLine(); sbBody.AppendLine(string.Format(BbCode.Size(fontSizeHeading3, BbCode.BoldItalic("Audio #{0}:")), a + 1)); sbBody.AppendLine(); StringBuilder sbAudio = new StringBuilder(); // Format sbAudio.Append(string.Format(" [u]Format:[/u] {0}", ai.Format)); if (!string.IsNullOrEmpty(ai.FormatVersion)) { sbAudio.Append(string.Format(" {0}", ai.FormatVersion)); } if (!string.IsNullOrEmpty(ai.FormatProfile)) { sbAudio.Append(string.Format(" {0}", ai.FormatProfile)); } sbAudio.Append(Environment.NewLine); // Codec if (!string.IsNullOrEmpty(ai.Codec)) { sbAudio.AppendLine(string.Format(" [u]Codec:[/u] {0}", ai.Codec)); } // Bitrate sbAudio.AppendLine(string.Format(" [u]Bitrate:[/u] {0} ({1})", ai.Bitrate, ai.BitrateMode)); // Channels sbAudio.AppendLine(string.Format(" [u]Channels:[/u] {0}", ai.Channels)); // Sampling Rate sbAudio.AppendLine(string.Format(" [u]Sampling Rate:[/u] {0}", ai.SamplingRate)); // Resolution if (!string.IsNullOrEmpty(ai.Resolution)) { sbAudio.AppendLine(string.Format((" [u]Resolution:[/u] {0}"), ai.Resolution)); } sbBody.Append(BbCode.Size(fontSizeBody, sbAudio.ToString())); sbBody.AppendLine(); } return(sbBody.ToString()); }
/// <summary> /// Reads a media file and creates a MediaFile object /// </summary> /// <param name="fp">File Path of the Media File</param> /// <returns>MediaFile object</returns> public void ReadFile() { this.Source = Source; if (File.Exists(FilePath)) { //********************* //* General //********************* //System.Debug.WriteLine("Current Dir1: " + System.Environment.CurrentDirectory); //System.Environment.CurrentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //System.Debug.WriteLine("Current Dir2: " + System.Environment.CurrentDirectory); MediaInfoLib.MediaInfo MI = null; try { Debug.WriteLine("Loading MediaInfo.dll"); MI = new MediaInfoLib.MediaInfo(); Debug.WriteLine("Loaded MediaInfo.dll"); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } if (MI != null) { Debug.WriteLine(string.Format("MediaInfo Opening {0}", FilePath)); MI.Open(FilePath); Debug.WriteLine(string.Format("MediaInfo Opened {0}", FilePath)); MI.Option("Complete"); this.Summary = MI.Inform(); MI.Option("Complete", "1"); this.SummaryComplete = MI.Inform(); if (Program.IsUNIX) { Debug.WriteLine(string.Format("MediaInfo Summary Length: {0}", this.Summary.Length.ToString())); Debug.WriteLine(string.Format("MediaInfo Summary: {0}", this.Summary)); } // Format Info if (string.IsNullOrEmpty(this.Format)) { this.Format = MI.Get(StreamKind.General, 0, "Format"); } this.FormatInfo = MI.Get(StreamKind.General, 0, "Format/Info"); // this.FileName = mMI.Get(0, 0, "FileName"); if (0 == this.FileSize) { double sz; double.TryParse(MI.Get(0, 0, "FileSize"), out sz); this.FileSize = sz; } if (string.IsNullOrEmpty(this.FileSizeString)) { this.FileSizeString = string.Format("{0} MiB", (this.FileSize / 1024.0 / 1024.0).ToString("0.00")); } // Duration if (string.IsNullOrEmpty(this.DurationString2)) { this.DurationString2 = MI.Get(0, 0, "Duration/String2"); } if (this.Duration == 0.0) { double dura = 0.0; double.TryParse(MI.Get(0, 0, "Duration"), out dura); this.Duration = dura; this.SegmentDuration = dura; } if (string.IsNullOrEmpty(this.DurationString3)) { this.DurationString3 = MI.Get(0, 0, "Duration/String3"); } this.BitrateOverall = MI.Get(StreamKind.General, 0, "OverallBitRate/String"); this.EncodedApplication = MI.Get(StreamKind.General, 0, "Encoded_Application"); this.EncodedDate = MI.Get(StreamKind.General, 0, "Encoded_Date"); if (string.IsNullOrEmpty(this.Subtitles)) { StringBuilder sbSubs = new StringBuilder(); int subCount = 0; int.TryParse(MI.Get(StreamKind.Text, 0, "StreamCount"), out subCount); if (subCount > 0) { StringBuilder sbLang = new StringBuilder(); for (int i = 0; i < subCount; i++) { string lang = MI.Get(StreamKind.Text, i, "Language/String"); if (!string.IsNullOrEmpty(lang)) { // System.Windows.Forms.MessageBox.Show(lang); sbLang.Append(lang); if (i < subCount - 1) { sbLang.Append(", "); } } } if (!string.IsNullOrEmpty(sbLang.ToString())) { sbSubs.Append(sbLang.ToString()); } else { sbSubs.Append("N/A"); } } else { sbSubs.Append("None"); } this.Subtitles = sbSubs.ToString(); } //********************* //* Video //********************* int videoCount; int.TryParse(MI.Get(StreamKind.General, 0, "VideoCount"), out videoCount); this.HasVideo = videoCount > 0; this.Video.Format = MI.Get(StreamKind.Video, 0, "Format"); this.Video.FormatVersion = MI.Get(StreamKind.Video, 0, "Format_Version"); if (Path.GetExtension(this.FilePath).ToLower().Equals(".mkv")) { this.Video.Codec = MI.Get(StreamKind.Video, 0, "Encoded_Library"); } this.Video.EncodedLibrarySettings = MI.Get(StreamKind.Video, 0, "Encoded_Library_Settings"); this.Video.DisplayAspectRatio = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio/String"); if (string.IsNullOrEmpty(this.Video.Codec)) { this.Video.Codec = MI.Get(StreamKind.Video, 0, "CodecID/Hint"); } if (string.IsNullOrEmpty(this.Video.Codec)) { this.Video.Codec = MI.Get(StreamKind.Video, 0, "CodecID"); } this.Video.Bitrate = MI.Get(StreamKind.Video, 0, "BitRate/String"); this.Video.Standard = MI.Get(StreamKind.Video, 0, "Standard");; this.Video.FrameRate = MI.Get(StreamKind.Video, 0, "FrameRate/String"); this.Video.ScanType = MI.Get(StreamKind.Video, 0, "ScanType/String"); this.Video.Height = MI.Get(StreamKind.Video, 0, "Height"); this.Video.Width = MI.Get(StreamKind.Video, 0, "Width"); this.Video.Resolution = string.Format("{0}x{1}", this.Video.Width, this.Video.Height); this.Video.BitsPerPixelXFrame = MI.Get(StreamKind.Video, 0, "Bits-(Pixel*Frame)"); //********************* //* Audio //********************* int audioCount; int.TryParse(MI.Get(StreamKind.General, 0, "AudioCount"), out audioCount); this.HasAudio = audioCount > 0; for (int id = 0; id < audioCount; id++) { AudioInfo ai = new AudioInfo(id); ai.Format = MI.Get(StreamKind.Audio, id, "Format"); ai.FormatVersion = MI.Get(StreamKind.Audio, 0, "Format_Version"); ai.FormatProfile = MI.Get(StreamKind.Audio, 0, "Format_Profile"); ai.Codec = MI.Get(StreamKind.Audio, 0, "CodecID/Hint"); if (string.IsNullOrEmpty(ai.Codec)) { ai.Codec = MI.Get(StreamKind.Audio, 0, "CodecID/Info"); } if (string.IsNullOrEmpty(ai.Codec)) { ai.Codec = MI.Get(StreamKind.Audio, 0, "CodecID"); } ai.Bitrate = MI.Get(StreamKind.Audio, id, "BitRate/String"); ai.BitrateMode = MI.Get(StreamKind.Audio, id, "BitRate_Mode/String"); ai.Channels = MI.Get(StreamKind.Audio, id, "Channel(s)/String"); ai.SamplingRate = MI.Get(StreamKind.Audio, id, "SamplingRate/String"); ai.Resolution = MI.Get(StreamKind.Audio, id, "Resolution/String"); this.Audio.Add(ai); } MI.Close(); //// Analyse Audio only files using TagLib //if (this.HasAudio && !this.HasVideo) //{ // TagLib.File f = TagLib.File.Create(this.FilePath); // this.TagLibFile = f; //} } } }
private string GetStringFromAudio(string pattern, AudioInfo ai) { pattern = Regex.Replace(pattern, "%Audio_Format%", ai.Format, RegexOptions.IgnoreCase); pattern = Regex.Replace(pattern, "%Audio_Bitrate%", ai.Bitrate, RegexOptions.IgnoreCase); pattern = Regex.Replace(pattern, "%Audio_BitrateMode%", ai.BitrateMode, RegexOptions.IgnoreCase); pattern = Regex.Replace(pattern, "%Audio_Channels%", ai.Channels, RegexOptions.IgnoreCase); pattern = Regex.Replace(pattern, "%Audio_SamplingRate%", ai.SamplingRate, RegexOptions.IgnoreCase); pattern = Regex.Replace(pattern, "%Audio_Resolution%", ai.Resolution, RegexOptions.IgnoreCase); return pattern; }
private string GetStringFromAudio(string pattern, AudioInfo ai) { if (string.IsNullOrEmpty(pattern)) return null; pattern = pattern.ReplaceCode("%Audio_Format%", ai.Format); pattern = pattern.ReplaceCode("%Audio_%Format%", ai.Format); pattern = pattern.ReplaceCode("%Audio_Bitrate%", ai.Bitrate); pattern = pattern.ReplaceCode("%Audio_BitrateMode%", ai.BitrateMode); pattern = pattern.ReplaceCode("%Audio_Channels%", ai.Channels); pattern = pattern.ReplaceCode("%Audio_SamplingRate%", ai.SamplingRate); pattern = pattern.ReplaceCode("%Audio_Resolution%", ai.Resolution); pattern = TorrentInfo.Media.Info.ReplacePatternAudio(ai.Index, pattern); return pattern; }
/// <summary> /// Reads a media file and creates a MediaFile object /// </summary> /// <param name="fp">File Path of the Media File</param> /// <returns>MediaFile object</returns> public void ReadFile() { this.Source = Source; if (File.Exists(FilePath)) { //********************* //* General //********************* //System.Debug.WriteLine("Current Dir1: " + System.Environment.CurrentDirectory); //System.Environment.CurrentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //System.Debug.WriteLine("Current Dir2: " + System.Environment.CurrentDirectory); MediaInfoLib.MediaInfo MI = null; try { Debug.WriteLine("Loading MediaInfo.dll"); MI = new MediaInfoLib.MediaInfo(); Debug.WriteLine("Loaded MediaInfo.dll"); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } if (MI != null) { Debug.WriteLine(string.Format("MediaInfo Opening {0}", FilePath)); MI.Open(FilePath); Debug.WriteLine(string.Format("MediaInfo Opened {0}", FilePath)); MI.Option("Complete"); this.Summary = MI.Inform(); MI.Option("Complete", "1"); this.SummaryComplete = MI.Inform(); if (Program.IsUNIX) { Debug.WriteLine(string.Format("MediaInfo Summary Length: {0}", this.Summary.Length.ToString())); Debug.WriteLine(string.Format("MediaInfo Summary: {0}", this.Summary)); } // Format Info if (string.IsNullOrEmpty(this.Format)) this.Format = MI.Get(StreamKind.General, 0, "Format"); this.FormatInfo = MI.Get(StreamKind.General, 0, "Format/Info"); // this.FileName = mMI.Get(0, 0, "FileName"); if (0 == this.FileSize) { double sz; double.TryParse(MI.Get(0, 0, "FileSize"), out sz); this.FileSize = sz; } if (string.IsNullOrEmpty(this.FileSizeString)) { this.FileSizeString = string.Format("{0} MiB", (this.FileSize / 1024.0 / 1024.0).ToString("0.00")); } // Duration if (string.IsNullOrEmpty(this.DurationString2)) this.DurationString2 = MI.Get(0, 0, "Duration/String2"); if (this.Duration == 0.0) { double dura = 0.0; double.TryParse(MI.Get(0, 0, "Duration"), out dura); this.Duration = dura; this.SegmentDuration = dura; } if (string.IsNullOrEmpty(this.DurationString3)) this.DurationString3 = MI.Get(0, 0, "Duration/String3"); this.BitrateOverall = MI.Get(StreamKind.General, 0, "OverallBitRate/String"); this.EncodedApplication = MI.Get(StreamKind.General, 0, "Encoded_Application"); this.EncodedDate = MI.Get(StreamKind.General, 0, "Encoded_Date"); if (string.IsNullOrEmpty(this.Subtitles)) { StringBuilder sbSubs = new StringBuilder(); int subCount = 0; int.TryParse(MI.Get(StreamKind.Text, 0, "StreamCount"), out subCount); if (subCount > 0) { StringBuilder sbLang = new StringBuilder(); for (int i = 0; i < subCount; i++) { string lang = MI.Get(StreamKind.Text, i, "Language/String"); if (!string.IsNullOrEmpty(lang)) { // System.Windows.Forms.MessageBox.Show(lang); sbLang.Append(lang); if (i < subCount - 1) sbLang.Append(", "); } } if (!string.IsNullOrEmpty(sbLang.ToString())) { sbSubs.Append(sbLang.ToString()); } else { sbSubs.Append("N/A"); } } else { sbSubs.Append("None"); } this.Subtitles = sbSubs.ToString(); } //********************* //* Video //********************* int videoCount; int.TryParse(MI.Get(StreamKind.General, 0, "VideoCount"), out videoCount); this.HasVideo = videoCount > 0; this.Video.Format = MI.Get(StreamKind.Video, 0, "Format"); this.Video.FormatVersion = MI.Get(StreamKind.Video, 0, "Format_Version"); if (Path.GetExtension(this.FilePath).ToLower().Equals(".mkv")) { this.Video.Codec = MI.Get(StreamKind.Video, 0, "Encoded_Library"); } this.Video.EncodedLibrarySettings = MI.Get(StreamKind.Video, 0, "Encoded_Library_Settings"); this.Video.DisplayAspectRatio = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio/String"); if (string.IsNullOrEmpty(this.Video.Codec)) this.Video.Codec = MI.Get(StreamKind.Video, 0, "CodecID/Hint"); if (string.IsNullOrEmpty(this.Video.Codec)) this.Video.Codec = MI.Get(StreamKind.Video, 0, "CodecID"); this.Video.Bitrate = MI.Get(StreamKind.Video, 0, "BitRate/String"); this.Video.Standard = MI.Get(StreamKind.Video, 0, "Standard"); ; this.Video.FrameRate = MI.Get(StreamKind.Video, 0, "FrameRate/String"); this.Video.ScanType = MI.Get(StreamKind.Video, 0, "ScanType/String"); this.Video.Height = MI.Get(StreamKind.Video, 0, "Height"); this.Video.Width = MI.Get(StreamKind.Video, 0, "Width"); this.Video.Resolution = string.Format("{0}x{1}", this.Video.Width, this.Video.Height); this.Video.BitsPerPixelXFrame = MI.Get(StreamKind.Video, 0, "Bits-(Pixel*Frame)"); //********************* //* Audio //********************* int audioCount; int.TryParse(MI.Get(StreamKind.General, 0, "AudioCount"), out audioCount); this.HasAudio = audioCount > 0; for (int id = 0; id < audioCount; id++) { AudioInfo ai = new AudioInfo(id); ai.Format = MI.Get(StreamKind.Audio, id, "Format"); ai.FormatVersion = MI.Get(StreamKind.Audio, 0, "Format_Version"); ai.FormatProfile = MI.Get(StreamKind.Audio, 0, "Format_Profile"); ai.Codec = MI.Get(StreamKind.Audio, 0, "CodecID/Hint"); if (string.IsNullOrEmpty(ai.Codec)) ai.Codec = MI.Get(StreamKind.Audio, 0, "CodecID/Info"); if (string.IsNullOrEmpty(ai.Codec)) ai.Codec = MI.Get(StreamKind.Audio, 0, "CodecID"); ai.Bitrate = MI.Get(StreamKind.Audio, id, "BitRate/String"); ai.BitrateMode = MI.Get(StreamKind.Audio, id, "BitRate_Mode/String"); ai.Channels = MI.Get(StreamKind.Audio, id, "Channel(s)/String"); ai.SamplingRate = MI.Get(StreamKind.Audio, id, "SamplingRate/String"); ai.Resolution = MI.Get(StreamKind.Audio, id, "Resolution/String"); this.Audio.Add(ai); } MI.Close(); //// Analyse Audio only files using TagLib //if (this.HasAudio && !this.HasVideo) //{ // TagLib.File f = TagLib.File.Create(this.FilePath); // this.TagLibFile = f; //} } } }