Exemplo n.º 1
0
        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(Where.FullName, settings))
                {
                    if (Episode != null) // specific episode
                    {
                        if (Episode.Type == ProcessedEpisode.ProcessedEpisodeType.merged)
                        {
                            foreach (Episode ep in Episode.SourceEpisodes)
                            {
                                WriteEpisodeDetailsFor(ep, writer, true, Episode.Show.DvdOrder);
                            }
                        }
                        else
                        {
                            WriteEpisodeDetailsFor(Episode, writer, false, Episode.Show.DvdOrder);
                        }
                    }
                    else if (SelectedShow != null) // show overview (tvshow.nfo)
                    {
                        // http://www.xbmc.org/wiki/?title=Import_-_Export_Library#TV_Shows
                        writer.WriteStartElement("tvshow");

                        XmlHelper.WriteElementToXml(writer, "title", SelectedShow.ShowName);

                        XmlHelper.WriteElementToXml(writer, "episodeguideurl",
                                                    TheTVDB.BuildUrl(SelectedShow.TvdbCode, SelectedShow.UseCustomLanguage? SelectedShow.PreferredLanguage.Abbreviation:TVSettings.Instance.PreferredLanguageCode));

                        XmlHelper.WriteElementToXml(writer, "plot", SelectedShow.TheSeries().GetOverview());

                        string genre = string.Join(" / ", SelectedShow.TheSeries().GetGenres());
                        if (!string.IsNullOrEmpty(genre))
                        {
                            XmlHelper.WriteElementToXml(writer, "genre", genre);
                        }

                        XmlHelper.WriteElementToXml(writer, "premiered", SelectedShow.TheSeries().GetFirstAired());
                        XmlHelper.WriteElementToXml(writer, "year", SelectedShow.TheSeries().GetYear());
                        XmlHelper.WriteElementToXml(writer, "rating", SelectedShow.TheSeries().GetContentRating());
                        XmlHelper.WriteElementToXml(writer, "status", SelectedShow.TheSeries().GetStatus());

                        // actors...
                        foreach (Actor aa in SelectedShow.TheSeries().GetActors())
                        {
                            if (string.IsNullOrEmpty(aa.ActorName))
                            {
                                continue;
                            }

                            writer.WriteStartElement("actor");
                            XmlHelper.WriteElementToXml(writer, "name", aa.ActorName);
                            XmlHelper.WriteElementToXml(writer, "role", aa.ActorRole);
                            XmlHelper.WriteElementToXml(writer, "order", aa.ActorSortOrder);
                            XmlHelper.WriteElementToXml(writer, "thumb", aa.ActorImage);
                            writer.WriteEndElement(); // actor
                        }

                        XmlHelper.WriteElementToXml(writer, "mpaa", SelectedShow.TheSeries().GetContentRating());
                        XmlHelper.WriteInfo(writer, "id", "moviedb", "imdb", SelectedShow.TheSeries().GetImdb());

                        XmlHelper.WriteElementToXml(writer, "tvdbid", SelectedShow.TheSeries().TvdbCode);

                        string rt = SelectedShow.TheSeries().GetRuntime();
                        if (!string.IsNullOrEmpty(rt))
                        {
                            XmlHelper.WriteElementToXml(writer, "runtime", rt + " minutes");
                        }
                        writer.WriteEndElement(); // tvshow
                    }
                }
            }
            catch (Exception e)
            {
                ErrorText = e.Message;
                Error     = true;
                Done      = true;
                return(false);
            }
            Done = true;
            return(true);
        }
Exemplo n.º 2
0
        public override bool Go(TVRenameStats stats)
        {
            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent              = true,
                IndentChars         = "    ",
                Encoding            = Encoding.UTF8,
                NewLineChars        = "\r\n",
                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(Where.FullName, settings))
                {
                    if (Episode != null) // specific episode
                    {
                        if (Episode.Type == ProcessedEpisode.ProcessedEpisodeType.merged)
                        {
                            foreach (Episode ep in Episode.SourceEpisodes)
                            {
                                ShowItem si = Episode.Show ?? SelectedShow;
                                WriteEpisodeDetailsFor(ep, si, writer, true, si.DvdOrder);
                            }
                        }
                        else
                        {
                            ShowItem si = Episode.Show ?? SelectedShow;
                            WriteEpisodeDetailsFor(Episode, si, writer, false, si.DvdOrder);
                        }
                    }
                    else if (SelectedShow != null) // show overview (tvshow.nfo)
                    {
                        SeriesInfo series = SelectedShow.TheSeries();

                        // https://kodi.wiki/view/NFO_files/TV_shows
                        writer.WriteStartElement("tvshow");

                        writer.WriteElement("title", SelectedShow.ShowName);
                        writer.WriteElement("originaltitle", series?.Name);
                        writer.WriteElement("studio", series?.Network);
                        float?showRating = series?.SiteRating;
                        if (showRating.HasValue)
                        {
                            writer.WriteStartElement("ratings");

                            writer.WriteStartElement("rating");
                            writer.WriteAttributeString("name", "tvdb");
                            writer.WriteAttributeString("max", "10");
                            writer.WriteAttributeString("default", "true");

                            writer.WriteElement("value", showRating.Value);
                            writer.WriteElement("votes", series.SiteRatingVotes, true);

                            writer.WriteEndElement(); //rating

                            writer.WriteEndElement(); //ratings
                        }

                        string lang = TVSettings.Instance.PreferredLanguageCode;
                        if (SelectedShow.UseCustomLanguage && SelectedShow.PreferredLanguage != null)
                        {
                            lang = SelectedShow.PreferredLanguage.Abbreviation;
                        }

                        writer.WriteElement("episodeguideurl",
                                            TheTVDB.BuildUrl(SelectedShow.TvdbCode, lang));

                        if (!(series is null))
                        {
                            writer.WriteElement("id", series.SeriesId);
                            writer.WriteElement("runtime", series.Runtime, true);
                            writer.WriteElement("mpaa", series.ContentRating, true);

                            writer.WriteStartElement("uniqueid");
                            writer.WriteAttributeString("type", "tvdb");
                            writer.WriteAttributeString("default", "true");
                            writer.WriteValue(series.TvdbCode);
                            writer.WriteEndElement();

                            writer.WriteStartElement("uniqueid");
                            writer.WriteAttributeString("type", "imdb");
                            writer.WriteAttributeString("default", "false");
                            writer.WriteValue(series.Imdb);
                            writer.WriteEndElement();

                            writer.WriteElement("plot", series.Overview);

                            writer.WriteElement("premiered", series.FirstAired);
                            writer.WriteElement("year", series.Year);
                            writer.WriteElement("status", series.Status);
                        }

                        writer.WriteStringsToXml("genre", SelectedShow.Genres);

                        // actors...
                        foreach (Actor aa in SelectedShow.Actors.Where(aa => !string.IsNullOrEmpty(aa.ActorName)))
                        {
                            writer.WriteStartElement("actor");
                            writer.WriteElement("name", aa.ActorName);
                            writer.WriteElement("role", aa.ActorRole);
                            writer.WriteElement("order", aa.ActorSortOrder);
                            writer.WriteElement("thumb", aa.ActorImage);
                            writer.WriteEndElement(); // actor
                        }

                        writer.WriteEndElement(); // tvshow
                    }
                }
            }
            catch (Exception e)
            {
                ErrorText = e.Message;
                LastError = e;
                Error     = true;
                Done      = true;
                return(false);
            }
            Done = true;
            return(true);
        }
Exemplo n.º 3
0
        private void WriteSeriesXmlFile([NotNull] XmlWriter writer)
        {
            SeriesInfo series = SelectedShow.TheSeries();

            // https://kodi.wiki/view/NFO_files/TV_shows
            writer.WriteStartElement("tvshow");

            writer.WriteElement("title", SelectedShow.ShowName);
            writer.WriteElement("originaltitle", series?.Name);
            writer.WriteElement("studio", series?.Network);
            float?showRating = series?.SiteRating;

            if (showRating.HasValue)
            {
                writer.WriteStartElement("ratings");

                writer.WriteStartElement("rating");
                writer.WriteAttributeString("name", "tvdb");
                writer.WriteAttributeString("max", "10");
                writer.WriteAttributeString("default", "true");

                writer.WriteElement("value", showRating.Value);
                writer.WriteElement("votes", series.SiteRatingVotes, true);

                writer.WriteEndElement(); //rating

                writer.WriteEndElement(); //ratings
            }

            string lang = TVSettings.Instance.PreferredLanguageCode;

            if (SelectedShow.UseCustomLanguage && SelectedShow.PreferredLanguage != null)
            {
                lang = SelectedShow.PreferredLanguage.Abbreviation;
            }

            //https://forum.kodi.tv/showthread.php?tid=323588
            //says that we need a format like this:
            //<episodeguide><url post="yes" cache="auth.json">https://api.thetvdb.com/login?{&quot;apikey&quot;:&quot;((API-KEY))&quot;,&quot;id&quot;:((ID))}|Content-Type=application/json</url></episodeguide>

            writer.WriteStartElement("episodeguide");
            writer.WriteStartElement("url");
            writer.WriteAttributeString("post", "yes");
            writer.WriteAttributeString("cache", "auth.json");
            writer.WriteRaw(TheTVDB.BuildUrl(SelectedShow.TvdbCode, lang));
            writer.WriteEndElement(); //url
            writer.WriteEndElement(); //episodeguide

            if (!(series is null))
            {
                writer.WriteElement("id", series.TvdbCode);
                writer.WriteElement("runtime", series.Runtime, true);
                writer.WriteElement("mpaa", series.ContentRating, true);

                writer.WriteStartElement("uniqueid");
                writer.WriteAttributeString("type", "tvdb");
                writer.WriteAttributeString("default", "true");
                writer.WriteValue(series.TvdbCode);
                writer.WriteEndElement();

                writer.WriteStartElement("uniqueid");
                writer.WriteAttributeString("type", "imdb");
                writer.WriteAttributeString("default", "false");
                writer.WriteValue(series.Imdb);
                writer.WriteEndElement();

                writer.WriteElement("plot", series.Overview);

                writer.WriteElement("premiered", series.FirstAired);
                writer.WriteElement("year", series.Year);
                writer.WriteElement("status", series.Status);
            }

            writer.WriteStringsToXml("genre", SelectedShow.Genres);

            // actors...
            foreach (Actor aa in SelectedShow.Actors.Where(aa => !string.IsNullOrEmpty(aa.ActorName)))
            {
                writer.WriteStartElement("actor");
                writer.WriteElement("name", aa.ActorName);
                writer.WriteElement("role", aa.ActorRole);
                writer.WriteElement("order", aa.ActorSortOrder);
                writer.WriteElement("thumb", TheTVDB.GetImageURL(aa.ActorImage), true);
                writer.WriteEndElement(); // actor
            }

            writer.WriteEndElement(); // tvshow
        }