Exemplo n.º 1
0
        public int Scan(MovideoSettings settings)
        {
            var count = 0;
            var index = 0;

            var files      = _fileScanner.Scan().ToArray();
            var totalItems = files.Length;


            foreach (var file in files)
            {
                index++;
                OnProgressChanged(index, totalItems);

                var item = _analyzer.Analyze(file);
                if (!item.IsKnown)
                {
                    float accuracy;
                    var   res = TryIdentify(item, out accuracy);
                    if (res != null)
                    {
                        var args = new MatchFoundEventArgs(item, res, accuracy);
                        OnMatchFound(args);

                        if (args.Cancel)
                        {
                            break;
                        }

                        if (args.IsMatch == true)
                        {
                            DoRename(args, settings);

                            UpdateItem(item, res);
                            count++;
                        }
                    }
                }
                else
                {
                    float accuracy;
                    var   movieId = _db.GetMovieIdFor(item);
                    var   movie   = _db.GetMovie(movieId.Value);
                    item.Title = movie.Title;
                    item.Year  = movie.Year;

                    var res  = TryIdentify(item, out accuracy);
                    var args = new MatchFoundEventArgs(item, res, 1);
                    DoRename(args, settings);
                }
            }

            return(count);
        }
Exemplo n.º 2
0
        public AnalyzedItem Analyze(FileInfo file)
        {
            Log.DebugFormat("Analyzing: {0}", file.Name);

            var item = new AnalyzedItem(file);

            var fname   = item.Path.FullName;
            var cleaned = MovieTitleCleaner.Clean(fname);

            item.Title    = cleaned.Title;
            item.SubTitle = cleaned.SubTitle;
            item.Year     = cleaned.Year;

            var mf       = new MediaInfoDotNet.MediaFile(file.FullName);
            var duration = TimeSpan.FromMilliseconds(mf.General.Duration);

            item.Duration = duration;

            var fref = new FileRef(file);

            if (_db.HasHash(fref))
            {
                var hash = _db.GetHashFor(fref);
                Log.DebugFormat("Hash Found: {0}", hash);

                item.Hash = hash;
            }
            else
            {
                var hash = QuickHash(file);
                Log.DebugFormat("Hash Computed: {0}", hash);

                _db.Push(fref, hash);
                item.Hash = hash;
            }

            if (_db.HasMatch(item))
            {
                item.IsKnown = true;
                item.MovieId = _db.GetMovieIdFor(item);

                Log.DebugFormat("Match Found: {0} (MovieId)", item.MovieId);
            }

            return(item);
        }