Exemple #1
0
        public void IndexWriteIndexUTF8()
        {
            Indexer indexer = new Indexer("おはよう.mkv");

            Index index = indexer.Index();

            index.WriteIndex("おはよう.ffindex");
        }
Exemple #2
0
        private void buttonConfirm_Click(object sender, EventArgs e)
        {
            var audioFile = boxAudioFile.Text;
            string indexFile;

            try
            {
                if (!File.Exists(audioFile))
                    throw new FileNotFoundException();

                panelIndexingProgress.BringToFront();
                labelIndexingProgress.Text = "Hashing...";

                using (var md5 = MD5.Create())
                using (var stream = File.OpenRead(audioFile))
                {
                    var filename = new UTF8Encoding().GetBytes(Path.GetFileNameWithoutExtension(audioFile));
                    var buffer = new byte[4096];

                    filename.CopyTo(buffer, 0);
                    stream.Read(buffer, filename.Length, 4096 - filename.Length);

                    var hash = BitConverter.ToString(md5.ComputeHash(buffer));
                    indexFile = Path.Combine(Path.GetTempPath(), hash + ".ffindex");
                }

                if (File.Exists(indexFile))
                {
                    try
                    {
                        var index = new Index(indexFile);

                        if (index.BelongsToFile(audioFile))
                        {
                            DialogResult = DialogResult.OK;
                            GeneratedFilter = new DubFilter(audioFile, indexFile, (DubMode)comboDubMode.SelectedIndex);
                            Close();
                            return;
                        }
                    }
                    catch
                    {
                        // ignored
                    }

                    File.Delete(indexFile);
                }

                labelIndexingProgress.Text = "Indexing...";
                progressIndexingProgress.Value = 0;
                progressIndexingProgress.Style = ProgressBarStyle.Continuous;
                _worker = new BackgroundWorker
                {
                    WorkerSupportsCancellation = true,
                    WorkerReportsProgress = true
                };
                _worker.ProgressChanged += (o, args) =>
                {
                    progressIndexingProgress.Value = args.ProgressPercentage;
                };
                _worker.DoWork += (bw, workArgs) =>
                {
                    var indexer = new Indexer(audioFile, Source.Lavf);

                    indexer.UpdateIndexProgress += (ind, updateArgs) =>
                    {
                        _worker.ReportProgress((int) (((double) updateArgs.Current/updateArgs.Total)*100));
                        indexer.CancelIndexing = _worker.CancellationPending;
                    };

                    try
                    {
                        var index = indexer.Index();

                        try
                        {
                            index.GetFirstIndexedTrackOfType(TrackType.Audio);
                        }
                        catch (KeyNotFoundException)
                        {
                            throw new InvalidDataException("That file doesn't have any audio!");
                        }

                        index.WriteIndex(indexFile);

                    }
                    catch (OperationCanceledException)
                    {
                        workArgs.Cancel = true;
                    }
                };
                _worker.RunWorkerCompleted += (o, args) =>
                {
                    this.InvokeIfRequired(() =>
                    {
                        panelIndexingProgress.SendToBack();
                    });

                    if (args.Error != null)
                    {
                        this.InvokeIfRequired(() =>
                        {
                            SetFile(string.Empty);

                            if (
                                MessageBox.Show(args.Error.Message, "ERROR", MessageBoxButtons.OKCancel,
                                    MessageBoxIcon.Error) == DialogResult.Cancel)
                                Close();
                        });
                        return;
                    }

                    if (args.Cancelled)
                    {
                        DialogResult = DialogResult.Cancel;
                    }
                    else
                    {
                        DialogResult = DialogResult.OK;
                        GeneratedFilter = new DubFilter(audioFile, indexFile, (DubMode)comboDubMode.SelectedIndex);
                    }

                    this.InvokeIfRequired(Close);
                };
                _worker.RunWorkerAsync();
            }
            catch (Exception err)
            {
                if (MessageBox.Show(err.Message, "ERROR", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) ==
                    DialogResult.Cancel)
                    Close();
            }
        }
Exemple #3
0
        public void IndexerCancelIndexing()
        {
            Indexer indexer = new Indexer("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv");
            indexer.UpdateIndexProgress += delegate(object sender, IndexingProgressChangeEventArgs e)
            {
                indexer.CancelIndexing = true;
            };

            indexer.Index();
        }
Exemple #4
0
        public void IndexBelongsToFile()
        {
            Indexer indexer = new Indexer("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.mkv");
            indexer.Index().WriteIndex("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.ffindex");

            Index indexFromFile = new Index("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.ffindex");
            Assert.IsTrue(indexFromFile.BelongsToFile("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.mkv"));
            Assert.IsFalse(indexFromFile.BelongsToFile("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv"));
        }
Exemple #5
0
        public void IndexAudioIndex()
        {
            Indexer indexer = new Indexer("h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.mkv");

            List<int> AudioIndexList = new List<int>();
            AudioIndexList.Add(2);
            Index index = indexer.Index(AudioIndexList);

            Assert.AreEqual(1, index.GetFirstTrackOfType(TrackType.Audio));
            Assert.AreEqual(2, index.GetFirstIndexedTrackOfType(TrackType.Audio));
        }
Exemple #6
0
        public void IndexAudioDump()
        {
            Indexer indexer = new Indexer("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv");

            List<int> AudioDumpList = new List<int>();
            AudioDumpList.Add(1);

            indexer.Index(audioDump: AudioDumpList, audioDumpFileName: @"%sourcefile%_track%trackzn%.w64");
        }
Exemple #7
0
        public void IndexAndAPIFunctions()
        {
            Indexer indexer = new Indexer("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.mkv");

            Index index = indexer.Index();

            Assert.AreEqual(Source.Matroska, index.Source);
            Assert.AreEqual(IndexErrorHandling.Abort, index.IndexErrorHandling);
            Assert.AreEqual(1, index.GetFirstTrackOfType(TrackType.Audio));
            Assert.AreEqual(1, index.GetFirstIndexedTrackOfType(TrackType.Audio));

            index.WriteIndex("h264_720p_hp_5.1_3mbps_vorbis_styled_and_unstyled_subs_suzumiya.ffindex");
        }