Esempio n. 1
0
 private static string SafeMovieFileName(Movie movie)
 {
     string safeTitle = Regex.Replace(movie.Title, @"[^a-z0-9_-]", "_", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant).Trim();
     return string.Format("{0}_{1}.jpg", safeTitle, movie.ImdbId);
 }
Esempio n. 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Movies EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMovies(Movie movie)
 {
     base.AddObject("Movies", movie);
 }
Esempio n. 3
0
 /// <summary>
 /// Create a new Movie object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="score">Initial value of the Score property.</param>
 /// <param name="year">Initial value of the Year property.</param>
 /// <param name="imdbQueried">Initial value of the ImdbQueried property.</param>
 /// <param name="addedAt">Initial value of the AddedAt property.</param>
 /// <param name="imdbQueryFailCount">Initial value of the ImdbQueryFailCount property.</param>
 public static Movie CreateMovie(global::System.Int32 id, global::System.String title, global::System.Int32 score, global::System.Int16 year, global::System.Boolean imdbQueried, global::System.DateTime addedAt, global::System.Int32 imdbQueryFailCount)
 {
     Movie movie = new Movie();
     movie.Id = id;
     movie.Title = title;
     movie.Score = score;
     movie.Year = year;
     movie.ImdbQueried = imdbQueried;
     movie.AddedAt = addedAt;
     movie.ImdbQueryFailCount = imdbQueryFailCount;
     return movie;
 }
        public bool UpdateMovieFromDataSource(Movie movie)
        {
            if (string.IsNullOrEmpty(movie.ImdbId) && (movie.TmdbId == null || movie.TmdbId.Value == 0))
                throw new ArgumentNullException("No IMDB id!");

            Task<int> getScores = null;

            try
            {
                try
                {
                    //Overview: if we have an IMDB, start fetching the ImdbApi score asynchronously, then fetch Tmdb data.
                    //After Tmdb data fetch, if either we did not have an imdb id beforehand, of if the imdbid changed, update the score from imdb synchronously.

                    if (!string.IsNullOrEmpty(movie.ImdbId))
                        getScores = Task.Factory.StartNew<int>(() => Imdb.ImdbApi.QuickScoreFetcher(movie.ImdbId));
                    var requestedImdbId = movie.ImdbId;

                    var ret = UpdateMovieFromTmdb(movie);

                    if (getScores != null)
                    {
                        try
                        {
                            movie.Score = getScores.Result;
                            getScores.Dispose();
                            getScores = null;
                        }
                        catch (AggregateException ex)
                        {
                            _log.Error("UpdateMovieFromDataSource GetMovieScoresFromImdbAsync: {0}", ex.InnerException.Message);
                            movie.Score = -2;
                        }
                    }

                    if ((getScores == null || movie.ImdbId != requestedImdbId) && !string.IsNullOrEmpty(movie.ImdbId))
                    {
                        try
                        {
                            _log.Debug("Fetching imdb score synchronously. MovieId {0} Old ImdbId {1} New ImdbId {2}", movie.Id, requestedImdbId, movie.ImdbId);
                            movie.Score = Imdb.ImdbApi.QuickScoreFetcher(movie.ImdbId);
                        }
                        catch (Exception ex)
                        {
                            _log.Error("UpdateMovieFromDataSource Sync QuickScoreFetcher failed with: {0}", ex.InnerException.Message);
                            movie.Score = -3;
                        }
                    }

                    return ret;
                }
                catch (TmdbNotConfiguredException)
                {
                    return UpdateMovieFromImdb(movie);
                }
            }
            catch (Exception ex)
            {
                _log.Error("{0} update failure: {1}", movie.ImdbId, ex.ToString()); //This should not update fail count...
                return !(ex is WebException); //If webexception, return false to indicate break of loop
            }
            finally
            {
                if (getScores != null) //We need to observe any exceptions, thus this code.
                {
                    getScores.Wait(5000);
                    try
                    {
                        var hm = getScores.Result;
                    }
                    catch
                    {
                        _log.Error("In finally, getscores.Result failed...");
                    }
                }
            }
        }
Esempio n. 5
0
 public MovieViewModel(Movie movie)
 {
     _movie = movie;
     _youtubeTrailerUrl = new Lazy<string>(TryGetYoutubeId);
 }
        private bool UpdateMovieFromTmdb(Movie movie)
        {
            var tmdb = new EpiTmdbApi();
            var result = (movie.TmdbId.HasValue && movie.TmdbId.Value > 0) ?
                tmdb.QueryMovieByTmdbId(movie.TmdbId.Value) :
                tmdb.QueryMovieByImdbId(movie.ImdbId);

            if (result != null)
            {
                movie.ImdbQueried = true;
                movie.Plot = result.Plot;
                movie.Title = result.Title;
                movie.Year = result.Year;
                movie.Score = result.Score;
                movie.ImageUrl = result.Poster;
                movie.Runtime = result.Runtime;
                movie.Homepage = result.Homepage;
                movie.SetGenres(result.Genres);
                movie.TrailerUrl = result.TrailerUrl;
                if (!string.IsNullOrEmpty(result.ImdbId))
                    movie.ImdbId = result.ImdbId;

                movie.Casts.ToList().ForEach(_movieSystemService.DbEntities.DeleteObject);
                foreach (var cast in result.Casts)
                    movie.AddCastMember(cast.Job, cast.Name, cast.ImdbId, cast.TmdbId, cast.SortOrder, cast.RoleName);

                movie.ImdbQueryFailCount = 0;
                movie.TmdbId = result.TmdbId;
                _log.Info("TmdbApi successful query {0}({1}) : {2}", movie.TmdbId, movie.ImdbId, movie.Title);
            }
            else
            {
                _log.Error("TmdbApi FAILED query {0} : {1}", movie.ImdbId, movie.Title);
                movie.ImdbQueryFailCount = movie.ImdbQueryFailCount <= 5 ? 10 : movie.ImdbQueryFailCount + 1;
            }

            return true;
        }
        private bool UpdateMovieFromImdb(Movie movie)
        {
            var imdbResult = Imdb.ImdbApi.GetInfo(movie.ImdbId);
            if (imdbResult != null)
            {
                movie.ImdbQueried = true;
                movie.Plot = imdbResult.Plot;
                movie.Title = imdbResult.Title;
                movie.Year = short.Parse(imdbResult.Year);
                if (imdbResult.Rating != "N/A")
                    movie.Score = (int) (double.Parse(imdbResult.Rating, CultureInfo.InvariantCulture.NumberFormat)*10.0);
                else
                    movie.Score = -1;
                movie.ImageUrl = imdbResult.Poster;
                movie.Runtime = RuntimeParser(imdbResult.Runtime);

                UpdateGenresInfo(movie, imdbResult.Genre);
                UpdatePeopleInfo(movie, imdbResult);
                movie.ImdbQueryFailCount = 0;
                _log.Info("ImdbApi successful query {0} : {1}", movie.ImdbId, movie.Title);
            }
            else
            {
                _log.Error("ImdbApi FAILED query {0} : {1}", movie.ImdbId, movie.Title);
                movie.ImdbQueryFailCount += 1;
            }

            return true;
        }
 private void TryFindMovieIdAndUpdateMovie(Movie movie)
 {
     _log.Trace("Trying to find imdb id for " + movie.Title);
     var newImdbId = Imdb.ImdbApi.ImdbIdFinder(movie.Title, movie.Year > 1800 ? (int?)movie.Year : null);
     if (!string.IsNullOrEmpty(newImdbId))
     {
         var newMovie = _movieSystemService.SetImdbIdOnMovie(movie.Id, newImdbId);
         if (!newMovie.ImdbQueried)
             UpdateMovieFromDataSource(newMovie);
     }
 }
 private static void UpdatePeopleInfo(Movie movie, ImdbSearchResult imdbResult)
 {
     throw new NotImplementedException(); //TODO: Will be removed when ImdbApi uses new MovieDataSource thingy
     //movie.SetDirectors(from d in imdbResult.Director.Split(',') let dt = d.Trim() where dt.Length > 0 select dt);
     //movie.SetActors(from d in imdbResult.Actors.Split(',') let dt = d.Trim() where dt.Length > 0 select dt);
     //movie.SetWriters(from d in imdbResult.Writer.Split(',') let dt = d.Trim() where dt.Length > 0 select dt);
 }
Esempio n. 10
0
 private static void UpdateGenresInfo(Movie movie, string genresStr)
 {
     movie.SetGenres(from g in genresStr.Split(',') let trimmed = g.Trim() where trimmed.Length > 0 select trimmed);
 }