Example #1
0
        public override Item Fetch(Item item)
        {
            Item movie = new Item();
            movie.ProvidersId = item.ProvidersId;
            DataProviderId dp = movie.ProvidersId.Find(p => p.Name == this.Name);
            if (dp == null) return null;
            movie.ProvidersId = new List<DataProviderId> { dp };
            XmlDocument InfosDoc = Helper.Fetch(string.Format(GetInfo, dp.Id), Encoding.UTF8);
            if (InfosDoc == null)
                return null;
            XmlNode node = InfosDoc.GetNodeByName("movie");
            //Titre
            movie.Title = CleanAllocineTitle(SafeGetString(node, "title"));

            //Titre original
            movie.OriginalTitle = CleanAllocineTitle(SafeGetString(node, "originalTitle"));

            //Année
            string release = SafeGetString(node, "productionYear");
            if (release != null && release.Length == 4)
                movie.Year = Int32.Parse(release);

            //Résumé
            movie.Overview = SafeGetString(node, "synopsis");

            //Durée
            try { movie.RunningTime = (int)(Int32.Parse(SafeGetString(node, "runtime")) / 60); }
            catch { }

            //Media
            XmlNode mediaNode = node.GetNodeByName("mediaList");
            foreach (XmlNode mNode in mediaNode.SelectChildren())
            {
                XmlNode typeNode = mNode.GetNodeByName("type");
                if (typeNode == null) continue;
                string typeCode = typeNode.Attributes["code"].InnerText;
                //Posters
                if (typeCode == "31001")
                {
                    if (movie.ImagesPaths == null) movie.ImagesPaths = new List<Poster>();
                    XmlNode thumbNode = mNode.GetNodeByName("thumbnail");
                    if (thumbNode == null) continue;
                    movie.ImagesPaths.Add(new Poster { Image = thumbNode.Attributes["href"].InnerText });
                }

                //Backdrops
                if (typeCode == "31006")
                {
                    if (movie.BackdropImagePaths == null) movie.BackdropImagePaths = new List<Poster>();
                    XmlNode thumbNode = mNode.GetNodeByName("thumbnail");
                    if (thumbNode == null) continue;
                    movie.BackdropImagePaths.Add(new Poster { Image = thumbNode.Attributes["href"].InnerText });
                }

                //Trailers
                if (PluginOptions.Instance.UseTrailers && (typeCode == "31003" || typeCode == "31016"))
                {
                    if (movie.TrailerFiles == null) movie.TrailerFiles = new List<string>();
                    string cmedia = mNode.Attributes["code"].InnerText;
                    XmlDocument trailerDoc = Helper.Fetch(string.Format(GetTrailers, cmedia), Encoding.UTF8);
                    if (trailerDoc != null)
                    {
                        XmlNode n = trailerDoc.SelectSingleNode("//AcVisionVideo");
                        if (n != null)
                        {
                            string url = n.Attributes["hd_path"].InnerText;
                            if (string.IsNullOrEmpty(url))
                                url = n.Attributes["md_path"].InnerText;
                            if (string.IsNullOrEmpty(url))
                                url = n.Attributes["ld_path"].InnerText;
                            if (!string.IsNullOrEmpty(url))
                            {
                                movie.TrailerFiles.Add(url);
                            }
                        }
                    }
                }
            }

            //Pays
            XmlNode countryNode = node.GetNodeByName("nationalityList");
            foreach (XmlNode n in countryNode.SelectChildren())
            {
                if (movie.Countries == null) movie.Countries = new List<string>();
                if (!string.IsNullOrEmpty(n.InnerText))
                    movie.Countries.Add(n.InnerText);
            }

            //Genre
            XmlNode genreNode = node.GetNodeByName("genreList");
            foreach (XmlNode n in genreNode.SelectChildren())
            {
                if (movie.Genres == null) movie.Genres = new List<string>();
                if (!string.IsNullOrEmpty(n.InnerText))
                    movie.Genres.Add(n.InnerText);
            }

            //Note
            XmlNode statNode = node.GetNodeByName("statistics");
            if (statNode != null)
            {
                XmlNode ratingNode = statNode.GetNodeByName("ratingStats");
                float? rating = null;
                double vote = 0; double note = 0;
                foreach (XmlNode n in ratingNode.SelectChildren())
                {
                        double V; double N;
                        try
                        {
                            V = Int32.Parse(n.InnerText);
                            N = double.Parse(n.Attributes["note"].InnerText, CultureInfo.InvariantCulture) * 2;
                        }
                        catch { continue; }
                        vote = vote + V;
                        note = note + (N * V);
                }
                    if (vote > 0)
                        rating = (float)Math.Round((double)(note / vote), 1);

                movie.Rating = rating;
            }

            //Acteurs - Equipe
            XmlNode castingNode = node.GetNodeByName("casting");
            foreach (XmlNode n in castingNode.SelectChildren())
            {
                string activity = SafeGetString(n, "activity");
                if (activity == "Acteur" || activity == "Actrice")
                {
                    if (movie.Actors == null) movie.Actors = new List<Actor>();
                    Actor actor = new Actor();
                    actor.Name = SafeGetString(n, "person");
                    actor.Role = SafeGetString(n, "role");
                    actor.ImagePath = SafeGetString(n, "picture");
                    movie.Actors.Add(actor);
                }
                else
                {
                    if (movie.Crew == null) movie.Crew = new List<CrewMember>();
                    CrewMember cm = new CrewMember();
                    cm.Name = SafeGetString(n, "person");
                    cm.Activity = activity;
                    movie.Crew.Add(cm);
                }
            }

            return movie;
        }
 private void crewBox_OnTextChanged(object sender, EventArgs e)
 {
     SelectedItem.Crew = new List<CrewMember>();
     foreach (string s in crewBox.text.Split(','))
     {
         CrewMember crew = new CrewMember();
         Regex r = new Regex(@"^(?<name>[^\(]+)\((?<activity>.+)\)$");
         Match m = r.Match(s.Trim());
         if (m.Success)
         {
             crew.Activity = m.Groups["activity"].Value;
             crew.Name = m.Groups["name"].Value;
         }
         else
             crew.Name = s.Trim();
         SelectedItem.Crew.Add(crew);
     }
     UpdateCrew();
     HasChanged();
 }