Exemple #1
0
        private static void UpdateEpisodeFields([NotNull] Episode episode, ShowConfiguration?show, [NotNull] XElement root, bool isMultiPart)
        {
            root.UpdateElement("title", episode.Name, true);
            root.UpdateElement("id", episode.EpisodeId, true);
            root.UpdateElement("plot", episode.Overview, true);
            UpdateAmongstElements(root, "studio", episode.TheCachedSeries.Network);

            UpdateId(root, "tvdb", "true", episode.EpisodeId);
            UpdateId(root, "imdb", "false", episode.ImdbCode);

            string showRating = episode.EpisodeRating;

            if (showRating != null)
            {
                UpdateRatings(root, showRating, episode.SiteRatingCount ?? 0);
            }

            if (!(show is null))
            {
                root.UpdateElement("originaltitle", show.ShowName, true);
                root.UpdateElement("showtitle", show.ShowName, true);
                root.UpdateElement("season", episode.GetSeasonNumber(show.Order), true);
                root.UpdateElement("episode", episode.GetEpisodeNumber(show.Order), true);
                root.UpdateElement("mpaa", show.CachedShow?.ContentRating, true);

                //actor(s) and guest actor(s)
                CachedSeriesInfo s = show.CachedShow;
                if (s != null)
                {
                    ReplaceActors(root, episode.AllActors(s));
                }
            }

            if (episode.FirstAired.HasValue)
            {
                root.UpdateElement("aired", episode.FirstAired.Value.ToString("yyyy-MM-dd"), true);
            }

            //Director(s)
            string?epDirector = episode.EpisodeDirector;

            if (!string.IsNullOrEmpty(epDirector))
            {
                string[] dirs = epDirector.Split('|');
                if (dirs.Any())
                {
                    root.ReplaceElements("director", dirs);
                }
            }

            //Writers(s)
            string?epWriter = episode.Writer;

            if (!string.IsNullOrEmpty(epWriter))
            {
                string[] writers = epWriter.Split('|');
                if (writers.Any())
                {
                    root.ReplaceElements("credits", writers);
                }
            }

            if (isMultiPart && show != null)
            {
                XElement resumeElement = root.GetOrCreateElement("resume");

                //we have to put 0 as we don't know where the multipart episode starts/ends
                resumeElement.UpdateElement("position", 0);
                resumeElement.UpdateElement("total", 0);

                //For now we only put art in for multipart episodes. Kodi finds the art appropriately
                //without our help for the others

                string filename = TVSettings.Instance.FilenameFriendly(show, episode);

                string thumbFilename = filename + ".jpg";
                UpdateAmongstElements(root, "thumb", thumbFilename);
                //Should be able to do this using the local filename, but only seems to work if you provide a URL
                //XMLHelper.WriteElementToXML(writer, "thumb", LocalCache.Instance.GetTVDBDownloadURL(episode.GetFilename()))
            }
        }