fixes for saving media info xml

pull/702/head
Luke Pulverenti 12 years ago
parent 673bc9d31b
commit d94c8495b8

@ -78,7 +78,7 @@ namespace MediaBrowser.Providers.Savers
} }
XmlSaverHelpers.AddCommonNodes(item, builder); XmlSaverHelpers.AddCommonNodes(item, builder);
XmlSaverHelpers.AppendMediaInfo(episode, builder); XmlSaverHelpers.AddMediaInfo(episode, builder);
builder.Append("</Item>"); builder.Append("</Item>");

@ -1,4 +1,6 @@
using MediaBrowser.Controller.Configuration; using System.Globalization;
using System.Security;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
@ -51,6 +53,8 @@ namespace MediaBrowser.Providers.Savers
return false; return false;
} }
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
/// <summary> /// <summary>
/// Saves the specified item. /// Saves the specified item.
/// </summary> /// </summary>
@ -64,13 +68,28 @@ namespace MediaBrowser.Providers.Savers
builder.Append("<Title>"); builder.Append("<Title>");
XmlSaverHelpers.AddCommonNodes(item, builder); XmlSaverHelpers.AddCommonNodes(item, builder);
XmlSaverHelpers.AppendMediaInfo((Video)item, builder);
if (item.CommunityRating.HasValue)
{
builder.Append("<IMDBrating>" + SecurityElement.Escape(item.CommunityRating.Value.ToString(UsCulture)) + "</IMDBrating>");
}
if (!string.IsNullOrEmpty(item.Overview))
{
builder.Append("<Description><![CDATA[" + item.Overview + "]]></Description>");
}
XmlSaverHelpers.AddMediaInfo((Video)item, builder);
builder.Append("</Title>"); builder.Append("</Title>");
var xmlFilePath = GetSavePath(item); var xmlFilePath = GetSavePath(item);
XmlSaverHelpers.Save(builder, xmlFilePath, new string[] { }); XmlSaverHelpers.Save(builder, xmlFilePath, new[]
{
"IMDBrating",
"Description"
});
// Set last refreshed so that the provider doesn't trigger after the file save // Set last refreshed so that the provider doesn't trigger after the file save
MovieProviderFromXml.Current.SetLastRefreshed(item, DateTime.UtcNow); MovieProviderFromXml.Current.SetLastRefreshed(item, DateTime.UtcNow);

@ -57,7 +57,7 @@ namespace MediaBrowser.Providers.Savers
"RunningTime", "RunningTime",
"Runtime", "Runtime",
"TagLine", "TagLine",
"TagLines", "Taglines",
"IMDB_ID", "IMDB_ID",
"IMDB", "IMDB",
"IMDbId", "IMDbId",
@ -71,7 +71,9 @@ namespace MediaBrowser.Providers.Savers
"Tags", "Tags",
"Added", "Added",
"LockData", "LockData",
"Trailer" "Trailer",
"CriticRating",
"CriticRatingSummary"
}); });
var position = xml.ToString().LastIndexOf("</", StringComparison.OrdinalIgnoreCase); var position = xml.ToString().LastIndexOf("</", StringComparison.OrdinalIgnoreCase);
@ -299,14 +301,14 @@ namespace MediaBrowser.Providers.Savers
{ {
builder.Append("<TagLine>" + SecurityElement.Escape(item.Taglines[0]) + "</TagLine>"); builder.Append("<TagLine>" + SecurityElement.Escape(item.Taglines[0]) + "</TagLine>");
builder.Append("<TagLines>"); builder.Append("<Taglines>");
foreach (var tagline in item.Taglines) foreach (var tagline in item.Taglines)
{ {
builder.Append("<Tagline>" + SecurityElement.Escape(tagline) + "</Tagline>"); builder.Append("<Tagline>" + SecurityElement.Escape(tagline) + "</Tagline>");
} }
builder.Append("</TagLines>"); builder.Append("</Taglines>");
} }
if (item.Genres.Count > 0) if (item.Genres.Count > 0)
@ -369,60 +371,73 @@ namespace MediaBrowser.Providers.Savers
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
/// <param name="builder">The builder.</param> /// <param name="builder">The builder.</param>
public static void AppendMediaInfo<T>(T item, StringBuilder builder) public static void AddMediaInfo<T>(T item, StringBuilder builder)
where T : BaseItem, IHasMediaStreams where T : BaseItem, IHasMediaStreams
{ {
builder.Append("<MediaInfo>"); builder.Append("<MediaInfo>");
foreach (var stream in item.MediaStreams) foreach (var stream in item.MediaStreams)
{ {
if (stream.Type == MediaStreamType.Video) builder.Append("<" + stream.Type + ">");
if (!string.IsNullOrEmpty(stream.Codec))
{ {
builder.Append("<Video>"); builder.Append("<Codec>" + SecurityElement.Escape(stream.Codec) + "</Codec>");
builder.Append("<FFCodec>" + SecurityElement.Escape(stream.Codec) + "</FFCodec>");
}
if (!string.IsNullOrEmpty(stream.Codec)) if (stream.BitRate.HasValue)
{ {
builder.Append("<Codec>" + SecurityElement.Escape(stream.Codec) + "</Codec>"); builder.Append("<BitRate>" + stream.BitRate.Value.ToString(UsCulture) + "</BitRate>");
builder.Append("<FFCodec>" + SecurityElement.Escape(stream.Codec) + "</FFCodec>"); }
}
if (stream.BitRate.HasValue) if (stream.Width.HasValue)
{ {
builder.Append("<BitRate>" + stream.BitRate.Value.ToString(UsCulture) + "</BitRate>"); builder.Append("<Width>" + stream.Width.Value.ToString(UsCulture) + "</Width>");
} }
if (stream.Width.HasValue) if (stream.Height.HasValue)
{ {
builder.Append("<Width>" + stream.Width.Value.ToString(UsCulture) + "</Width>"); builder.Append("<Height>" + stream.Height.Value.ToString(UsCulture) + "</Height>");
} }
if (stream.Height.HasValue) if (!string.IsNullOrEmpty(stream.AspectRatio))
{ {
builder.Append("<Height>" + stream.Height.Value.ToString(UsCulture) + "</Height>"); builder.Append("<AspectRatio>" + SecurityElement.Escape(stream.AspectRatio) + "</AspectRatio>");
} }
if (!string.IsNullOrEmpty(stream.AspectRatio)) var framerate = stream.AverageFrameRate ?? stream.RealFrameRate;
{
builder.Append("<AspectRatio>" + SecurityElement.Escape(stream.AspectRatio) + "</AspectRatio>");
}
var framerate = stream.AverageFrameRate ?? stream.RealFrameRate; if (framerate.HasValue)
{
builder.Append("<FrameRate>" + framerate.Value.ToString(UsCulture) + "</FrameRate>");
}
if (framerate.HasValue) if (!string.IsNullOrEmpty(stream.Language))
{ {
builder.Append("<FrameRate>" + framerate.Value.ToString(UsCulture) + "</FrameRate>"); builder.Append("<Language>" + SecurityElement.Escape(stream.Language) + "</Language>");
} }
if (!string.IsNullOrEmpty(stream.Language)) if (!string.IsNullOrEmpty(stream.ScanType))
{ {
builder.Append("<Language>" + SecurityElement.Escape(stream.Language) + "</Language>"); builder.Append("<ScanType>" + SecurityElement.Escape(stream.ScanType) + "</ScanType>");
} }
if (stream.Channels.HasValue)
{
builder.Append("<Channels>" + stream.Channels.Value.ToString(UsCulture) + "</Channels>");
}
if (!string.IsNullOrEmpty(stream.ScanType)) if (stream.SampleRate.HasValue)
{ {
builder.Append("<ScanType>" + SecurityElement.Escape(stream.ScanType) + "</ScanType>"); builder.Append("<SamplingRate>" + stream.SampleRate.Value.ToString(UsCulture) + "</SamplingRate>");
} }
builder.Append("<Default>" + SecurityElement.Escape(stream.IsDefault.ToString()) + "</Default>");
builder.Append("<Forced>" + SecurityElement.Escape(stream.IsForced.ToString()) + "</Forced>");
if (stream.Type == MediaStreamType.Video)
{
if (item.RunTimeTicks.HasValue) if (item.RunTimeTicks.HasValue)
{ {
var timespan = TimeSpan.FromTicks(item.RunTimeTicks.Value); var timespan = TimeSpan.FromTicks(item.RunTimeTicks.Value);
@ -431,9 +446,6 @@ namespace MediaBrowser.Providers.Savers
builder.Append("<DurationSeconds>" + Convert.ToInt32(timespan.TotalSeconds).ToString(UsCulture) + "</DurationSeconds>"); builder.Append("<DurationSeconds>" + Convert.ToInt32(timespan.TotalSeconds).ToString(UsCulture) + "</DurationSeconds>");
} }
builder.Append("<Default>" + SecurityElement.Escape(stream.IsDefault.ToString()) + "</Default>");
builder.Append("<Forced>" + SecurityElement.Escape(stream.IsForced.ToString()) + "</Forced>");
var video = item as Video; var video = item as Video;
if (video != null && video.Video3DFormat.HasValue) if (video != null && video.Video3DFormat.HasValue)
@ -454,58 +466,9 @@ namespace MediaBrowser.Providers.Savers
break; break;
} }
} }
builder.Append("</Video>");
}
else if (stream.Type == MediaStreamType.Audio)
{
builder.Append("<Audio>");
if (!string.IsNullOrEmpty(stream.Codec))
{
builder.Append("<Codec>" + SecurityElement.Escape(stream.Codec) + "</Codec>");
builder.Append("<FFCodec>" + SecurityElement.Escape(stream.Codec) + "</FFCodec>");
}
if (stream.Channels.HasValue)
{
builder.Append("<Channels>" + stream.Channels.Value.ToString(UsCulture) + "</Channels>");
}
if (stream.BitRate.HasValue)
{
builder.Append("<BitRate>" + stream.BitRate.Value.ToString(UsCulture) + "</BitRate>");
}
if (stream.SampleRate.HasValue)
{
builder.Append("<SamplingRate>" + stream.SampleRate.Value.ToString(UsCulture) + "</SamplingRate>");
}
if (!string.IsNullOrEmpty(stream.Language))
{
builder.Append("<Language>" + SecurityElement.Escape(stream.Language) + "</Language>");
}
builder.Append("<Default>" + SecurityElement.Escape(stream.IsDefault.ToString()) + "</Default>");
builder.Append("<Forced>" + SecurityElement.Escape(stream.IsForced.ToString()) + "</Forced>");
builder.Append("</Audio>");
}
else if (stream.Type == MediaStreamType.Subtitle)
{
builder.Append("<Subtitle>");
if (!string.IsNullOrEmpty(stream.Language))
{
builder.Append("<Language>" + SecurityElement.Escape(stream.Language) + "</Language>");
}
builder.Append("<Default>" + SecurityElement.Escape(stream.IsDefault.ToString()) + "</Default>");
builder.Append("<Forced>" + SecurityElement.Escape(stream.IsForced.ToString()) + "</Forced>");
builder.Append("</Subtitle>");
} }
builder.Append("</" + stream.Type + ">");
} }
builder.Append("</MediaInfo>"); builder.Append("</MediaInfo>");

Loading…
Cancel
Save