Ejemplo n.º 1
0
        private Models.Movie TryIdentify(AnalyzedItem item, out float matchAccuracy)
        {
            Log.DebugFormat("Querying remote: {0} ({1})", item.Title, item.Year);
            IEnumerable <string> tokens = new[] { item.Title };
            var matches = new List <Movie>();

            foreach (var token in tokens)
            {
                var results = _apiClient.SearchMovieAsync(token).Result;

                Log.Debug($"Got {results.Results.Count:N0} of {results.TotalResults:N0} results");
                foreach (var result in results.Results)
                {
                    Log.DebugFormat(" => {0}| {1} / {2} ({3})", result.Id, result.Title, result.OriginalTitle,
                                    result.ReleaseDate.GetValueOrDefault().Year);


                    var movieTask = _apiClient.GetMovieAsync(result.Id);
                    movieTask.Wait();
                    var movie = movieTask.Result;

                    matches.Add(movie);
                }
            }


            var resChart = matches
                           .Select(x => new { Movie = MapDbItem(x), Match = GetMatch(x, item) })
                           .OrderByDescending(z => z.Match).ToArray();



            var candidate = resChart.FirstOrDefault(x => x.Match >= 0.2f);

            if (candidate != null)
            {
                matchAccuracy = candidate.Match;

                _apiClient.GetConfig();
                candidate.Movie.ImageUri = _apiClient.GetImageUrl("w185", candidate.Movie.PosterPath).ToString();

                var movie = candidate.Movie;
                _db.Push(movie);

                _db.Push(item.Hash, movie.Id);

                return(movie);
            }
            else
            {
                matchAccuracy = 0f;
            }


            return(null);
        }
Ejemplo 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);
        }