Esempio n. 1
0
        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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        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);
        }