예제 #1
0
        /// <summary>
        /// Returns detailed information for a single <see cref="OmDbEpisode"/> with given <paramref name="id"/>. This method caches request
        /// to same episodes using the cache path given in <see cref="OmDbApiV1"/> constructor.
        /// </summary>
        /// <param name="id">IMDB id of series</param>
        /// <param name="season">Season number</param>
        /// <param name="episode">Episode number</param>
        /// <returns>Episode information</returns>
        public async Task <OmDbEpisode> GetSeriesEpisodeAsync(string id, int season, int episode, bool cacheOnly)
        {
            string      cache       = CreateAndGetCacheName(id, string.Format("Season{0}_Episode{1}", season, episode));
            OmDbEpisode returnValue = null;

            if (!string.IsNullOrEmpty(cache) && File.Exists(cache))
            {
                returnValue = await _downloader.ReadCacheAsync <OmDbEpisode>(cache).ConfigureAwait(false);
            }
            else
            {
                if (cacheOnly)
                {
                    return(null);
                }
                string url = GetUrl(URL_GETIMDBIDEPISODE, 0, true, true, id, season, episode);
                returnValue = await _downloader.DownloadAsync <OmDbEpisode>(url, cache).ConfigureAwait(false);
            }
            if (returnValue == null)
            {
                return(null);
            }
            if (returnValue.ResponseValid == false)
            {
                return(null);
            }
            if (returnValue != null)
            {
                returnValue.AssignProperties();
            }
            return(returnValue);
        }