Пример #1
0
        /// <summary>
        /// Gets the ChapterExtractor for the source
        /// </summary>
        /// <param name="strFileOrInputFolder"></param>
        /// <returns>the ChapterExtrator will be returned if found or null if not</returns>
        private ChapterExtractor GetExtractor(string strFileOrInputFolder)
        {
            ChapterExtractor ex = null;

            if (strFileOrInputFolder.ToLowerInvariant().EndsWith(".mpls"))
            {
                ex = new MplsExtractor();
            }
            else if (strFileOrInputFolder.ToLowerInvariant().EndsWith(".txt") || strFileOrInputFolder.ToLowerInvariant().EndsWith(".xml"))
            {
                ex = new TextExtractor();
            }
            else if (!String.IsNullOrEmpty(MeGUI.core.util.FileUtil.GetBlurayPath(strFileOrInputFolder)))
            {
                ex = new BlurayExtractor();
            }
            else if (!String.IsNullOrEmpty(MeGUI.core.util.FileUtil.GetDVDPath(strFileOrInputFolder)))
            {
                ex        = new DvdExtractor();
                this.Text = "Select your Title/PGC";
            }
            else if (System.IO.File.Exists(strFileOrInputFolder))
            {
                ex = new MediaInfoExtractor();
            }

            return(ex);
        }
Пример #2
0
        public ChapterInfo GetChapterInfo(string location, int titleSetNum)
        {
            if (location.StartsWith("VTS_"))
            {
                titleSetNum = int.Parse(Path.GetFileNameWithoutExtension(location)
                                        .ToUpper(System.Globalization.CultureInfo.InvariantCulture)
                                        .Replace("VTS_", string.Empty)
                                        .Replace("_0.IFO", string.Empty));
            }

            ChapterInfo pgc = new ChapterInfo();

            pgc.SourceType  = "DVD";
            pgc.SourceName  = "PGC " + titleSetNum.ToString("D2");
            pgc.TitleNumber = titleSetNum;
            pgc.SourceHash  = ChapterExtractor.ComputeMD5Sum(location);
            pgc.Title       = Path.GetFileNameWithoutExtension(location);
            if (pgc.Title.Split('_').Length == 3)
            {
                pgc.Title = pgc.Title.Split('_')[0] + "_" + pgc.Title.Split('_')[1];
            }

            TimeSpan duration;
            double   fps;

            pgc.Chapters        = GetChapters(location, titleSetNum, out duration, out fps);
            pgc.Duration        = duration;
            pgc.FramesPerSecond = fps;

            OnStreamDetected(pgc);
            OnExtractionComplete();
            return(pgc);
        }
Пример #3
0
        public frmStreamSelect(ChapterExtractor extractor, SelectionMode selectionMode)
        {
            InitializeComponent();
            listBox1.SelectionMode = selectionMode;

            extractor.StreamDetected += (sender, arg) =>
            {
                listBox1.Items.Add(arg.ProgramChain);
            };
            extractor.ChaptersLoaded += (sender, arg) =>
            {
                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    if (((ChapterInfo)listBox1.Items[i]).SourceName == arg.ProgramChain.SourceName)
                    {
                        listBox1.Items[i] = arg.ProgramChain;
                        break;
                    }
                }
            };
            extractor.ExtractionComplete += (sender, arg) =>
            {
                btnSortDuration.Checked = true;
            };
        }
Пример #4
0
        public frmStreamSelect(ChapterExtractor extractor)
        {
            InitializeComponent();

              extractor.StreamDetected += (sender, arg) =>
            {
              listBox1.Items.Add(arg.ProgramChain);
            };
              extractor.ChaptersLoaded += (sender, arg) =>
            {
              for (int i = 0; i < listBox1.Items.Count; i++)
              {
            if (((ChapterInfo)listBox1.Items[i]).SourceName == arg.ProgramChain.SourceName)
            {
              listBox1.Items[i] = arg.ProgramChain;
              break;
            }
              }
            };
              extractor.ExtractionComplete += (sender, arg) =>
            {
              List<ChapterInfo> list = new List<ChapterInfo>(listBox1.Items.Cast<ChapterInfo>());
              list = list.OrderByDescending(p => p.Duration).ToList();
              listBox1.Items.Clear();
              listBox1.Items.AddRange(list.ToArray());
            };
        }
Пример #5
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            ChapterInfo pgc = new ChapterInfo();

            pgc.Chapters   = new List <Chapter>();
            pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location);
            pgc.SourceName = location;
            pgc.Title      = Path.GetFileNameWithoutExtension(location);
            pgc.SourceType = "Blu-Ray";

            FileInfo fileInfo = new FileInfo(location);

            OnStreamDetected(pgc);
            TSPlaylistFile mpls = new TSPlaylistFile(fileInfo);

            //Dictionary<string, TSStreamClipFile> clips = new Dictionary<string,TSStreamClipFile>();
            mpls.Scan(); int count = 1;
            foreach (double d in mpls.Chapters)
            {
                pgc.Chapters.Add(new Chapter()
                {
                    Name = "Chapter " + count.ToString("D2"),
                    Time = new TimeSpan((long)(d * (double)TimeSpan.TicksPerSecond))
                });
                count++;
            }

            pgc.Duration = new TimeSpan((long)(mpls.TotalLength * (double)TimeSpan.TicksPerSecond));

            foreach (TSStreamClip clip in mpls.StreamClips)
            {
                clip.StreamClipFile.Scan();
                foreach (TSStream stream in clip.StreamClipFile.Streams.Values)
                {
                    if (stream.IsVideoStream)
                    {
                        pgc.FramesPerSecond = (double)((TSVideoStream)stream).FrameRateEnumerator /
                                              (double)((TSVideoStream)stream).FrameRateDenominator;
                        break;
                    }
                }
                if (pgc.FramesPerSecond != 0)
                {
                    break;
                }
            }

            OnChaptersLoaded(pgc);
            OnExtractionComplete();
            return(new List <ChapterInfo>()
            {
                pgc
            });
        }
Пример #6
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            List <ChapterInfo> pgcs = new List <ChapterInfo>();

            List <Chapter> list = new List <Chapter>();

            int      num    = 0;
            TimeSpan ts     = new TimeSpan(0);
            string   time   = String.Empty;
            string   name   = String.Empty;
            bool     onTime = true;

            string[] lines = File.ReadAllLines(location);
            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
                    list.Add(new Chapter()
                    {
                        Name = name, Time = ts
                    });
                }
                onTime = !onTime;
            }

            pgcs.Add(new ChapterInfo()
            {
                Chapters        = list,
                SourceName      = location,
                SourceHash      = ChapterExtractor.ComputeMD5Sum(location),
                FramesPerSecond = 25.0,
                Title           = Path.GetFileNameWithoutExtension(location)
            });

            OnStreamDetected(pgcs[0]);
            OnChaptersLoaded(pgcs[0]);
            OnExtractionComplete();
            return(pgcs);
        }
Пример #7
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            ChapterInfo pgc = new ChapterInfo();

            pgc.Chapters   = new List <Chapter>();
            pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location);
            pgc.SourceName = location;
            pgc.Title      = Path.GetFileNameWithoutExtension(location);
            pgc.SourceType = "Blu-Ray";

            DirectoryInfo DirectoryBDMV = GetDirectoryBDMV(location);

            if (DirectoryBDMV == null)
            {
                throw new Exception("Unable to locate BD structure.");
            }

            DirectoryInfo DirectoryRoot =
                DirectoryBDMV.Parent;
            DirectoryInfo DirectoryBDJO =
                GetDirectory("BDJO", DirectoryBDMV, 0);
            DirectoryInfo DirectoryCLIPINF =
                GetDirectory("CLIPINF", DirectoryBDMV, 0);
            DirectoryInfo DirectoryPLAYLIST =
                GetDirectory("PLAYLIST", DirectoryBDMV, 0);
            DirectoryInfo DirectorySNP =
                GetDirectory("SNP", DirectoryRoot, 0);
            DirectoryInfo DirectorySTREAM =
                GetDirectory("STREAM", DirectoryBDMV, 0);
            DirectoryInfo DirectorySSIF =
                GetDirectory("SSIF", DirectorySTREAM, 0);

            Dictionary <string, TSStreamClipFile> StreamClipFiles = new Dictionary <string, TSStreamClipFile>();
            Dictionary <string, TSStreamFile>     StreamFiles     = new Dictionary <string, TSStreamFile>();

            if (DirectorySTREAM != null)
            {
                FileInfo[] files = DirectorySTREAM.GetFiles("*.m2ts");
                if (files.Length == 0)
                {
                    files = DirectoryPLAYLIST.GetFiles("*.M2TS");
                }
                foreach (FileInfo file in files)
                {
                    StreamFiles.Add(file.Name.ToUpper(), new TSStreamFile(file));
                }
            }

            if (DirectoryCLIPINF != null)
            {
                FileInfo[] files = DirectoryCLIPINF.GetFiles("*.clpi");
                if (files.Length == 0)
                {
                    files = DirectoryPLAYLIST.GetFiles("*.CLPI");
                }
                foreach (FileInfo file in files)
                {
                    StreamClipFiles.Add(file.Name.ToUpper(), new TSStreamClipFile(file));
                }
            }

            FileInfo       fileInfo = new FileInfo(location);
            TSPlaylistFile mpls     = new TSPlaylistFile(fileInfo);

            mpls.Scan(StreamFiles, StreamClipFiles);

            int count = 1;

            foreach (double d in mpls.Chapters)
            {
                pgc.Chapters.Add(new Chapter()
                {
                    Name = "Chapter " + count.ToString("D2"),
                    Time = new TimeSpan((long)(d * (double)TimeSpan.TicksPerSecond))
                });
                count++;
            }

            pgc.Duration = new TimeSpan((long)(mpls.TotalLength * (double)TimeSpan.TicksPerSecond));

            foreach (TSStreamClip clip in mpls.StreamClips)
            {
                clip.StreamClipFile.Scan();
                foreach (TSStream stream in clip.StreamClipFile.Streams.Values)
                {
                    if (stream.IsVideoStream)
                    {
                        pgc.FramesPerSecond = VideoUtil.ConvertFPSFractionToDouble(((TSVideoStream)stream).FrameRateEnumerator, ((TSVideoStream)stream).FrameRateDenominator);
                        break;
                    }
                }
                if (pgc.FramesPerSecond != 0)
                {
                    break;
                }
            }

            if (pgc.Duration.TotalSeconds > MainForm.Instance.Settings.ChapterCreatorMinimumLength)
            {
                OnStreamDetected(pgc);
                OnChaptersLoaded(pgc);
            }
            else
            {
                pgc = null;
            }
            OnExtractionComplete();
            return(new List <ChapterInfo>()
            {
                pgc
            });
        }
Пример #8
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            List <ChapterInfo> pgcs            = new List <ChapterInfo>();
            List <Chapter>     list            = new List <Chapter>();
            string             tempChapterFile = String.Empty;

            do
            {
                tempChapterFile = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), Path.GetRandomFileName());
            }while (File.Exists(tempChapterFile));

            MediaInfoFile oInfo = new MediaInfoFile(location);

            if (!oInfo.hasMKVChapters() || !oInfo.extractMKVChapters(tempChapterFile))
            {
                OnExtractionComplete();
                return(pgcs);
            }

            int      num    = 0;
            TimeSpan ts     = new TimeSpan(0);
            string   time   = String.Empty;
            string   name   = String.Empty;
            bool     onTime = true;

            string[] lines = File.ReadAllLines(tempChapterFile);
            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
                    list.Add(new Chapter()
                    {
                        Name = name, Time = ts
                    });
                }
                onTime = !onTime;
            }

            pgcs.Add(new ChapterInfo()
            {
                Chapters        = list,
                SourceName      = location,
                SourceHash      = ChapterExtractor.ComputeMD5Sum(tempChapterFile),
                FramesPerSecond = oInfo.VideoInfo.FPS,
                Title           = Path.GetFileNameWithoutExtension(location)
            });

            try { File.Delete(tempChapterFile); } catch {}

            OnStreamDetected(pgcs[0]);
            OnChaptersLoaded(pgcs[0]);
            OnExtractionComplete();
            return(pgcs);
        }
Пример #9
0
        private void btInput_Click(object sender, EventArgs e)
        {
            if (rbFromFile.Checked)
            {
                openFileDialog.Filter      = "IFO Files (*.ifo)|*.ifo|MPLS Files (*.mpls)|*.mpls|Text Files (*.txt)|*.txt|All Files supported (*.ifo,*.mpls,*.txt)|*.ifo;*.mpls;*.txt";
                openFileDialog.FilterIndex = 4;

                if (this.openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    input.Text = openFileDialog.FileName;

                    if (input.Text.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith("ifo"))
                    {
                        ChapterExtractor ex = new DvdExtractor();
                        using (frmStreamSelect frm = new frmStreamSelect(ex))
                        {
                            if (ex is DvdExtractor)
                            {
                                frm.Text = "Select your PGC";
                            }
                            else
                            {
                                frm.Text = "Select your Playlist";
                            }
                            ex.GetStreams(input.Text);
                            if (frm.ChapterCount == 1 || frm.ShowDialog(this) == DialogResult.OK)
                            {
                                pgc = frm.SelectedSingleChapterInfo;
                                if (pgc.FramesPerSecond == 0)
                                {
                                    pgc.FramesPerSecond = 25.0;
                                }
                                if (String.IsNullOrEmpty(pgc.LangCode))
                                {
                                    pgc.LangCode = "und";
                                }
                            }
                        }
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else if (input.Text.ToLower(System.Globalization.CultureInfo.InvariantCulture).EndsWith("mpls"))
                    {
                        ChapterExtractor ex = new MplsExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else
                    {
                        ChapterExtractor ex = new TextExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                }
            }
            else
            {
                using (FolderBrowserDialog d = new FolderBrowserDialog())
                {
                    d.ShowNewFolderButton = false;
                    d.Description         = "Select DVD, BluRay disc, or folder.";
                    if (d.ShowDialog() == DialogResult.OK)
                    {
                        input.Text = d.SelectedPath;
                        try
                        {
                            ChapterExtractor ex =
                                Directory.Exists(Path.Combine(input.Text, "VIDEO_TS")) ?
                                new DvdExtractor() as ChapterExtractor :
                                File.Exists(Path.Combine(input.Text, "VIDEO_TS.IFO")) ?
                                new DvdExtractor() as ChapterExtractor :
                                Directory.Exists(Path.Combine(Path.Combine(input.Text, "BDMV"), "PLAYLIST")) ?
                                new BlurayExtractor() as ChapterExtractor :
                                null;

                            if (ex == null)
                            {
                                throw new Exception("The location was not detected as DVD, or Blu-Ray.");
                            }

                            using (frmStreamSelect frm = new frmStreamSelect(ex))
                            {
                                if (ex is DvdExtractor)
                                {
                                    frm.Text = "Select your Title";
                                }
                                else
                                {
                                    frm.Text = "Select your Playlist";
                                }
                                ex.GetStreams(input.Text);
                                if (frm.ChapterCount == 1 || frm.ShowDialog(this) == DialogResult.OK)
                                {
                                    pgc = frm.SelectedSingleChapterInfo;
                                    if (pgc.FramesPerSecond == 0)
                                    {
                                        pgc.FramesPerSecond = 25.0;
                                    }
                                    if (String.IsNullOrEmpty(pgc.LangCode))
                                    {
                                        pgc.LangCode = "und";
                                    }
                                }
                            }
                            FreshChapterView();
                            updateTimeLine();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }

            if (chapterListView.Items.Count != 0)
            {
                chapterListView.Items[0].Selected = true;
            }
        }
Пример #10
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            ChapterInfo    pgc      = new ChapterInfo();
            List <Chapter> chapters = new List <Chapter>();

            pgc.SourceName = location;
            pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location);
            pgc.SourceType = "Blu-Ray";
            pgc.Title      = Path.GetFileNameWithoutExtension(location);

            FileInfo fileInfo = new FileInfo(location);

            byte[] data = File.ReadAllBytes(location);

            string fileType = ASCIIEncoding.ASCII.GetString(data, 0, 8);

            if ((fileType != "MPLS0100" && fileType != "MPLS0200")
                /*|| data[45] != 1*/)
            {
                throw new Exception(string.Format(
                                        "Playlist {0} has an unknown file type {1}.",
                                        fileInfo.Name, fileType));
            }

            List <Clip> chapterClips = GetClips(data);

            pgc.Duration = new TimeSpan((long)(chapterClips.Sum(c => c.Length) * (double)TimeSpan.TicksPerSecond));

            int chaptersIndex =
                ((int)data[12] << 24) +
                ((int)data[13] << 16) +
                ((int)data[14] << 8) +
                ((int)data[15]);

            int chaptersLength =
                ((int)data[chaptersIndex] << 24) +
                ((int)data[chaptersIndex + 1] << 16) +
                ((int)data[chaptersIndex + 2] << 8) +
                ((int)data[chaptersIndex + 3]);

            byte[] chapterData = new byte[chaptersLength];
            Array.Copy(data, chaptersIndex + 4, chapterData, 0, chaptersLength);

            int chapterCount  = ((int)chapterData[0] << 8) + chapterData[1];
            int chapterOffset = 2;

            for (int chapterIndex = 0; chapterIndex < chapterCount; chapterIndex++)
            {
                if (chapterData[chapterOffset + 1] == 1)
                {
                    int streamFileIndex =
                        ((int)chapterData[chapterOffset + 2] << 8) +
                        chapterData[chapterOffset + 3];

                    Clip streamClip = chapterClips[streamFileIndex];

                    long chapterTime =
                        ((long)chapterData[chapterOffset + 4] << 24) +
                        ((long)chapterData[chapterOffset + 5] << 16) +
                        ((long)chapterData[chapterOffset + 6] << 8) +
                        ((long)chapterData[chapterOffset + 7]);

                    double chapterSeconds  = (double)chapterTime / 45000D;
                    double relativeSeconds = chapterSeconds - streamClip.TimeIn + streamClip.RelativeTimeIn;
                    chapters.Add(new Chapter()
                    {
                        Name = "Chapter " + (chapterIndex + 1).ToString("D2"),//string.Empty,
                        Time = new TimeSpan((long)(relativeSeconds * (double)TimeSpan.TicksPerSecond))
                    });
                }
                chapterOffset += 14;
            }
            pgc.Chapters = chapters;

            MediaInfoFile oInfo = new MediaInfoFile(pgc.SourceName);

            pgc.FramesPerSecond = oInfo.VideoInfo.FPS;

            OnStreamDetected(pgc);
            OnChaptersLoaded(pgc);
            OnExtractionComplete();
            return(new List <ChapterInfo>()
            {
                pgc
            });
        }
Пример #11
0
 public frmStreamSelect(ChapterExtractor extractor) : this(extractor, SelectionMode.One)
 {
 }
Пример #12
0
        public override List <ChapterInfo> GetStreams(string location)
        {
            List <ChapterInfo> pgcs = new List <ChapterInfo>();
            XDocument          doc  = XDocument.Load(location);
            XNamespace         ns   = "http://www.dvdforum.org/2005/HDDVDVideo/Playlist";

            foreach (XElement ts in doc.Element(ns + "Playlist").Elements(ns + "TitleSet"))
            {
                float timeBase = GetFps((string)ts.Attribute("timeBase"));
                float tickBase = GetFps((string)ts.Attribute("tickBase"));
                foreach (XElement title in ts.Elements(ns + "Title").Where(t => t.Element(ns + "ChapterList") != null))
                {
                    ChapterInfo    pgc      = new ChapterInfo();
                    List <Chapter> chapters = new List <Chapter>();
                    pgc.SourceName      = location;
                    pgc.SourceHash      = ChapterExtractor.ComputeMD5Sum(location);
                    pgc.SourceType      = "HD-DVD";
                    pgc.FramesPerSecond = 24D;
                    OnStreamDetected(pgc);

                    int tickBaseDivisor = (int?)title.Attribute("tickBaseDivisor") ?? 1;
                    pgc.Duration = GetTimeSpan((string)title.Attribute("titleDuration"), timeBase, tickBase, tickBaseDivisor);
                    string titleName = Path.GetFileNameWithoutExtension(location);
                    if (title.Attribute("id") != null)
                    {
                        titleName = (string)title.Attribute("id");
                    }
                    if (title.Attribute("displayName") != null)
                    {
                        titleName = (string)title.Attribute("displayName");
                    }
                    pgc.Title = titleName;
                    int count = 0;
                    foreach (XElement chapter in title.Element(ns + "ChapterList").Elements(ns + "Chapter"))
                    {
                        if (string.IsNullOrEmpty((string)chapter.Attribute("displayName")))
                        {
                            chapters.Add(new Chapter()
                            {
                                Name = "Chapter " + (count + 1).ToString("D2"),
                                Time = GetTimeSpan((string)chapter.Attribute("titleTimeBegin"), timeBase, tickBase, tickBaseDivisor)
                            });
                        }
                        else
                        {
                            chapters.Add(new Chapter()
                            {
                                Name = (string)chapter.Attribute("displayName"),
                                Time = GetTimeSpan((string)chapter.Attribute("titleTimeBegin"), timeBase, tickBase, tickBaseDivisor)
                            });
                        }
                        count++;
                    }
                    pgc.Chapters = chapters;
                    OnChaptersLoaded(pgc);
                    //pgc.ChangeFps(24D / 1.001D);
                    pgcs.Add(pgc);
                }
            }
            pgcs = pgcs.OrderByDescending(p => p.Duration).ToList();
            OnExtractionComplete();
            return(pgcs);
        }
Пример #13
0
        private void btInput_Click(object sender, EventArgs e)
        {
            if (rbFromFile.Checked)
            {
                openFileDialog.Filter      = "IFO files (*.ifo)|*.ifo|MKV files (*.mkv)|*.mkv|MPLS files (*.mpls)|*.mpls|Text files (*.txt)|*.txt|All supported files (*.ifo,*.mkv,*.mpls,*.txt)|*.ifo;*.mkv;*.mpls;*.txt";
                openFileDialog.FilterIndex = 5;

                if (this.openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    input.Text = openFileDialog.FileName;

                    if (input.Text.ToLowerInvariant().EndsWith("ifo"))
                    {
                        ChapterExtractor ex = new DvdExtractor();
                        using (frmStreamSelect frm = new frmStreamSelect(ex))
                        {
                            if (ex is DvdExtractor)
                            {
                                frm.Text = "Select your PGC";
                            }
                            else
                            {
                                frm.Text = "Select your Playlist";
                            }
                            ex.GetStreams(input.Text);
                            if (frm.ChapterCount <= 1 || frm.ShowDialog(this) == DialogResult.OK)
                            {
                                if (frm.ChapterCount == 0)
                                {
                                    if (MainForm.Instance.Settings.ChapterCreatorMinimumLength > 0)
                                    {
                                        MessageBox.Show("No titles found. Please try to reduce the \"Minimum title length\"");
                                    }
                                    else
                                    {
                                        MessageBox.Show("No titles found.");
                                    }
                                    return;
                                }
                                else
                                {
                                    pgc = frm.SelectedSingleChapterInfo;
                                    if (pgc.FramesPerSecond == 0)
                                    {
                                        MediaInfoFile oInfo = new MediaInfoFile(input.Text);
                                        pgc.FramesPerSecond = oInfo.VideoInfo.FPS;
                                    }
                                    if (String.IsNullOrEmpty(pgc.LangCode))
                                    {
                                        pgc.LangCode = "und";
                                    }
                                }
                            }
                        }
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else if (input.Text.ToLowerInvariant().EndsWith("mpls"))
                    {
                        ChapterExtractor ex = new MplsExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else if (input.Text.ToLowerInvariant().EndsWith("txt"))
                    {
                        ChapterExtractor ex = new TextExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else if (input.Text.ToLowerInvariant().EndsWith("mkv"))
                    {
                        ChapterExtractor ex = new MkvExtractor();
                        pgc = ex.GetStreams(input.Text)[0];
                        FreshChapterView();
                        updateTimeLine();
                    }
                    else
                    {
                        MessageBox.Show("The input file is not supported.");
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                using (FolderBrowserDialog d = new FolderBrowserDialog())
                {
                    d.ShowNewFolderButton = false;
                    d.Description         = "Select DVD, BluRay disc or folder.";
                    if (d.ShowDialog() == DialogResult.OK)
                    {
                        input.Text = d.SelectedPath;
                        try
                        {
                            ChapterExtractor ex =
                                Directory.Exists(Path.Combine(input.Text, "VIDEO_TS")) ?
                                new DvdExtractor() as ChapterExtractor :
                                File.Exists(Path.Combine(input.Text, "VIDEO_TS.IFO")) ?
                                new DvdExtractor() as ChapterExtractor :
                                Directory.Exists(Path.Combine(Path.Combine(input.Text, "BDMV"), "PLAYLIST")) ?
                                new BlurayExtractor() as ChapterExtractor :
                                null;

                            if (ex == null)
                            {
                                MessageBox.Show("The input folder is not supported.");
                                return;
                            }

                            using (frmStreamSelect frm = new frmStreamSelect(ex))
                            {
                                if (ex is DvdExtractor)
                                {
                                    frm.Text = "Select your Title";
                                }
                                else
                                {
                                    frm.Text = "Select your Playlist";
                                }
                                ex.GetStreams(input.Text);
                                if (frm.ChapterCount <= 1 || frm.ShowDialog(this) == DialogResult.OK)
                                {
                                    if (frm.ChapterCount == 0)
                                    {
                                        if (MainForm.Instance.Settings.ChapterCreatorMinimumLength > 0)
                                        {
                                            MessageBox.Show("No titles found. Please try to reduce the \"Minimum title length\"");
                                        }
                                        else
                                        {
                                            MessageBox.Show("No titles found.");
                                        }
                                        return;
                                    }
                                    else
                                    {
                                        pgc = frm.SelectedSingleChapterInfo;
                                        if (pgc.FramesPerSecond == 0)
                                        {
                                            MediaInfoFile oInfo = new MediaInfoFile(input.Text);
                                            pgc.FramesPerSecond = oInfo.VideoInfo.FPS;
                                        }
                                        if (String.IsNullOrEmpty(pgc.LangCode))
                                        {
                                            pgc.LangCode = "und";
                                        }
                                    }
                                }
                            }
                            FreshChapterView();
                            updateTimeLine();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (chapterListView.Items.Count != 0)
            {
                chapterListView.Items[0].Selected = true;
            }

            if (pgc.FramesPerSecond > 0)
            {
                fpsChooser.Value = (decimal)pgc.FramesPerSecond;
                bFPSKnown        = true;
            }
            else
            {
                bFPSKnown = false;
            }

            string path = String.Empty;

            if (Directory.Exists(MainForm.Instance.Settings.DefaultOutputDir) && FileUtil.IsDirWriteable(MainForm.Instance.Settings.DefaultOutputDir))
            {
                path = MainForm.Instance.Settings.DefaultOutputDir;
            }
            else if (!String.IsNullOrEmpty(input.Text) && Directory.Exists(Path.GetDirectoryName(input.Text)) && FileUtil.IsDirWriteable(Path.GetDirectoryName(input.Text)))
            {
                path = Path.GetDirectoryName(input.Text);
            }

            string file = String.Empty;

            if (String.IsNullOrEmpty(Path.GetFileNameWithoutExtension(input.Text)))
            {
                file = "Chapter Information.txt";
            }
            else
            {
                file = Path.GetFileNameWithoutExtension(input.Text) + " - Chapter Information.txt";
            }
            if (rbXML.Checked)
            {
                Path.ChangeExtension(file, "xml");
            }
            else if (rbQPF.Checked)
            {
                Path.ChangeExtension(file, "qpf");
            }

            if (String.IsNullOrEmpty(path))
            {
                output.Text = file;
            }
            else
            {
                output.Text = Path.Combine(path, file);
            }
        }
Пример #14
0
        public frmStreamSelect(string strFileOrFolderInput, SelectionMode selectionMode)
        {
            InitializeComponent();

            listBox1.Height = MainForm.Instance.Settings.DPIRescale(238);
            btnOK.BringToFront();
            btnCancel.BringToFront();

            listBox1.SelectionMode = selectionMode;
            arrChapterInfo         = new List <ChapterInfo>();

            extractor = GetExtractor(strFileOrFolderInput);
            if (extractor == null)
            {
                return;
            }

            if (minimumTitleLength.Maximum >= MainForm.Instance.Settings.ChapterCreatorMinimumLength &&
                minimumTitleLength.Minimum <= MainForm.Instance.Settings.ChapterCreatorMinimumLength)
            {
                minimumTitleLength.Value = MainForm.Instance.Settings.ChapterCreatorMinimumLength;
            }
            else
            {
                minimumTitleLength.Value = 900;
            }

            extractor.StreamDetected += (sender, arg) =>
            {
                arrChapterInfo.Add(arg.ProgramChain);
            };
            extractor.ChaptersLoaded += (sender, arg) =>
            {
                for (int i = 0; i < arrChapterInfo.Count; i++)
                {
                    if (arrChapterInfo[i].SourceFilePath == arg.ProgramChain.SourceFilePath)
                    {
                        arrChapterInfo[i] = arg.ProgramChain;
                        break;
                    }
                }
            };
            extractor.ExtractionComplete += (sender, arg) =>
            {
                if (MainForm.Instance.Settings.ChapterCreatorSortString.Equals("chapter"))
                {
                    btnSortChapter.Checked = true;
                }
                else if (MainForm.Instance.Settings.ChapterCreatorSortString.Equals("name"))
                {
                    btnSortName.Checked = true;
                }
                else
                {
                    btnSortDuration.Checked = true;
                }
                rbShowAll.Text = "show all (" + TitleCount + " in total)";
            };

            extractor.GetStreams(strFileOrFolderInput);
        }