コード例 #1
0
        /// <summary>
        /// Constructor for creating AppleTrailers object.  The constructor will do the outbound query and load up a collection
        /// of titles you can query/sort against.
        /// </summary>
        /// <param name="res">The resolution of the trailers</param>
        public AppleTrailers(AppleTrailerRes res)
        {
            string url = (res == AppleTrailerRes.HiRes)
                            ? HiFiUrl
                            : LoFiUrl;
            try
            {
                // load the xml
                using (OMLWebClient client = new OMLWebClient())
                {
                    client.UserAgent = AppleTrailers.QUICKTIME_USER_AGENT_STRING;
                    using (Stream stream = client.OpenRead(url))
                    {
                        XmlTextReader reader = new XmlTextReader(stream);

                        reader.Read();

                        AppleTrailer trailer = null;

                        DateTimeFormatInfo dateFormat = new DateTimeFormatInfo();
                        dateFormat.ShortDatePattern = "yyyy-MM-dd";

                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                switch (reader.Name)
                                {
                                    case "movieinfo":
                                        if (trailer != null)
                                            appleTrailers.Add(trailer);

                                        trailer = new AppleTrailer();

                                        trailer.Id = reader.GetAttribute(0);
                                        break;

                                    case "title":
                                        trailer.Title = ReadToValue(reader);
                                        break;

                                    case "runtime":
                                        trailer.RunTime = ReadToValue(reader);
                                        break;

                                    case "rating":
                                        trailer.Rating = ReadToValue(reader);
                                        break;

                                    case "studio":
                                        trailer.Studio = ReadToValue(reader);
                                        break;

                                    case "postdate":
                                        trailer.PostDate = DateTime.Parse(ReadToValue(reader), dateFormat);
                                        break;

                                    case "releasedate":
                                        trailer.ReleaseDate = DateTime.Parse(ReadToValue(reader), dateFormat);
                                        break;

                                    case "director":
                                        trailer.Director = ReadToValue(reader);
                                        break;

                                    case "description":
                                        trailer.Description = ReadToValue(reader);
                                        break;

                                    case "cast":
                                        while (reader.Read())
                                        {
                                            if (reader.NodeType == XmlNodeType.EndElement &&
                                                reader.Name == "cast")
                                                break;

                                            if (reader.Name == "name")
                                            {
                                                trailer.AddCast(ReadToValue(reader));
                                            }
                                        }
                                        break;

                                    case "genre":
                                        while (reader.Read())
                                        {
                                            if (reader.NodeType == XmlNodeType.EndElement &&
                                                reader.Name == "genre")
                                                break;

                                            if (reader.Name == "name")
                                            {
                                                trailer.AddGenre(ReadToValue(reader));
                                            }
                                        }
                                        break;

                                    case "poster":
                                        while (reader.Read())
                                        {
                                            if (reader.NodeType == XmlNodeType.EndElement &&
                                                reader.Name == "poster")
                                                break;

                                            if (reader.Name == "location")
                                            {
                                                trailer.SmallImageUrl = ReadToValue(reader);
                                            }
                                            else if (reader.Name == "xlarge")
                                            {
                                                trailer.LargeImageUrl = ReadToValue(reader);
                                            }
                                        }
                                        break;

                                    case "preview":
                                        while (reader.Read())
                                        {
                                            if (reader.NodeType == XmlNodeType.EndElement &&
                                                reader.Name == "preview")
                                                break;

                                            if (reader.Name == "large")
                                            {
                                                trailer.TrailerUrl = ReadToValue(reader);
                                            }
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                Utilities.DebugLine("[AppleTrailers] Error: {0}", err.Message);
            }
        }
コード例 #2
0
        /// <summary>
        /// Constructor for creating AppleTrailers object.  The constructor will do the outbound query and load up a collection
        /// of titles you can query/sort against.
        /// </summary>
        /// <param name="res">The resolution of the trailers</param>
        public AppleTrailers(AppleTrailerRes res)
        {
            string url = (res == AppleTrailerRes.HiRes)
                            ? HiFiUrl
                            : LoFiUrl;

            try
            {
                // load the xml
                using (OMLWebClient client = new OMLWebClient())
                {
                    client.UserAgent = AppleTrailers.QUICKTIME_USER_AGENT_STRING;
                    using (Stream stream = client.OpenRead(url))
                    {
                        XmlTextReader reader = new XmlTextReader(stream);

                        reader.Read();

                        AppleTrailer trailer = null;

                        DateTimeFormatInfo dateFormat = new DateTimeFormatInfo();
                        dateFormat.ShortDatePattern = "yyyy-MM-dd";

                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                switch (reader.Name)
                                {
                                case "movieinfo":
                                    if (trailer != null)
                                    {
                                        appleTrailers.Add(trailer);
                                    }

                                    trailer = new AppleTrailer();

                                    trailer.Id = reader.GetAttribute(0);
                                    break;

                                case "title":
                                    trailer.Title = ReadToValue(reader);
                                    break;

                                case "runtime":
                                    trailer.RunTime = ReadToValue(reader);
                                    break;

                                case "rating":
                                    trailer.Rating = ReadToValue(reader);
                                    break;

                                case "studio":
                                    trailer.Studio = ReadToValue(reader);
                                    break;

                                case "postdate":
                                    trailer.PostDate = DateTime.Parse(ReadToValue(reader), dateFormat);
                                    break;

                                case "releasedate":
                                    trailer.ReleaseDate = DateTime.Parse(ReadToValue(reader), dateFormat);
                                    break;

                                case "director":
                                    trailer.Director = ReadToValue(reader);
                                    break;

                                case "description":
                                    trailer.Description = ReadToValue(reader);
                                    break;

                                case "cast":
                                    while (reader.Read())
                                    {
                                        if (reader.NodeType == XmlNodeType.EndElement &&
                                            reader.Name == "cast")
                                        {
                                            break;
                                        }

                                        if (reader.Name == "name")
                                        {
                                            trailer.AddCast(ReadToValue(reader));
                                        }
                                    }
                                    break;

                                case "genre":
                                    while (reader.Read())
                                    {
                                        if (reader.NodeType == XmlNodeType.EndElement &&
                                            reader.Name == "genre")
                                        {
                                            break;
                                        }

                                        if (reader.Name == "name")
                                        {
                                            trailer.AddGenre(ReadToValue(reader));
                                        }
                                    }
                                    break;

                                case "poster":
                                    while (reader.Read())
                                    {
                                        if (reader.NodeType == XmlNodeType.EndElement &&
                                            reader.Name == "poster")
                                        {
                                            break;
                                        }

                                        if (reader.Name == "location")
                                        {
                                            trailer.SmallImageUrl = ReadToValue(reader);
                                        }
                                        else if (reader.Name == "xlarge")
                                        {
                                            trailer.LargeImageUrl = ReadToValue(reader);
                                        }
                                    }
                                    break;

                                case "preview":
                                    while (reader.Read())
                                    {
                                        if (reader.NodeType == XmlNodeType.EndElement &&
                                            reader.Name == "preview")
                                        {
                                            break;
                                        }

                                        if (reader.Name == "large")
                                        {
                                            trailer.TrailerUrl = ReadToValue(reader);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                Utilities.DebugLine("[AppleTrailers] Error: {0}", err.Message);
            }
        }