Esempio n. 1
0
        private bool WriteSeriesXml()
        {
            try
            {
                XmlWriterSettings settings = new XmlWriterSettings
                {
                    Indent = true,
                    NewLineOnAttributes = true
                };

                using (XmlWriter writer = XmlWriter.Create(Where.FullName, settings))
                {
                    writer.WriteStartElement("details");
                    writer.WriteStartElement("show");

                    writer.WriteElement("title", SelectedShow.ShowName);
                    writer.WriteElement("premiered", SelectedShow.TheSeries()?.FirstAired);
                    writer.WriteElement("year", SelectedShow.TheSeries()?.Year);
                    writer.WriteElement("status", SelectedShow.TheSeries()?.Status);
                    writer.WriteElement("mpaa", SelectedShow.TheSeries()?.ContentRating);
                    writer.WriteElement("tvdbid", SelectedShow.TheSeries()?.TvdbCode);
                    writer.WriteElement("plot", SelectedShow.TheSeries()?.Overview);

                    foreach (string genre in SelectedShow.Genres)
                    {
                        writer.WriteElement("genre", genre);
                    }

                    float siteRating = SelectedShow.TheSeries()?.SiteRating ?? 0 * 10;

                    int intSiteRating = (int)siteRating;
                    if (intSiteRating > 0)
                    {
                        writer.WriteElement("rating", intSiteRating);
                    }

                    writer.WriteInfo("moviedb", "imdb", "id", SelectedShow.TheSeries()?.Imdb);

                    string rt = SelectedShow.TheSeries()?.Runtime;
                    if (!string.IsNullOrEmpty(rt))
                    {
                        writer.WriteElement("runtime", rt + " min");
                    }

                    writer.WriteEndElement(); // show
                    writer.WriteEndElement(); // tvshow
                }
                Done = true;
                return(true);
            }
            catch (Exception e)
            {
                ErrorText = e.Message;
                LastError = e;
                Error     = true;
                Done      = true;
                return(false);
            }
        }
Esempio n. 2
0
        private void WriteSeriesXml()
        {
            XmlWriterSettings settings = new XmlWriterSettings {
                Indent = true, NewLineOnAttributes = true
            };

            using (XmlWriter writer = XmlWriter.Create(Where.FullName, settings))
            {
                // http://www.xbmc.org/wiki/?title=Import_-_Export_Library#TV_Shows
                writer.WriteStartElement("details");
                writer.WriteStartElement("movie");
                XmlHelper.WriteElementToXml(writer, "title", SelectedShow.ShowName);
                writer.WriteStartElement("genres");
                string genre = string.Join(" / ", SelectedShow.TheSeries().GetGenres());
                if (!string.IsNullOrEmpty(genre))
                {
                    XmlHelper.WriteElementToXml(writer, "genre", genre);
                }

                writer.WriteEndElement(); // genres
                XmlHelper.WriteElementToXml(writer, "premiered", SelectedShow.TheSeries().GetFirstAired());
                XmlHelper.WriteElementToXml(writer, "year", SelectedShow.TheSeries().GetYear());

                //Mede8er Ratings are on a 100 point scale; TVDB are on a 10 point scale
                float siteRating    = float.Parse(SelectedShow.TheSeries().GetSiteRating(), new CultureInfo("en-US")) * 10;
                int   intSiteRating = (int)siteRating;
                if (intSiteRating > 0)
                {
                    XmlHelper.WriteElementToXml(writer, "rating", intSiteRating);
                }
                XmlHelper.WriteElementToXml(writer, "status", SelectedShow.TheSeries().GetStatus());
                XmlHelper.WriteElementToXml(writer, "mpaa", SelectedShow.TheSeries().GetContentRating());
                XmlHelper.WriteInfo(writer, "moviedb", "imdb", "id", SelectedShow.TheSeries().GetImdb());
                XmlHelper.WriteElementToXml(writer, "tvdbid", SelectedShow.TheSeries().TvdbCode);
                string rt = SelectedShow.TheSeries().GetRuntime();
                if (!string.IsNullOrEmpty(rt))
                {
                    XmlHelper.WriteElementToXml(writer, "runtime", rt + " min");
                }

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

                // actors...
                foreach (string aa in SelectedShow.TheSeries().GetActorNames())
                {
                    if (string.IsNullOrEmpty(aa))
                    {
                        continue;
                    }
                    XmlHelper.WriteElementToXml(writer, "actor", aa);
                }

                writer.WriteEndElement(); // cast
                writer.WriteEndElement(); // movie
                writer.WriteEndElement(); // tvshow
            }
        }
Esempio n. 3
0
        private void WriteSeriesXml()
        {
            XmlWriterSettings settings = new XmlWriterSettings {
                Indent = true, NewLineOnAttributes = true
            };

            using (XmlWriter writer = XmlWriter.Create(Where.FullName, settings))
            {
                // http://www.xbmc.org/wiki/?title=Import_-_Export_Library#TV_Shows
                writer.WriteStartElement("details");
                writer.WriteStartElement("movie");
                writer.WriteElement("title", SelectedShow.ShowName);

                writer.WriteStartElement("genres");
                string genre = string.Join(" / ", SelectedShow.TheSeries()?.Genres() ?? new List <string>());
                if (!string.IsNullOrEmpty(genre))
                {
                    writer.WriteElement("genre", genre);
                }

                writer.WriteEndElement(); // genres
                writer.WriteElement("premiered", SelectedShow.TheSeries()?.FirstAired);
                writer.WriteElement("year", SelectedShow.TheSeries()?.Year);

                //Mede8er Ratings are on a 100 point scale; TVDB are on a 10 point scale
                float siteRating    = SelectedShow.TheSeries()?.SiteRating ?? 0 * 10;
                int   intSiteRating = (int)siteRating;
                if (intSiteRating > 0)
                {
                    writer.WriteElement("rating", intSiteRating);
                }

                writer.WriteElement("status", SelectedShow?.TheSeries()?.Status);
                writer.WriteElement("mpaa", SelectedShow.TheSeries()?.ContentRating);
                writer.WriteInfo("moviedb", "imdb", "id", SelectedShow.TheSeries()?.Imdb);
                writer.WriteElement("tvdbid", SelectedShow.TheSeries()?.TvdbCode);
                string rt = SelectedShow.TheSeries()?.Runtime;
                if (!string.IsNullOrEmpty(rt))
                {
                    writer.WriteElement("runtime", rt + " min");
                }

                writer.WriteElement("plot", SelectedShow.TheSeries()?.Overview);
                writer.WriteStartElement("cast");

                // actors...
                foreach (string aa in
                         SelectedShow.TheSeries()?.GetActorNames().Where(aa => !string.IsNullOrEmpty(aa)) ??
                         new List <string>())
                {
                    writer.WriteElement("actor", aa);
                }

                writer.WriteEndElement(); // cast
                writer.WriteEndElement(); // movie
                writer.WriteEndElement(); // tvshow
            }
        }
Esempio n. 4
0
        private void UpdateShowFields([NotNull] XElement root)
        {
            SeriesInfo series = SelectedShow.TheSeries();

            root.UpdateElement("title", SelectedShow.ShowName);

            float?showRating = series?.SiteRating;

            if (showRating.HasValue)
            {
                UpdateRatings(root, showRating.Value.ToString(CultureInfo.InvariantCulture), series.SiteRatingVotes);
            }

            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>

            XElement episodeGuideNode = root.GetOrCreateElement("episodeguide");
            XElement urlNode          = episodeGuideNode.GetOrCreateElement("url");

            urlNode.UpdateAttribute("post", "yes");
            urlNode.UpdateAttribute("cache", "auth.json");
            urlNode.SetValue(TheTVDB.API.BuildUrl(SelectedShow.TvdbCode, lang));

            if (!(series is null))
            {
                root.UpdateElement("originaltitle", series.Name);
                root.UpdateElement("studio", series.Network);
                root.UpdateElement("id", series.TvdbCode);
                root.UpdateElement("runtime", series.Runtime, true);
                root.UpdateElement("mpaa", series.ContentRating, true);
                root.UpdateElement("premiered", series.FirstAired);
                root.UpdateElement("year", series.Year);
                root.UpdateElement("status", series.Status);
                root.UpdateElement("plot", series.Overview);

                UpdateId(root, "tvdb", "true", series.TvdbCode);
                UpdateId(root, "imdb", "false", series.Imdb);
            }

            root.ReplaceElements("genre", SelectedShow.Genres);

            ReplaceActors(root, SelectedShow.Actors);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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
        }
Esempio n. 8
0
        private bool WriteSeriesXml()
        {
            try
            {
                XmlWriterSettings settings = new XmlWriterSettings
                {
                    Indent = true,
                    NewLineOnAttributes = true
                };

                using (XmlWriter writer = XmlWriter.Create(Where.FullName, settings))
                {
                    writer.WriteStartElement("details");
                    writer.WriteStartElement("show");

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

                    foreach (string genre in SelectedShow.TheSeries().GetGenres())
                    {
                        XmlHelper.WriteElementToXml(writer, "genre", genre);
                    }

                    XmlHelper.WriteElementToXml(writer, "premiered", SelectedShow.TheSeries().GetFirstAired());
                    XmlHelper.WriteElementToXml(writer, "year", SelectedShow.TheSeries().GetYear());

                    float siteRating =
                        float.Parse(SelectedShow.TheSeries().GetSiteRating(), new CultureInfo("en-US")) * 10;

                    int intSiteRating = (int)siteRating;
                    if (intSiteRating > 0)
                    {
                        XmlHelper.WriteElementToXml(writer, "rating", intSiteRating);
                    }

                    XmlHelper.WriteElementToXml(writer, "status", SelectedShow.TheSeries().GetStatus());

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

                    string rt = SelectedShow.TheSeries().GetRuntime();
                    if (!string.IsNullOrEmpty(rt))
                    {
                        XmlHelper.WriteElementToXml(writer, "runtime", rt + " min");
                    }

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

                    writer.WriteEndElement(); // show
                    writer.WriteEndElement(); // tvshow
                }
                Done = true;
                return(true);
            }
            catch (Exception e)
            {
                ErrorText = e.Message;
                Error     = true;
                Done      = true;
                return(false);
            }
        }