From d6cf7b51acda145d32c9944f1b66728c7e09a9f8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 23 Jun 2013 13:48:30 -0400 Subject: added movie, series, folder and episode xml saving support --- MediaBrowser.Providers/Savers/XmlHelpers.cs | 346 ++++++++++++++++++++++++++++ 1 file changed, 346 insertions(+) create mode 100644 MediaBrowser.Providers/Savers/XmlHelpers.cs (limited to 'MediaBrowser.Providers/Savers/XmlHelpers.cs') diff --git a/MediaBrowser.Providers/Savers/XmlHelpers.cs b/MediaBrowser.Providers/Savers/XmlHelpers.cs new file mode 100644 index 000000000..3838f6669 --- /dev/null +++ b/MediaBrowser.Providers/Savers/XmlHelpers.cs @@ -0,0 +1,346 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Model.Entities; +using System; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Security; +using System.Text; +using System.Xml; + +namespace MediaBrowser.Providers.Savers +{ + /// + /// Class XmlHelpers + /// + public static class XmlHelpers + { + /// + /// The us culture + /// + private static readonly CultureInfo UsCulture = new CultureInfo("en-US"); + + /// + /// Saves the specified XML. + /// + /// The XML. + /// The path. + public static void Save(StringBuilder xml, string path) + { + var xmlDocument = new XmlDocument(); + xmlDocument.LoadXml(xml.ToString()); + + //Add the new node to the document. + xmlDocument.InsertBefore(xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", "yes"), xmlDocument.DocumentElement); + + using (var streamWriter = new StreamWriter(path, false, Encoding.UTF8)) + { + xmlDocument.Save(streamWriter); + } + } + + /// + /// Adds the common nodes. + /// + /// The item. + /// The builder. + public static void AddCommonNodes(BaseItem item, StringBuilder builder) + { + if (!string.IsNullOrEmpty(item.OfficialRating)) + { + builder.Append("" + SecurityElement.Escape(item.OfficialRating) + ""); + builder.Append("" + SecurityElement.Escape(item.OfficialRating) + ""); + builder.Append("" + SecurityElement.Escape(item.OfficialRating) + ""); + } + + if (item.People.Count > 0) + { + builder.Append(""); + + foreach (var person in item.People) + { + builder.Append(""); + builder.Append("" + SecurityElement.Escape(person.Name) + ""); + builder.Append("" + SecurityElement.Escape(person.Type) + ""); + builder.Append("" + SecurityElement.Escape(person.Role) + ""); + builder.Append(""); + } + + builder.Append(""); + } + + if (!string.IsNullOrEmpty(item.DisplayMediaType)) + { + builder.Append("" + SecurityElement.Escape(item.DisplayMediaType) + ""); + } + + if (!string.IsNullOrEmpty(item.Overview)) + { + builder.Append(""); + } + + if (!string.IsNullOrEmpty(item.CustomRating)) + { + builder.Append("" + SecurityElement.Escape(item.CustomRating) + ""); + } + + if (!string.IsNullOrEmpty(item.Name) && !(item is Episode)) + { + builder.Append("" + SecurityElement.Escape(item.Name) + ""); + } + + if (!string.IsNullOrEmpty(item.ForcedSortName)) + { + builder.Append("" + SecurityElement.Escape(item.ForcedSortName) + ""); + } + + if (item.Budget.HasValue) + { + builder.Append("" + SecurityElement.Escape(item.Budget.Value.ToString(UsCulture)) + ""); + } + + if (item.Revenue.HasValue) + { + builder.Append("" + SecurityElement.Escape(item.Revenue.Value.ToString(UsCulture)) + ""); + } + + if (item.CommunityRating.HasValue) + { + builder.Append("" + SecurityElement.Escape(item.CommunityRating.Value.ToString(UsCulture)) + ""); + } + + if (item.ProductionYear.HasValue) + { + builder.Append("" + SecurityElement.Escape(item.ProductionYear.Value.ToString(UsCulture)) + ""); + } + + if (!string.IsNullOrEmpty(item.HomePageUrl)) + { + builder.Append("" + SecurityElement.Escape(item.HomePageUrl) + ""); + } + + if (!string.IsNullOrEmpty(item.AspectRatio)) + { + builder.Append("" + SecurityElement.Escape(item.AspectRatio) + ""); + } + + if (!string.IsNullOrEmpty(item.Language)) + { + builder.Append("" + SecurityElement.Escape(item.Language) + ""); + } + + if (item.RunTimeTicks.HasValue) + { + var timespan = TimeSpan.FromTicks(item.RunTimeTicks.Value); + + builder.Append("" + Convert.ToInt32(timespan.TotalMinutes).ToString(UsCulture) + ""); + builder.Append("" + Convert.ToInt32(timespan.TotalMinutes).ToString(UsCulture) + ""); + } + + if (item.Taglines.Count > 0) + { + builder.Append("" + SecurityElement.Escape(item.Taglines[0]) + ""); + + builder.Append(""); + + foreach (var tagline in item.Taglines) + { + builder.Append("" + SecurityElement.Escape(tagline) + ""); + } + + builder.Append(""); + } + + var imdb = item.GetProviderId(MetadataProviders.Imdb); + + if (!string.IsNullOrEmpty(imdb)) + { + builder.Append("" + SecurityElement.Escape(imdb) + ""); + builder.Append("" + SecurityElement.Escape(imdb) + ""); + builder.Append("" + SecurityElement.Escape(imdb) + ""); + } + + var tmdb = item.GetProviderId(MetadataProviders.Tmdb); + + if (!string.IsNullOrEmpty(tmdb)) + { + builder.Append("" + SecurityElement.Escape(tmdb) + ""); + } + + var tvcom = item.GetProviderId(MetadataProviders.Tvcom); + + if (!string.IsNullOrEmpty(tvcom)) + { + builder.Append("" + SecurityElement.Escape(tvcom) + ""); + } + + var rt = item.GetProviderId(MetadataProviders.RottenTomatoes); + + if (!string.IsNullOrEmpty(rt)) + { + builder.Append("" + SecurityElement.Escape(rt) + ""); + } + + var tmdbCollection = item.GetProviderId(MetadataProviders.TmdbCollection); + + if (!string.IsNullOrEmpty(tmdbCollection)) + { + builder.Append("" + SecurityElement.Escape(tmdbCollection) + ""); + } + + if (item.Genres.Count > 0) + { + builder.Append(""); + + foreach (var genre in item.Genres) + { + builder.Append("" + SecurityElement.Escape(genre) + ""); + } + + builder.Append(""); + } + + if (item.Studios.Count > 0) + { + builder.Append(""); + + foreach (var studio in item.Studios) + { + builder.Append("" + SecurityElement.Escape(studio) + ""); + } + + builder.Append(""); + } + + builder.Append("" + SecurityElement.Escape(item.DateCreated.ToString(UsCulture)) + ""); + } + + /// + /// Appends the media info. + /// + /// + /// The item. + /// The builder. + public static void AppendMediaInfo(T item, StringBuilder builder) + where T : BaseItem, IHasMediaStreams + { + builder.Append(""); + + foreach (var stream in item.MediaStreams) + { + if (stream.Type == MediaStreamType.Video) + { + builder.Append(""); + } + else if (stream.Type == MediaStreamType.Audio) + { + builder.Append(""); + } + else if (stream.Type == MediaStreamType.Subtitle) + { + builder.Append(""); + + if (!string.IsNullOrEmpty(stream.Language)) + { + builder.Append("" + SecurityElement.Escape(stream.Language) + ""); + } + + builder.Append("" + SecurityElement.Escape(stream.IsDefault.ToString()) + ""); + builder.Append("" + SecurityElement.Escape(stream.IsForced.ToString()) + ""); + + builder.Append(""); + } + } + + builder.Append(""); + } + } +} -- cgit v1.2.3