Example #1
0
 protected Task <T> GetAsync <T>(string url, string cacheName, bool cacheOnly)
 {
     if (!string.IsNullOrEmpty(cacheName) && File.Exists(cacheName))
     {
         return(Task.FromResult(_downloader.ReadCache <T>(cacheName)));
     }
     if (cacheOnly)
     {
         return(Task.FromResult(default(T)));
     }
     return(_downloader.DownloadAsync <T>(url, cacheName));
 }
        /// <summary>
        /// Returns detailed information for a single <see cref="Movie"/> with given <paramref name="id"/>. This method caches request
        /// to same movies using the cache path given in <see cref="MovieDbApiV3"/> constructor.
        /// </summary>
        /// <param name="id">TMDB id of movie</param>
        /// <param name="language">Language</param>
        /// <returns>Movie information</returns>
        public Movie GetMovie(int id, string language, bool cacheOnly)
        {
            string cache = CreateAndGetCacheName(id, language, "Movie");
            Movie  movie = null;

            if (!string.IsNullOrEmpty(cache) && File.Exists(cache))
            {
                movie = _downloader.ReadCache <Movie>(cache);
            }
            else
            {
                if (cacheOnly)
                {
                    return(null);
                }
                string url = GetUrl(URL_GETMOVIE, language, id);
                movie = _downloader.Download <Movie>(url, cache);
            }
            if (movie != null && movie.Id > 0 && movie.Collection != null && movie.Collection.Id > 0)
            {
                lock (_collectionMovieList)
                {
                    if (!_collectionMovieList.ContainsKey(movie.Collection.Id))
                    {
                        _collectionMovieList.Add(movie.Collection.Id, new List <int>());
                    }
                    if (!_collectionMovieList[movie.Collection.Id].Contains(movie.Id))
                    {
                        _collectionMovieList[movie.Collection.Id].Add(movie.Id);
                    }
                }
            }
            return(movie);
        }