Beispiel #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);
        }
Beispiel #2
0
        private static float GetMatch(Movie movie, AnalyzedItem item)
        {
            float res = 0;

            var   dtt    = LevenshteinDistance.ComputeIgnoreCase(item.Title, movie.Title);
            var   dto    = LevenshteinDistance.ComputeIgnoreCase(item.Title, movie.OriginalTitle);
            float score1 = Math.Max(0, 5 - Math.Min(dtt, dto));

            res += score1;

            //if (string.Equals(item.Title, movie.Title, StringComparison.OrdinalIgnoreCase)
            //    || string.Equals(item.Title, movie.OriginalTitle, StringComparison.OrdinalIgnoreCase))
            //{
            //    res += 3;
            //}

            if (!string.IsNullOrEmpty(item.SubTitle))
            {
                var   dst    = LevenshteinDistance.ComputeIgnoreCase(item.SubTitle, movie.Title);
                var   dso    = LevenshteinDistance.ComputeIgnoreCase(item.SubTitle, movie.OriginalTitle);
                float score2 = Math.Max(0, 3 - Math.Min(dst, dso));
                res += score2;
            }

            //if (string.Equals(item.SubTitle, movie.Title, StringComparison.OrdinalIgnoreCase)
            //    || string.Equals(item.SubTitle, movie.OriginalTitle, StringComparison.OrdinalIgnoreCase))
            //{
            //    res += 2;
            //}

            if (LooksLike(item.Year, movie.ReleaseDate))
            {
                res += 3;
            }


            if (item.Duration > TimeSpan.Zero && movie.Runtime.HasValue)
            {
                var mtime = TimeSpan.FromMinutes(movie.Runtime.Value);
                var diff  = Math.Abs(item.Duration.Subtract(mtime).TotalMinutes);
                var score = (int)Math.Max(5 - diff, 0);
                {
                    res += score;
                }
            }
            else
            {
                res += 1;
            }

            return(res / 16);
        }
Beispiel #3
0
 public void UpdateItem(AnalyzedItem item, Models.Movie res)
 {
 }
Beispiel #4
0
 public int?GetMovieIdFor(AnalyzedItem item)
 {
     return(_ctx.MediaBindings.First(x => x.Hash == item.Hash).MovieId);
 }
Beispiel #5
0
 public bool HasMatch(AnalyzedItem item)
 {
     return(_ctx.MediaBindings.Any(x => x.Hash == item.Hash && x.MovieId.HasValue));
 }
Beispiel #6
0
 public MatchFoundEventArgs(AnalyzedItem item, Movie res, float accuracy)
 {
     _item     = item;
     _res      = res;
     _accuracy = accuracy;
 }