Пример #1
0
        // Collection/DVD/Credits/*
        private void HandleCredits(OMLSDKTitle title, XPathNavigator creditsNavigator)
        {
            List <string> writersAlreadyAdded   = new List <string>();
            List <string> producersAlreadyAdded = new List <string>();

            foreach (XPathNavigator creditNavigator in creditsNavigator.SelectChildren("Credit", string.Empty))
            {
                string       creditType = creditNavigator.GetAttribute("CreditType", string.Empty);
                OMLSDKPerson person     = new OMLSDKPerson(ReadFullName(creditNavigator));
                switch (creditType)
                {
                case "Direction":
                    title.AddDirector(person);
                    break;

                case "Writing":
                    title.AddWriter(person);
                    break;

                case "Production":
                    title.AddProducer(person);
                    break;
                }
            }
        }
Пример #2
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);
            }
        }