Example #1
0
        public async Task <FindContainer> FindByExternalIdAsync(
            string externalId,
            FindExternalSource source,
            string language,
            CancellationToken cancellationToken)
        {
            var key = $"find-{source.ToString()}-{externalId.ToString(CultureInfo.InvariantCulture)}-{language}";

            if (_memoryCache.TryGetValue(key, out FindContainer result))
            {
                return(result);
            }

            await EnsureClientConfigAsync().ConfigureAwait(false);

            result = await _tmDbClient.FindAsync(
                source,
                externalId,
                TmdbUtils.NormalizeLanguage(language),
                cancellationToken).ConfigureAwait(false);

            if (result != null)
            {
                _memoryCache.Set(key, result, TimeSpan.FromHours(CacheDurationInHours));
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// FindAsync movies, people and tv shows by an external id.
        /// The following trypes can be found based on the specified external id's
        /// - Movies: Imdb
        /// - People: Imdb, FreeBaseMid, FreeBaseId, TvRage
        /// - TV Series: Imdb, FreeBaseMid, FreeBaseId, TvRage, TvDb
        /// </summary>
        /// <param name="source">The source the specified id belongs to</param>
        /// <param name="id">The id of the object you wish to located</param>
        /// <returns>A list of all objects in TMDb that matched your id</returns>
        /// <param name="cancellationToken">A cancellation token</param>
        public async Task <FindContainer> FindAsync(FindExternalSource source, string id, CancellationToken cancellationToken = default(CancellationToken))
        {
            RestRequest req = _client.Create("find/{id}");

            req.AddUrlSegment("id", WebUtility.UrlEncode(id));

            req.AddParameter("external_source", source.GetDescription());

            RestResponse <FindContainer> resp = await req.ExecuteGet <FindContainer>(cancellationToken).ConfigureAwait(false);

            return(resp);
        }
Example #3
0
        /// <summary>
        /// Find movies, people and tv shows by an external id.
        /// The following trypes can be found based on the specified external id's
        /// - Movies: Imdb
        /// - People: Imdb, FreeBaseMid, FreeBaseId, TvRage
        /// - TV Series: Imdb, FreeBaseMid, FreeBaseId, TvRage, TvDb
        /// </summary>
        /// <param name="source">The source the specified id belongs to</param>
        /// <param name="id">The id of the object you wish to located</param>
        /// <returns>A list of all objects in TMDb that matched your id</returns>
        public FindContainer Find(FindExternalSource source, string id)
        {
            RestRequest req = new RestRequest("find/{id}");

            req.AddUrlSegment("id", HttpUtility.UrlEncode(id));

            req.AddParameter("external_source", source.GetDescription());

            IRestResponse <FindContainer> resp = _client.Get <FindContainer>(req);

            return(resp.Data);
        }
Example #4
0
        /// <summary>
        /// Find movies, people and tv shows by an external id.
        /// The following trypes can be found based on the specified external id's
        /// - Movies: Imdb
        /// - People: Imdb, FreeBaseMid, FreeBaseId, TvRage
        /// - TV Series: Imdb, FreeBaseMid, FreeBaseId, TvRage, TvDb
        /// </summary>
        /// <param name="source">The source the specified id belongs to</param>
        /// <param name="id">The id of the object you wish to located</param>
        /// <returns>A list of all objects in TMDb that matched your id</returns>
        public FindContainer Find(FindExternalSource source, string id)
        {
            RestRequest req = new RestRequest("find/{id}");

            if (source == FindExternalSource.FreeBaseId || source == FindExternalSource.FreeBaseMid)
                // No url encoding for freebase Id's (they include /-slashes)
                req.AddUrlSegment("id", id);
            else
                req.AddUrlSegment("id", HttpUtility.UrlEncode(id));

            req.AddParameter("external_source", source.GetDescription());

            IRestResponse<FindContainer> resp = _client.Get<FindContainer>(req);

            return resp.Data;
        }
Example #5
0
        /// <summary>
        /// Find movies, people and tv shows by an external id.
        /// The following trypes can be found based on the specified external id's
        /// - Movies: Imdb
        /// - People: Imdb, FreeBaseMid, FreeBaseId, TvRage
        /// - TV Series: Imdb, FreeBaseMid, FreeBaseId, TvRage, TvDb
        /// </summary>
        /// <param name="source">The source the specified id belongs to</param>
        /// <param name="id">The id of the object you wish to located</param>
        /// <returns>A list of all objects in TMDb that matched your id</returns>
        public async Task<FindContainer> Find(FindExternalSource source, string id)
        {
            RestRequest req = _client.Create("find/{id}");

            if (source == FindExternalSource.FreeBaseId || source == FindExternalSource.FreeBaseMid)
                // No url encoding for freebase Id's (they include /-slashes)
                req.AddUrlSegment("id", id);
            else
                req.AddUrlSegment("id", WebUtility.UrlEncode(id));

            req.AddParameter("external_source", source.GetDescription());

            RestResponse<FindContainer> resp = await req.ExecuteGet<FindContainer>().ConfigureAwait(false);

            return resp;
        }
Example #6
0
        /// <summary>
        /// FindAsync movies, people and tv shows by an external id.
        /// The following types can be found based on the specified external id's
        /// - Movies: Imdb
        /// - People: Imdb, FreeBaseMid, FreeBaseId, TvRage
        /// - TV Series: Imdb, FreeBaseMid, FreeBaseId, TvRage, TvDb
        /// </summary>
        /// <param name="source">The source the specified id belongs to</param>
        /// <param name="id">The id of the object you wish to located</param>
        /// <returns>A list of all objects in TMDb that matched your id</returns>
        /// <param name="language">If specified the api will attempt to return a localized result. ex: en,it,es.</param>
        /// <param name="cancellationToken">A cancellation token</param>
        public async Task <FindContainer> FindAsync(FindExternalSource source, string id, string language, CancellationToken cancellationToken = default)
        {
            RestRequest req = _client.Create("find/{id}");

            req.AddUrlSegment("id", WebUtility.UrlEncode(id));
            req.AddParameter("external_source", source.GetDescription());

            language ??= DefaultLanguage;
            if (!string.IsNullOrEmpty(language))
            {
                req.AddParameter("language", language);
            }

            FindContainer resp = await req.GetOfT <FindContainer>(cancellationToken).ConfigureAwait(false);

            return(resp);
        }
Example #7
0
        /// <summary>
        /// Find movies, people and tv shows by an external id.
        /// The following trypes can be found based on the specified external id's
        /// - Movies: Imdb
        /// - People: Imdb, FreeBaseMid, FreeBaseId, TvRage
        /// - TV Series: Imdb, FreeBaseMid, FreeBaseId, TvRage, TvDb
        /// </summary>
        /// <param name="source">The source the specified id belongs to</param>
        /// <param name="id">The id of the object you wish to located</param>
        /// <returns>A list of all objects in TMDb that matched your id</returns>
        public FindContainer Find(FindExternalSource source, string id)
        {
            RestRequest req = new RestRequest("find/{id}");

            if (source == FindExternalSource.FreeBaseId || source == FindExternalSource.FreeBaseMid)
            {
                // No url encoding for freebase Id's (they include /-slashes)
                req.AddUrlSegment("id", id);
            }
            else
            {
                req.AddUrlSegment("id", HttpUtility.UrlEncode(id));
            }

            req.AddParameter("external_source", source.GetDescription());

            IRestResponse <FindContainer> resp = _client.Get <FindContainer>(req);

            return(resp.Data);
        }
Example #8
0
        /// <summary>
        /// FindAsync movies, people and tv shows by an external id.
        /// The following trypes can be found based on the specified external id's
        /// - Movies: Imdb
        /// - People: Imdb, FreeBaseMid, FreeBaseId, TvRage
        /// - TV Series: Imdb, FreeBaseMid, FreeBaseId, TvRage, TvDb
        /// </summary>
        /// <param name="source">The source the specified id belongs to</param>
        /// <param name="id">The id of the object you wish to located</param>
        /// <returns>A list of all objects in TMDb that matched your id</returns>
        public async Task <FindContainer> FindAsync(FindExternalSource source, string id)
        {
            RestRequest req = _client.Create("find/{id}");

            if (source == FindExternalSource.FreeBaseId || source == FindExternalSource.FreeBaseMid)
            {
                // No url encoding for freebase Id's (they include /-slashes)
                req.AddUrlSegment("id", id);
            }
            else
            {
                req.AddUrlSegment("id", WebUtility.UrlEncode(id));
            }

            req.AddParameter("external_source", source.GetDescription());

            RestResponse <FindContainer> resp = await req.ExecuteGet <FindContainer>().ConfigureAwait(false);

            return(resp);
        }
Example #9
0
 /// <summary>
 /// FindAsync movies, people and tv shows by an external id.
 /// The following types can be found based on the specified external id's
 /// - Movies: Imdb
 /// - People: Imdb, FreeBaseMid, FreeBaseId, TvRage
 /// - TV Series: Imdb, FreeBaseMid, FreeBaseId, TvRage, TvDb
 /// </summary>
 /// <param name="source">The source the specified id belongs to</param>
 /// <param name="id">The id of the object you wish to located</param>
 /// <returns>A list of all objects in TMDb that matched your id</returns>
 /// <param name="cancellationToken">A cancellation token</param>
 public Task <FindContainer> FindAsync(FindExternalSource source, string id, CancellationToken cancellationToken = default)
 {
     return(FindAsync(source, id, null, cancellationToken));
 }