예제 #1
0
        public async Task <Episode> getEpisode(string EpisodeName)
        {
            using (HttpClient client = new HttpClient())
            {
                // Url to TVDB
                //Uri url = new Uri("https://api.thetvdb.com/episodes/75897");
                //Uri url = new Uri("https://api.thetvdb.com/series/75897/episodes/query?airedSeason=23&airedEpisode=5");     // South Park
                Uri url = new Uri("https://api.thetvdb.com/series/75978/episodes/query?airedSeason=18");   // Family Guy

                // Set Accept request header
                client.DefaultRequestHeaders.Add("Accept", "application/json");
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Token.token);

                // Setup request message with json apikey and content-type header
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);

                // Send via post, get response, read content into string, check to be sure it was OK
                HttpResponseMessage resp = await client.SendAsync(request);

                var respString = await resp.Content.ReadAsStringAsync();

                if (resp.ReasonPhrase != "OK")
                {
                    throw new Exception(resp.ReasonPhrase);
                }

                // Deserialize string into token
                RarEpisode rarEpisode = new RarEpisode();
                rarEpisode = JsonConvert.DeserializeObject <RarEpisode>(respString);
                Episode episode = rarEpisode.convertToEpisode(0);

                return(episode);
            }
        }
예제 #2
0
        // Gets a series from the API

        public async Task <List <Episode> > getEpisodeList(int seriesId)
        {
            List <Episode> episodeList = new List <Episode>();
            long           nextPage    = 1;

            using (HttpClient client = new HttpClient())
            {
                do
                {
                    // Url to TVDB
                    //Uri url = new Uri("https://api.thetvdb.com/episodes/75897");
                    //Uri url = new Uri("https://api.thetvdb.com/series/75897/episodes/query?airedSeason=23&airedEpisode=5");     // South Park
                    //Uri url = new Uri("https://api.thetvdb.com/series/seriesId/episodes/query?airedSeason=18");   // Family Guy
                    //Uri url = new Uri("https://api.thetvdb.com/series/75897/episodes/query?airedSeason=23");   // South Park S23
                    //Uri url = new Uri("https://api.thetvdb.com/series/276562/episodes/query?airedSeason=6");   // Power
                    Uri url = new Uri($"https://api.thetvdb.com/series/{seriesId}/episodes?page={nextPage}");   // 100 episoder

                    // Set Accept request header
                    client.DefaultRequestHeaders.Add("Accept", "application/json");
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Token.token);

                    // Setup request message with json apikey and content-type header
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);

                    // Send via post, get response, read content into string, check to be sure it was OK
                    HttpResponseMessage resp = await client.SendAsync(request);

                    var respString = await resp.Content.ReadAsStringAsync();

                    if (resp.ReasonPhrase != "OK")
                    {
                        throw new Exception(resp.ReasonPhrase);
                    }

                    // Deserialize string into token
                    RarEpisode rarEpisode = new RarEpisode();
                    rarEpisode = JsonConvert.DeserializeObject <RarEpisode>(respString);

                    for (int i = 0; i < rarEpisode.data.Count; i++)
                    {
                        episodeList.Add(rarEpisode.convertToEpisode(i));
                    }

                    // Sets nextPage int to check if there are more pages with more episodes
                    if (rarEpisode.links.next != null)
                    {
                        nextPage = (long)rarEpisode.links.next;
                    }
                    else
                    {
                        nextPage = 0;
                    }
                } while (nextPage != 0);


                return(episodeList);
            }
        }