コード例 #1
0
ファイル: ActionNFO.cs プロジェクト: Dpst94/tvrename
        public override bool Go(ref bool pause, TVRenameStats stats)
        {
            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent = true,
                NewLineOnAttributes = true,

                //Multipart NFO files are not actually valid XML as they have multiple episodeDetails elements
                ConformanceLevel = ConformanceLevel.Fragment
            };

            try
            {
                // "try" and silently fail.  eg. when file is use by other...
                using (XmlWriter writer = XmlWriter.Create(this.Where.FullName, settings))
                {
                    if (this.Episode != null) // specific episode
                    {
                        if (this.Episode.type == ProcessedEpisode.ProcessedEpisodeType.merged)
                        {
                            foreach (Episode ep in this.Episode.sourceEpisodes)
                            {
                                WriteEpisodeDetailsFor(ep, writer, true, this.Episode.SI.DVDOrder);
                            }
                        }
                        else
                        {
                            WriteEpisodeDetailsFor(this.Episode, writer, false, this.Episode.SI.DVDOrder);
                        }
                    }
                    else if (this.SI != null) // show overview (tvshow.nfo)
                    {
                        // http://www.xbmc.org/wiki/?title=Import_-_Export_Library#TV_Shows
                        writer.WriteStartElement("tvshow");

                        XMLHelper.WriteElementToXML(writer, "title", this.SI.ShowName);

                        XMLHelper.WriteElementToXML(writer, "episodeguideurl",
                                                    TheTVDB.BuildURL(this.SI.TVDBCode, TheTVDB.Instance.RequestLanguage));

                        XMLHelper.WriteElementToXML(writer, "plot", this.SI.TheSeries().GetOverview());

                        string genre = String.Join(" / ", this.SI.TheSeries().GetGenres());
                        if (!string.IsNullOrEmpty(genre))
                        {
                            XMLHelper.WriteElementToXML(writer, "genre", genre);
                        }

                        XMLHelper.WriteElementToXML(writer, "premiered", this.SI.TheSeries().GetFirstAired());
                        XMLHelper.WriteElementToXML(writer, "year", this.SI.TheSeries().GetYear());
                        XMLHelper.WriteElementToXML(writer, "rating", this.SI.TheSeries().GetContentRating());
                        XMLHelper.WriteElementToXML(writer, "status", this.SI.TheSeries().getStatus());

                        // actors...
                        foreach (string aa in this.SI.TheSeries().GetActors())
                        {
                            if (string.IsNullOrEmpty(aa))
                            {
                                continue;
                            }

                            writer.WriteStartElement("actor");
                            XMLHelper.WriteElementToXML(writer, "name", aa);
                            writer.WriteEndElement(); // actor
                        }

                        XMLHelper.WriteElementToXML(writer, "mpaa", this.SI.TheSeries().GetContentRating());
                        XMLHelper.WriteInfo(writer, "id", "moviedb", "imdb", this.SI.TheSeries().GetIMDB());

                        XMLHelper.WriteElementToXML(writer, "tvdbid", this.SI.TheSeries().TVDBCode);

                        string rt = this.SI.TheSeries().GetRuntime();
                        if (!string.IsNullOrEmpty(rt))
                        {
                            XMLHelper.WriteElementToXML(writer, "runtime", rt + " minutes");
                        }
                        writer.WriteEndElement(); // tvshow
                    }
                }
            }
            catch (Exception e)
            {
                this.ErrorText = e.Message;
                this.Error     = true;
                this.Done      = true;
                return(false);
            }
            this.Done = true;
            return(true);
        }
コード例 #2
0
        public bool Go(ref bool pause, TVRenameStats stats)
        {
            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent = true,
                NewLineOnAttributes = true
            };
            // "try" and silently fail.  eg. when file is use by other...
            XmlWriter writer;

            try
            {
                //                XmlWriter writer = XmlWriter.Create(this.Where.FullName, settings);
                writer = XmlWriter.Create(this.Where.FullName, settings);
                if (writer == null)
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                this.Done = true;
                return(true);
            }

            if (this.Episode != null) // specific episode
            {
                // See: http://xbmc.org/wiki/?title=Import_-_Export_Library#TV_Episodes
                writer.WriteStartElement("episodedetails");

                XMLHelper.WriteElementToXML(writer, "title", this.Episode.Name);
                XMLHelper.WriteElementToXML(writer, "rating", this.Episode.EpisodeRating);
                XMLHelper.WriteElementToXML(writer, "season", this.Episode.SeasonNumber);
                XMLHelper.WriteElementToXML(writer, "episode", this.Episode.EpNum);
                XMLHelper.WriteElementToXML(writer, "plot", this.Episode.Overview);

                writer.WriteStartElement("aired");
                if (this.Episode.FirstAired != null)
                {
                    writer.WriteValue(this.Episode.FirstAired.Value.ToString("yyyy-MM-dd"));
                }
                writer.WriteEndElement();

                if (this.Episode.SI != null)
                {
                    WriteInfo(writer, this.Episode.SI, "ContentRating", "mpaa");
                }

                //Director(s)
                if (!String.IsNullOrEmpty(this.Episode.EpisodeDirector))
                {
                    string EpDirector = this.Episode.EpisodeDirector;
                    if (!string.IsNullOrEmpty(EpDirector))
                    {
                        foreach (string Daa in EpDirector.Split('|'))
                        {
                            if (string.IsNullOrEmpty(Daa))
                            {
                                continue;
                            }

                            XMLHelper.WriteElementToXML(writer, "director", Daa);
                        }
                    }
                }

                //Writers(s)
                if (!String.IsNullOrEmpty(this.Episode.Writer))
                {
                    string EpWriter = this.Episode.Writer;
                    if (!string.IsNullOrEmpty(EpWriter))
                    {
                        XMLHelper.WriteElementToXML(writer, "credits", EpWriter);
                    }
                }

                // Guest Stars...
                if (!String.IsNullOrEmpty(this.Episode.EpisodeGuestStars))
                {
                    string RecurringActors = "";

                    if (this.Episode.SI != null)
                    {
                        RecurringActors = this.Episode.SI.TheSeries().GetItem("Actors");
                    }

                    string GuestActors = this.Episode.EpisodeGuestStars;
                    if (!string.IsNullOrEmpty(GuestActors))
                    {
                        foreach (string Gaa in GuestActors.Split('|'))
                        {
                            if (string.IsNullOrEmpty(Gaa))
                            {
                                continue;
                            }

                            // Skip if the guest actor is also in the overal recurring list
                            if (!string.IsNullOrEmpty(RecurringActors) && RecurringActors.Contains(Gaa))
                            {
                                continue;
                            }

                            writer.WriteStartElement("actor");
                            XMLHelper.WriteElementToXML(writer, "name", Gaa);
                            writer.WriteEndElement(); // actor
                        }
                    }
                }

                // actors...
                if (this.Episode.SI != null)
                {
                    string actors = this.Episode.SI.TheSeries().GetItem("Actors");
                    if (!string.IsNullOrEmpty(actors))
                    {
                        foreach (string aa in actors.Split('|'))
                        {
                            if (string.IsNullOrEmpty(aa))
                            {
                                continue;
                            }

                            writer.WriteStartElement("actor");
                            XMLHelper.WriteElementToXML(writer, "name", aa);
                            writer.WriteEndElement(); // actor
                        }
                    }
                }

                writer.WriteEndElement(); // episodedetails
            }
            else if (this.SI != null)     // show overview (tvshow.nfo)
            {
                // http://www.xbmc.org/wiki/?title=Import_-_Export_Library#TV_Shows

                writer.WriteStartElement("tvshow");

                XMLHelper.WriteElementToXML(writer, "title", this.SI.ShowName);

                XMLHelper.WriteElementToXML(writer, "episodeguideurl", TheTVDB.BuildURL(true, true, this.SI.TVDBCode, TheTVDB.Instance.RequestLanguage));

                WriteInfo(writer, this.SI, "Overview", "plot");

                string genre = this.SI.TheSeries().GetItem("Genre");
                if (!string.IsNullOrEmpty(genre))
                {
                    genre = genre.Trim('|');
                    genre = genre.Replace("|", " / ");
                    XMLHelper.WriteElementToXML(writer, "genre", genre);
                }

                WriteInfo(writer, this.SI, "FirstAired", "premiered");
                WriteInfo(writer, this.SI, "Year", "year");
                WriteInfo(writer, this.SI, "Rating", "rating");
                WriteInfo(writer, this.SI, "Status", "status");

                // actors...
                string actors = this.SI.TheSeries().GetItem("Actors");
                if (!string.IsNullOrEmpty(actors))
                {
                    foreach (string aa in actors.Split('|'))
                    {
                        if (string.IsNullOrEmpty(aa))
                        {
                            continue;
                        }

                        writer.WriteStartElement("actor");
                        XMLHelper.WriteElementToXML(writer, "name", aa);
                        writer.WriteEndElement(); // actor
                    }
                }

                WriteInfo(writer, this.SI, "ContentRating", "mpaa");
                WriteInfo(writer, this.SI, "IMDB_ID", "id", "moviedb", "imdb");

                XMLHelper.WriteElementToXML(writer, "tvdbid", this.SI.TheSeries().TVDBCode);

                string rt = this.SI.TheSeries().GetItem("Runtime");
                if (!string.IsNullOrEmpty(rt))
                {
                    XMLHelper.WriteElementToXML(writer, "runtime", rt + " minutes");
                }

                writer.WriteEndElement(); // tvshow
            }

            try
            {
                writer.Close();
            }
            catch (Exception e)
            {
                this.ErrorText = e.Message;
                this.Error     = true;
                this.Done      = true;
                return(false);
            }

            this.Done = true;
            return(true);
        }