Esempio n. 1
0
        private void btSearch_Click(object sender, RoutedEventArgs e)
        {
            btSearch.IsEnabled = false;
            edErrors.Text      = string.Empty;

            // Settings
            VFSimplePlayerEngine engine = VFSimplePlayerEngine.DirectShow;

            switch (cbEngine.SelectedIndex)
            {
            case 0:
                engine = VFSimplePlayerEngine.DirectShow;
                break;

            case 1:
                engine = VFSimplePlayerEngine.FFMPEG;
                break;

            case 2:
                engine = VFSimplePlayerEngine.LAV;
                break;
            }

            int indexingTime = 5;

            switch (cbIndexingTime.SelectedIndex)
            {
            case 0:
                indexingTime = 3;
                break;

            case 1:
                indexingTime = 5;
                break;

            case 2:
                indexingTime = 10;
                break;

            case 3:
                indexingTime = 30;
                break;
            }

            List <string> extensions = new List <string>();

            if (cbFormatAVI.IsChecked == true)
            {
                extensions.Add("avi");
            }

            if (cbFormatFLV.IsChecked == true)
            {
                extensions.Add("flv");
            }

            if (cbFormatMKV.IsChecked == true)
            {
                extensions.Add("mkv");
            }

            if (cbFormatMOV.IsChecked == true)
            {
                extensions.Add("mov");
            }

            if (cbFormatMP4.IsChecked == true)
            {
                extensions.Add("mp4");
            }

            if (cbFormatMPG.IsChecked == true)
            {
                extensions.Add("mpg");
            }

            if (cbFormatTS.IsChecked == true)
            {
                extensions.Add("ts");
            }

            if (cbFormatWMV.IsChecked == true)
            {
                extensions.Add("wmv");
            }

            lbStatus.Text = "Step 1: Searching video files";

            List <string> filenames = new List <string>();

            List <VFPFingerPrint> fingerPrints = new List <VFPFingerPrint>();

            foreach (string item in lbSourceFolders.Items)
            {
                filenames.AddRange(FileScanner.SearchVideoInFolder(item, extensions));
            }

            lbStatus.Text = "Step 2: Getting fingerprints for video files";

            int progress = 0;

            foreach (string filename in filenames)
            {
                pbProgress.Value = progress;

                VFPFingerPrint fp    = null;
                string         error = null;

                try
                {
                    var source = new VFPFingerprintSource(filename, engine)
                    {
                        StopTime = TimeSpan.FromSeconds(indexingTime)
                    };

                    fp = VFPAnalyzer.GetComparingFingerprintForVideoFile(source, ErrorCallback);
                }
                catch (Exception ex)
                {
                    edErrors.Text += ex.Message + Environment.NewLine;
                }

                if (fp != null)
                {
                    fingerPrints.Add(fp);
                }

                if (error != null)
                {
                    edErrors.Text += error + Environment.NewLine;
                }

                progress += 100 / filenames.Count;
            }

            pbProgress.Value = 100;

            List <SearchResult> results = new List <SearchResult>();

            results.Clear();
            lbResults.Items.Clear();
            lbStatus.Text = "Step 3: Analyzing data";
            progress      = 0;
            int foundCount = 0;

            List <string> clonesToIgnore = new List <string>();

            foreach (var first in fingerPrints)
            {
                pbProgress.Value = progress;

                if (first == null)
                {
                    continue;
                }

                if (clonesToIgnore.Contains(first.OriginalFilename))
                {
                    continue;
                }

                foreach (var second in fingerPrints)
                {
                    if (second == null)
                    {
                        continue;
                    }

                    if (first.OriginalFilename == second.OriginalFilename)
                    {
                        continue;
                    }

                    int diff = VFPAnalyzer.Compare(first, second, TimeSpan.FromSeconds(slMaxShift.Value));

                    if (diff < slSensitivity.Value * 10)
                    {
                        foundCount++;

                        clonesToIgnore.Add(second.OriginalFilename);

                        var result = new SearchResult()
                        {
                            GroupFile = first.OriginalFilename
                        };
                        result.Clones.Add(second.OriginalFilename);

                        results.Add(result);
                    }
                }

                progress += 100 / fingerPrints.Count;
            }

            pbProgress.Value = 0;

            foreach (var result in results)
            {
                ResultItem item = new ResultItem
                {
                    Text = { Text = result.GroupFile },
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Screenshot          = { Source = Helper.GetImageForFile(result.GroupFile) }
                };

                lbResults.Items.Add(item);

                foreach (var clone in result.Clones)
                {
                    ResultItem item2 = new ResultItem
                    {
                        Text                = { Text = clone },
                        Checked             = { IsChecked = true },
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                        Screenshot          = { Source = Helper.GetImageForFile(clone) }
                    };

                    lbResults.Items.Add(item2);
                }
            }

            lbStatus.Text = "Step 4: Done. " + foundCount + " copies found.";

            btSearch.IsEnabled = true;
        }
        private async void btStart_Click(object sender, RoutedEventArgs e)
        {
            if (cbDebug.IsChecked == true)
            {
                VFPAnalyzer.DebugDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\VisioForge\\MMT\\";
            }

            btStart.IsEnabled = false;

            results.Clear();
            lvResults.Items.Refresh();

            lbStatus.Content = "Step 1: Searching video files";

            VFSimplePlayerEngine engine = VFSimplePlayerEngine.LAV;

            switch (cbEngine.SelectedIndex)
            {
            case 0:
                engine = VFSimplePlayerEngine.DirectShow;
                break;

            case 1:
                engine = VFSimplePlayerEngine.FFMPEG;
                break;

            case 2:
                engine = VFSimplePlayerEngine.LAV;
                break;
            }

            List <string> adList        = new List <string>();
            List <string> broadcastList = new List <string>();

            List <VFPFingerPrint> adVFPList        = new List <VFPFingerPrint>();
            List <VFPFingerPrint> broadcastVFPList = new List <VFPFingerPrint>();

            foreach (string item in lbAdFolders.Items)
            {
                bool isDir = (File.GetAttributes(item) & FileAttributes.Directory) == FileAttributes.Directory;
                if (isDir)
                {
                    adList.AddRange(FileScanner.SearchVideoInFolder(item));
                }
                else
                {
                    adList.Add(item);
                }
            }

            foreach (string item in lbBroadcastFolders.Items)
            {
                bool isDir = (File.GetAttributes(item) & FileAttributes.Directory) == FileAttributes.Directory;
                if (isDir)
                {
                    broadcastList.AddRange(FileScanner.SearchVideoInFolder(item));
                }
                else
                {
                    broadcastList.Add(item);
                }
            }

            lbStatus.Content = "Step 2: Getting fingerprints for ads files";

            int progress = 0;

            foreach (string filename in adList)
            {
                pbProgress.Value = progress;

                var source = new VFPFingerprintSource(filename, engine);
                foreach (var area in _ignoredAreas)
                {
                    source.IgnoredAreas.Add(area);
                }

                VFPFingerPrint fp = _db.GetFingerprint(source);

                if (fp == null)
                {
                    fp = await VFPAnalyzer.GetSearchFingerprintForVideoFileAsync(source, errorDelegate);

                    if (fp == null)
                    {
                        MessageBox.Show("Unable to get fingerprint for the video file: " + filename);
                    }
                    else
                    {
                        _db.Items.Add(fp);
                        AddDBItem(fp);
                    }
                }

                adVFPList.Add(fp);

                progress += 100 / adList.Count;
            }

            pbProgress.Value = 100;

            lbStatus.Content = "Step 3: Getting fingerprints for broadcast files";
            progress         = 0;
            foreach (string filename in broadcastList)
            {
                pbProgress.Value = progress;

                var source = new VFPFingerprintSource(filename, engine);
                foreach (var area in _ignoredAreas)
                {
                    source.IgnoredAreas.Add(area);
                }

                VFPFingerPrint fp = _db.GetFingerprint(source);
                if (fp == null)
                {
                    fp = await VFPAnalyzer.GetSearchFingerprintForVideoFileAsync(source, errorDelegate);

                    if (fp == null)
                    {
                        MessageBox.Show("Unable to get fingerprint for the video file: " + filename);
                        return;
                    }
                    else
                    {
                        _db.Items.Add(fp);
                        AddDBItem(fp);
                    }
                }

                broadcastVFPList.Add(fp);

                progress += 100 / broadcastList.Count;
            }

            pbProgress.Value = 100;

            lbStatus.Content = "Step 4: Analyzing data";
            progress         = 0;
            int foundCount = 0;

            foreach (var broadcast in broadcastVFPList)
            {
                pbProgress.Value = progress;

                foreach (var ad in adVFPList)
                {
                    var positions = await VFPAnalyzer.SearchAsync(ad, broadcast, ad.Duration, (int)slDifference.Value, true);

                    if (positions.Count > 0)
                    {
                        foreach (var pos in positions)
                        {
                            foundCount++;
                            int minutes = (int)(pos.TotalSeconds / 60);
                            int seconds = (int)(pos.TotalSeconds % 60);

                            results.Add(
                                new ResultsViewModel()
                            {
                                Sample   = ad.OriginalFilename,
                                DumpFile = broadcast.OriginalFilename,
                                Position = minutes + ":" + seconds
                            });
                        }
                    }
                }

                progress += 100 / broadcastList.Count;
            }

            pbProgress.Value = 0;

            lvResults.Items.Refresh();

            lbStatus.Content = "Step 5: Done. " + foundCount + " ads found.";

            btStart.IsEnabled = true;
        }