private bool LoadText(string strFileName) { try { int num = 0; TimeSpan ts = new TimeSpan(0); string time = String.Empty; string name = String.Empty; bool onTime = true; string[] lines = File.ReadAllLines(strFileName, Encoding.Default); foreach (string line in lines) { if (onTime) { num++; //read time time = line.Replace("CHAPTER" + num.ToString("00") + "=", ""); ts = TimeSpan.Parse(time); } else { //read name name = line.Replace("CHAPTER" + num.ToString("00") + "NAME=", ""); //add it to list Chapters.Add(new Chapter() { Name = name, Time = ts }); } onTime = !onTime; } SourceFilePath = strFileName; Title = Path.GetFileNameWithoutExtension(strFileName); if (Chapters.Count > 0) { Duration = Chapters[Chapters.Count - 1].Time; } } catch (Exception) { Chapters.Clear(); return(false); } return(Chapters.Count != 0); }
private bool LoadText2(string strFileName) { // 00:00:00.000 Prologue // 00:00:14.000 Opening try { foreach (string line in File.ReadAllLines(strFileName, Encoding.Default)) { int iPos = line.IndexOf(' '); if (iPos <= 0) { continue; } string chapterTime = line.Split(' ')[0]; TimeSpan chapterSpan; if (!TimeSpan.TryParse(chapterTime, out chapterSpan)) { continue; } Chapters.Add(new Chapter() { Name = line.Substring(iPos + 1), Time = chapterSpan }); } SourceFilePath = strFileName; Title = Path.GetFileNameWithoutExtension(strFileName); if (Chapters.Count > 0) { Duration = Chapters[Chapters.Count - 1].Time; } } catch (Exception) { Chapters.Clear(); return(false); } return(Chapters.Count != 0); }
public MediaFile(List<MediaTrack> tracks, Chapters chapters, TimeSpan playTime, ContainerType container) { this.Container = container; AudioTracks = new List<AudioTrack>(); SubtitleTracks = new List<SubtitleTrack>(); foreach (MediaTrack m in tracks) { if (m is VideoTrack) { Debug.Assert(VideoTrack == null, "Only one video track per file supported"); VideoTrack = (VideoTrack)m; } if (m is AudioTrack) AudioTracks.Add((AudioTrack)m); if (m is SubtitleTrack) SubtitleTracks.Add((SubtitleTrack)m); } tracks.Sort( delegate(MediaTrack a, MediaTrack b) { return (int)a.TrackNumber - (int)b.TrackNumber; }); Tracks = tracks; Chapters = chapters; PlayTime = playTime; }
private bool LoadXML(string strFileName) { try { XmlDocument oChap = new XmlDocument(); oChap.Load(strFileName); foreach (XmlNode oFirstNode in oChap.ChildNodes) { if (!oFirstNode.Name.ToLowerInvariant().Equals("chapters")) { continue; } foreach (XmlNode oSecondNode in oFirstNode.ChildNodes) { if (!oSecondNode.Name.ToLowerInvariant().Equals("editionentry")) { continue; } foreach (XmlNode oThirdNode in oSecondNode.ChildNodes) { if (!oThirdNode.Name.ToLowerInvariant().Equals("chapteratom")) { continue; } Chapter oChapter = new Chapter(); foreach (XmlNode oChapterNode in oThirdNode.ChildNodes) { if (oChapterNode.Name.ToLowerInvariant().Equals("chaptertimestart")) { oChapter.SetTimeBasedOnString(oChapterNode.InnerText); } else if (oChapterNode.Name.ToLowerInvariant().Equals("chapterdisplay")) { foreach (XmlNode oChapterString in oChapterNode.ChildNodes) { if (oChapterString.Name.ToLowerInvariant().Equals("chapterstring")) { oChapter.Name = oChapterString.InnerText; } } } } Chapters.Add(oChapter); } break; // avoid multiple editions } } SourceFilePath = strFileName; Title = Path.GetFileNameWithoutExtension(strFileName); if (Chapters.Count > 0) { Duration = Chapters[Chapters.Count - 1].Time; } } catch (Exception) { Chapters.Clear(); return(false); } return(Chapters.Count != 0); }
public static MediaFile Open(string file) { try { MediaInfo m = new MediaInfo(file); // tracks List <MediaTrack> tracks = new List <MediaTrack>(); foreach (MediaInfoWrapper.VideoTrack t in m.Video) { VideoTrack v = new VideoTrack(); v.Codec = v.VCodec = getVideoCodec(t.Codec); v.Info = new MeGUI.core.details.TrackInfo(t.Language, t.Title); ulong width = ulong.Parse(t.Width); ulong height = ulong.Parse(t.Height); ulong frameCount = ulong.Parse(t.FrameCount); double fps = double.Parse(t.FrameRate); decimal?ar = easyParse <decimal>(delegate { return(decimal.Parse(t.AspectRatio)); }); Dar dar = new Dar(ar, width, height); v.StreamInfo = new VideoInfo2(width, height, dar, frameCount, fps); v.TrackNumber = uint.Parse(t.ID); tracks.Add(v); } foreach (MediaInfoWrapper.AudioTrack t in m.Audio) { AudioTrack a = new AudioTrack(); a.Codec = a.ACodec = getAudioCodec(t.Codec); a.Info = new MeGUI.core.details.TrackInfo(t.Language, t.Title); a.StreamInfo = new AudioInfo(); a.TrackNumber = uint.Parse(t.ID); tracks.Add(a); } foreach (MediaInfoWrapper.TextTrack t in m.Text) { SubtitleTrack s = new SubtitleTrack(); s.Codec = s.SCodec = getSubtitleCodec(t.Codec); s.Info = new MeGUI.core.details.TrackInfo(t.Language, t.Title); s.StreamInfo = new SubtitleInfo2(); s.TrackNumber = uint.Parse(t.ID); tracks.Add(s); } if (m.General.Count != 1) { throw new Exception("Expected one general track"); } GeneralTrack g = m.General[0]; ContainerType cType = getContainerType(g.Format, g.FormatString); TimeSpan playTime = TimeSpan.Parse(g.PlayTimeString3); Chapters chapters = null; if (m.Chapters.Count == 1) { chapters = parseChapters(m.Chapters[0]); } return(new MediaFile(tracks, chapters, playTime, cType)); } catch (Exception) { return(null); } }