2013-06-23 17:48:30 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-06-09 16:23:06 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-06-23 17:48:30 +00:00
|
|
|
|
using MediaBrowser.Providers.Movies;
|
|
|
|
|
using System;
|
2013-06-21 18:50:44 +00:00
|
|
|
|
using System.IO;
|
2013-06-09 16:23:06 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
2013-06-09 17:37:16 +00:00
|
|
|
|
namespace MediaBrowser.Providers.Savers
|
2013-06-09 16:23:06 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves movie.xml for movies, trailers and music videos
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class MovieXmlSaver : IMetadataSaver
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supportses the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
public bool Supports(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
if (item.LocationType != LocationType.FileSystem)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var trailer = item as Trailer;
|
|
|
|
|
|
|
|
|
|
if (trailer != null)
|
|
|
|
|
{
|
|
|
|
|
return !trailer.IsLocalTrailer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Don't support local trailers
|
|
|
|
|
return item is Movie || item is MusicVideo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2013-06-23 17:48:30 +00:00
|
|
|
|
public void Save(BaseItem item, CancellationToken cancellationToken)
|
2013-06-09 16:23:06 +00:00
|
|
|
|
{
|
2013-06-23 17:48:30 +00:00
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
builder.Append("<Title>");
|
|
|
|
|
|
|
|
|
|
XmlHelpers.AddCommonNodes(item, builder);
|
|
|
|
|
|
|
|
|
|
builder.Append("</Title>");
|
2013-06-10 01:40:53 +00:00
|
|
|
|
|
2013-06-21 18:50:44 +00:00
|
|
|
|
var xmlFilePath = GetSavePath(item);
|
2013-06-10 01:40:53 +00:00
|
|
|
|
|
2013-06-23 17:48:30 +00:00
|
|
|
|
XmlHelpers.Save(builder, xmlFilePath);
|
2013-06-21 18:50:44 +00:00
|
|
|
|
|
2013-06-23 17:48:30 +00:00
|
|
|
|
// Set last refreshed so that the provider doesn't trigger after the file save
|
|
|
|
|
MovieProviderFromXml.Current.SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
|
|
}
|
2013-06-21 18:50:44 +00:00
|
|
|
|
|
|
|
|
|
public string GetSavePath(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
var video = (Video)item;
|
|
|
|
|
|
|
|
|
|
var directory = video.VideoType == VideoType.Iso || video.VideoType == VideoType.VideoFile ? Path.GetDirectoryName(video.Path) : video.Path;
|
|
|
|
|
|
|
|
|
|
return Path.Combine(directory, "movie.xml");
|
|
|
|
|
}
|
2013-06-09 16:23:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|