示例#1
0
        private void SearchForEpisode(string EpisodeName, int?SeasonNo, int?EpisodeNo, int maxResults)
        {
            UriBuilder uri = new UriBuilder("http://thetvdb.com/api/" + API_KEY + "/series/" + SeriesID.ToString() + "/all/");

            if (BackDrops == null)
            {
                BackDrops = new List <string>();
            }
            else
            {
                BackDrops.Clear();
            }

            string actors  = "";
            string genres  = "";
            string network = "";
            int    runtime = 0;
            string rating  = "";

            results = new List <TheTVDBDbResult>();


            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.Uri);

            // execute the request
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                //StreamReader reader2 = new StreamReader(response.GetResponseStream());
                //string  tmp = reader2.ReadToEnd();
                //Console.Write(tmp);


                string mirrorpath = "";
                int    typemask   = 0;

                // we will read data via the response stream
                using (Stream resStream = response.GetResponseStream())
                {
                    XmlTextReader reader = new XmlTextReader(resStream);
                    reader.WhitespaceHandling = WhitespaceHandling.None;

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.Name.ToLower() == "series")
                            {
                                while (reader.Read())
                                {
                                    if (reader.NodeType == XmlNodeType.Element)
                                    {
                                        switch (reader.Name.ToLower())
                                        {
                                        case "actors":
                                            actors = GetElementValue(reader).ToString();
                                            break;

                                        case "genre":
                                            genres = GetElementValue(reader);
                                            break;

                                        case "network":
                                            network = GetElementValue(reader);
                                            break;

                                        case "runtime":
                                            int.TryParse(GetElementValue(reader), out runtime);
                                            //runtime = int.Parse(GetElementValue(reader));
                                            break;

                                        case "fanart":
                                            BackDrops.Add("http://images.thetvdb.com/banners/" + GetElementValue(reader));
                                            break;

                                        case "poster":
                                            BackDrops.Add("http://images.thetvdb.com/banners/" + GetElementValue(reader));
                                            break;

                                        case "contentrating":
                                            rating = GetElementValue(reader);
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                    else if (reader.NodeType == XmlNodeType.EndElement && reader.Name.ToLower() == "series")
                                    {
                                        break;
                                    }
                                }
                            }

                            if (reader.Name.ToLower() == "episode")
                            {
                                TheTVDBDbResult result = new TheTVDBDbResult();

                                while (reader.Read())
                                {
                                    if (reader.NodeType == XmlNodeType.Element)
                                    {
                                        switch (reader.Name.ToLower())
                                        {
                                        case "id":
                                            result.Id = int.Parse(GetElementValue(reader));
                                            break;

                                        case "episodename":
                                            result.Title.Name = GetElementValue(reader);
                                            break;

                                        case "director":
                                            foreach (string directorstr in GetElementValue(reader).Split('|'))
                                            {
                                                if (!string.IsNullOrEmpty(directorstr))
                                                {
                                                    OMLSDKPerson director = new OMLSDKPerson(directorstr);
                                                    result.Title.AddDirector(director);
                                                }
                                            }
                                            break;

                                        case "episodenumber":
                                            result.EpisodeNo           = int.Parse(GetElementValue(reader));
                                            result.Title.EpisodeNumber = (short)result.EpisodeNo;
                                            break;

                                        case "firstaired":
                                            //    result.Title.ReleaseDate = DateTime.Parse(GetElementValue(reader));
                                            break;

                                        case "overview":
                                            result.Title.Synopsis = GetElementValue(reader);
                                            break;

                                        case "seasonnumber":
                                            result.SeasonNo           = int.Parse(GetElementValue(reader));
                                            result.Title.SeasonNumber = (short)result.SeasonNo;
                                            break;

                                        case "seasonid":
                                            //    typemask = int.Parse(GetElementValue(reader));
                                            break;

                                        case "seriesid":
                                            //    typemask = int.Parse(GetElementValue(reader));
                                            break;

                                        case "filename":
                                            result.ImageUrl = GetElementValue(reader);
                                            break;

                                        case "gueststars":
                                            foreach (string actor in GetElementValue(reader).Split('|'))
                                            {
                                                if (!string.IsNullOrEmpty(actor))
                                                {
                                                    result.Title.AddActingRole(actor, "");
                                                }
                                            }
                                            break;

                                        case "runtime":
                                            result.Title.Runtime = int.Parse(GetElementValue(reader));
                                            break;

                                        default:
                                            break;
                                        }
                                    }

                                    else if (reader.NodeType == XmlNodeType.EndElement && reader.Name.ToLower() == "episode")
                                    {
                                        if (result.SeasonNo != 0)
                                        {
                                            bool AddTitle = true;

                                            // If an episode or season number is specified, only add if matched
                                            if ((SeasonNo > 0) && (SeasonNo != result.SeasonNo))
                                            {
                                                AddTitle = false;
                                            }
                                            if ((EpisodeNo > 0) && (EpisodeNo != result.EpisodeNo))
                                            {
                                                AddTitle = false;
                                            }

                                            // If an episode name is specified, calculate the match confidence
                                            if (!string.IsNullOrEmpty(EpisodeName))
                                            {
                                                result.NameMatchConfidence = StringMatching.Compute(EpisodeName, result.Title.Name);
                                            }

                                            if (AddTitle)
                                            {
                                                foreach (string actor in actors.Split('|'))
                                                {
                                                    if (!string.IsNullOrEmpty(actor))
                                                    {
                                                        result.Title.AddActingRole(actor, "");
                                                    }
                                                }
                                                foreach (string genre in genres.Split('|'))
                                                {
                                                    if (!string.IsNullOrEmpty(genre))
                                                    {
                                                        result.Title.AddGenre(genre);
                                                    }
                                                }
                                                result.Title.Studio  = network;
                                                result.Title.Runtime = runtime;
                                                if (string.IsNullOrEmpty(result.Title.ParentalRating))
                                                {
                                                    result.Title.ParentalRating = rating;
                                                }
                                                results.Add(result);
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //if (!string.IsNullOrEmpty(EpisodeName))
            //{
            // Sort by name confidence and limit result set
            results = (from r in results
                       orderby r.NameMatchConfidence
                       select r).Take(maxResults).ToList();
            //}

            // load up all the titles with images
            foreach (TheTVDBDbResult title in results)
            {
                title.Title.FrontCoverPath = "http://images.thetvdb.com/banners/" + title.ImageUrl;
                //DownloadImage(title.Title, "http://images.thetvdb.com/banners/" + title.ImageUrl);
            }
        }
        /// <summary>
        /// Queries tvdb to get a list of tc shows matching 'SeriesName'
        /// </summary>
        /// <param name="SeriesName"></param>
        private void SearchForTVShow(string SeriesName)
        {
            // Reset current series ID
            SeriesID = 0;

            UriBuilder uri = new UriBuilder("http://www.thetvdb.com/api/GetSeries.php");
            uri.Query = "seriesname=" + SeriesName;

            results = new List<TheTVDBDbResult>();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.Uri);

            // execute the request
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                string mirrorpath = "";
                int typemask = 0;

                // we will read data via the response stream
                using (Stream resStream = response.GetResponseStream())
                {
                    XmlTextReader reader = new XmlTextReader(resStream);
                    reader.WhitespaceHandling = WhitespaceHandling.None;

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.Name.ToLower() == "series")
                            {
                                TheTVDBDbResult result = new TheTVDBDbResult();

                                //TheTVDBDbResult title = GetTitleFromMovieNode(reader);

                                //if (title != null)
                                //    results.Add(title);
                                while (reader.Read())
                                {
                                    if (reader.NodeType == XmlNodeType.Element)
                                    {
                                        switch (reader.Name.ToLower())
                                        {
                                            case "seriesid":
                                                result.Id = int.Parse(GetElementValue(reader));
                                                break;
                                            //case "language":
                                            //    result. = GetElementValue(reader);
                                            //    break;
                                            case "seriesname":
                                                result.Title.Name = GetElementValue(reader);
                                                break;
                                            case "banner":
                                                TheTVDBSeries seriesObj = GetFullSeriesData(result.Id);
                                                if (seriesObj != null)
                                                    result.ImageUrl = seriesObj.PosterUrl;
                                                break;
                                            case "overview":
                                                result.Title.Synopsis = GetElementValue(reader);
                                                break;
                                            case "firstAired":
                                                result.Title.ReleaseDate = DateTime.Parse(GetElementValue(reader));
                                                break;
                                            //case "IMDB_ID":
                                            //    typemask = int.Parse(GetElementValue(reader));
                                            //    break;
                                            //case "zap2it_id":
                                            //    typemask = int.Parse(GetElementValue(reader));
                                            //    break;
                                            //case "id":
                                            //    typemask = int.Parse(GetElementValue(reader));
                                            //    break;
                                            //case "IMDB_ID":
                                            //    typemask = int.Parse(GetElementValue(reader));
                                            //    break;
                                            default:
                                                break;
                                        }
                                    }

                                    else if (reader.NodeType == XmlNodeType.EndElement && reader.Name.ToLower() == "series")
                                    {
                                        results.Add(result);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Queries tvdb to get a list of tc shows matching 'SeriesName'
        /// </summary>
        /// <param name="SeriesName"></param>
        private void SearchForTVShow(string SeriesName)
        {
            // Reset current series ID
            SeriesID = 0;

            UriBuilder uri = new UriBuilder("http://www.thetvdb.com/api/GetSeries.php");

            uri.Query = "seriesname=" + SeriesName;

            results = new List <TheTVDBDbResult>();


            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.Uri);

            // execute the request
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                string mirrorpath = "";
                int    typemask   = 0;

                // we will read data via the response stream
                using (Stream resStream = response.GetResponseStream())
                {
                    XmlTextReader reader = new XmlTextReader(resStream);
                    reader.WhitespaceHandling = WhitespaceHandling.None;

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.Name.ToLower() == "series")
                            {
                                TheTVDBDbResult result = new TheTVDBDbResult();

                                //TheTVDBDbResult title = GetTitleFromMovieNode(reader);

                                //if (title != null)
                                //    results.Add(title);
                                while (reader.Read())
                                {
                                    if (reader.NodeType == XmlNodeType.Element)
                                    {
                                        switch (reader.Name.ToLower())
                                        {
                                        case "seriesid":
                                            result.Id = int.Parse(GetElementValue(reader));
                                            break;

                                        //case "language":
                                        //    result. = GetElementValue(reader);
                                        //    break;
                                        case "seriesname":
                                            result.Title.Name = GetElementValue(reader);
                                            break;

                                        case "banner":
                                            TheTVDBSeries seriesObj = GetFullSeriesData(result.Id);
                                            if (seriesObj != null)
                                            {
                                                result.ImageUrl = seriesObj.PosterUrl;
                                            }
                                            break;

                                        case "overview":
                                            result.Title.Synopsis = GetElementValue(reader);
                                            break;

                                        case "firstAired":
                                            result.Title.ReleaseDate = DateTime.Parse(GetElementValue(reader));
                                            break;

                                        //case "IMDB_ID":
                                        //    typemask = int.Parse(GetElementValue(reader));
                                        //    break;
                                        //case "zap2it_id":
                                        //    typemask = int.Parse(GetElementValue(reader));
                                        //    break;
                                        //case "id":
                                        //    typemask = int.Parse(GetElementValue(reader));
                                        //    break;
                                        //case "IMDB_ID":
                                        //    typemask = int.Parse(GetElementValue(reader));
                                        //    break;
                                        default:
                                            break;
                                        }
                                    }

                                    else if (reader.NodeType == XmlNodeType.EndElement && reader.Name.ToLower() == "series")
                                    {
                                        results.Add(result);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private void SearchForEpisode(string EpisodeName, int? SeasonNo, int? EpisodeNo, int maxResults)
        {
            UriBuilder uri = new UriBuilder("http://thetvdb.com/api/" + API_KEY + "/series/" + SeriesID.ToString() + "/all/");

            if (BackDrops == null)
            {
                BackDrops = new List<string>();
            }
            else
            {
                BackDrops.Clear();
            }

            string actors = "";
            string genres = "";
            string network = "";
            int runtime = 0;
            string rating = "";

            results = new List<TheTVDBDbResult>();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.Uri);

            // execute the request
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                //StreamReader reader2 = new StreamReader(response.GetResponseStream());
                //string  tmp = reader2.ReadToEnd();
                //Console.Write(tmp);

                string mirrorpath = "";
                int typemask = 0;

                // we will read data via the response stream
                using (Stream resStream = response.GetResponseStream())
                {
                    XmlTextReader reader = new XmlTextReader(resStream);
                    reader.WhitespaceHandling = WhitespaceHandling.None;

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.Name.ToLower() == "series")
                            {
                                while (reader.Read())
                                {
                                    if (reader.NodeType == XmlNodeType.Element)
                                    {
                                        switch (reader.Name.ToLower())
                                        {
                                            case "actors":
                                                actors = GetElementValue(reader).ToString();
                                                break;
                                            case "genre":
                                                genres = GetElementValue(reader);
                                                break;
                                            case "network":
                                                network = GetElementValue(reader);
                                                break;
                                            case "runtime":
                                                int.TryParse(GetElementValue(reader), out runtime);
                                                //runtime = int.Parse(GetElementValue(reader));
                                                break;
                                            case "fanart":
                                                BackDrops.Add("http://images.thetvdb.com/banners/" + GetElementValue(reader));
                                                break;
                                            case "poster":
                                                BackDrops.Add("http://images.thetvdb.com/banners/" + GetElementValue(reader));
                                                break;
                                            case "contentrating":
                                                rating = GetElementValue(reader);
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                    else if (reader.NodeType == XmlNodeType.EndElement && reader.Name.ToLower() == "series")
                                    {
                                        break;
                                    }
                                }
                            }

                            if (reader.Name.ToLower() == "episode")
                            {
                                TheTVDBDbResult result = new TheTVDBDbResult();

                                while (reader.Read())
                                {
                                    if (reader.NodeType == XmlNodeType.Element)
                                    {
                                        switch (reader.Name.ToLower())
                                        {
                                            case "id":
                                                result.Id = int.Parse(GetElementValue(reader));
                                                break;
                                            case "episodename":
                                                result.Title.Name = GetElementValue(reader);
                                                break;
                                            case "director":
                                                foreach (string directorstr in GetElementValue(reader).Split('|'))
                                                {
                                                    if (!string.IsNullOrEmpty(directorstr))
                                                    {
                                                        OMLSDKPerson director = new OMLSDKPerson(directorstr);
                                                        result.Title.AddDirector(director);
                                                    }
                                                }
                                                break;
                                            case "episodenumber":
                                                result.EpisodeNo = int.Parse(GetElementValue(reader));
                                                result.Title.EpisodeNumber = (short)result.EpisodeNo;
                                                break;
                                            case "firstaired":
                                                //    result.Title.ReleaseDate = DateTime.Parse(GetElementValue(reader));
                                                break;
                                            case "overview":
                                                result.Title.Synopsis = GetElementValue(reader);
                                                break;
                                            case "seasonnumber":
                                                result.SeasonNo = int.Parse(GetElementValue(reader));
                                                result.Title.SeasonNumber = (short)result.SeasonNo;
                                                break;
                                            case "seasonid":
                                                //    typemask = int.Parse(GetElementValue(reader));
                                                break;
                                            case "seriesid":
                                                //    typemask = int.Parse(GetElementValue(reader));
                                                break;
                                            case "filename":
                                                result.ImageUrl = GetElementValue(reader);
                                                break;
                                            case "gueststars":
                                                foreach (string actor in GetElementValue(reader).Split('|'))
                                                {
                                                    if (!string.IsNullOrEmpty(actor))
                                                    {
                                                        result.Title.AddActingRole(actor, "");
                                                    }
                                                }
                                                break;

                                            case "runtime":
                                                result.Title.Runtime = int.Parse(GetElementValue(reader));
                                                break;
                                            default:
                                                break;
                                        }
                                    }

                                    else if (reader.NodeType == XmlNodeType.EndElement && reader.Name.ToLower() == "episode")
                                    {
                                        if (result.SeasonNo != 0)
                                        {
                                            bool AddTitle = true;

                                            // If an episode or season number is specified, only add if matched
                                            if ((SeasonNo > 0) && (SeasonNo != result.SeasonNo)) AddTitle = false;
                                            if ((EpisodeNo > 0) && (EpisodeNo != result.EpisodeNo)) AddTitle = false;

                                            // If an episode name is specified, calculate the match confidence
                                            if (!string.IsNullOrEmpty(EpisodeName)) result.NameMatchConfidence = StringMatching.Compute(EpisodeName, result.Title.Name);

                                            if (AddTitle)
                                            {
                                                foreach (string actor in actors.Split('|'))
                                                {
                                                    if (!string.IsNullOrEmpty(actor))
                                                    {
                                                        result.Title.AddActingRole(actor, "");
                                                    }
                                                }
                                                foreach (string genre in genres.Split('|'))
                                                {
                                                    if (!string.IsNullOrEmpty(genre))
                                                    {
                                                        result.Title.AddGenre(genre);
                                                    }
                                                }
                                                result.Title.Studio = network;
                                                result.Title.Runtime = runtime;
                                                if (string.IsNullOrEmpty(result.Title.ParentalRating))
                                                {
                                                    result.Title.ParentalRating = rating;
                                                }
                                                results.Add(result);
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //if (!string.IsNullOrEmpty(EpisodeName))
            //{
            // Sort by name confidence and limit result set
            results = (from r in results
                       orderby r.NameMatchConfidence
                       select r).Take(maxResults).ToList();
            //}

            // load up all the titles with images
            foreach (TheTVDBDbResult title in results)
            {
                title.Title.FrontCoverPath = "http://images.thetvdb.com/banners/" + title.ImageUrl;
                //DownloadImage(title.Title, "http://images.thetvdb.com/banners/" + title.ImageUrl);
            }
        }