2013-10-01 11:24:27 -07:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-06-23 10:48:30 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-06-09 09:23:06 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2013-12-28 22:32:03 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-06-09 09:23:06 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-08-12 12:18:31 -07:00
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
2013-10-01 11:24:27 -07:00
|
|
|
|
using System.Collections.Generic;
|
2013-07-01 09:05:21 -07:00
|
|
|
|
using System.Globalization;
|
2013-06-21 11:50:44 -07:00
|
|
|
|
using System.IO;
|
2013-07-01 09:05:21 -07:00
|
|
|
|
using System.Security;
|
2013-06-23 11:55:30 -07:00
|
|
|
|
using System.Text;
|
2013-06-09 09:23:06 -07:00
|
|
|
|
using System.Threading;
|
2014-02-02 06:36:31 -07:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-06-09 09:23:06 -07:00
|
|
|
|
|
2013-06-09 10:37:16 -07:00
|
|
|
|
namespace MediaBrowser.Providers.Savers
|
2013-06-09 09:23:06 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves movie.xml for movies, trailers and music videos
|
|
|
|
|
/// </summary>
|
2014-02-02 09:59:14 -07:00
|
|
|
|
public class MovieXmlSaver : IMetadataFileSaver
|
2013-06-09 09:23:06 -07:00
|
|
|
|
{
|
2013-06-23 11:55:30 -07:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
2013-08-12 12:18:31 -07:00
|
|
|
|
private readonly IItemRepository _itemRepository;
|
2013-06-23 11:55:30 -07:00
|
|
|
|
|
2013-08-12 12:18:31 -07:00
|
|
|
|
public MovieXmlSaver(IServerConfigurationManager config, IItemRepository itemRepository)
|
2013-06-23 11:55:30 -07:00
|
|
|
|
{
|
|
|
|
|
_config = config;
|
2013-08-12 12:18:31 -07:00
|
|
|
|
_itemRepository = itemRepository;
|
2013-06-23 11:55:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-02-02 22:35:43 -07:00
|
|
|
|
return "Media Browser Xml";
|
2014-02-02 06:36:31 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-09 09:23:06 -07:00
|
|
|
|
/// <summary>
|
2013-06-27 16:01:03 -07:00
|
|
|
|
/// Determines whether [is enabled for] [the specified item].
|
2013-06-09 09:23:06 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
2013-06-27 16:01:03 -07:00
|
|
|
|
/// <param name="updateType">Type of the update.</param>
|
|
|
|
|
/// <returns><c>true</c> if [is enabled for] [the specified item]; otherwise, <c>false</c>.</returns>
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType)
|
2013-06-09 09:23:06 -07:00
|
|
|
|
{
|
2013-06-28 07:11:09 -07:00
|
|
|
|
var wasMetadataEdited = (updateType & ItemUpdateType.MetadataEdit) == ItemUpdateType.MetadataEdit;
|
|
|
|
|
var wasMetadataDownloaded = (updateType & ItemUpdateType.MetadataDownload) == ItemUpdateType.MetadataDownload;
|
|
|
|
|
|
2013-10-02 07:14:10 -07:00
|
|
|
|
// If new metadata has been downloaded and save local is on
|
2014-01-01 11:26:31 -07:00
|
|
|
|
if (item.IsSaveLocalMetadataEnabled() && (wasMetadataEdited || wasMetadataDownloaded))
|
2013-06-09 09:23:06 -07:00
|
|
|
|
{
|
2014-02-02 06:36:31 -07:00
|
|
|
|
var video = item as Video;
|
2013-12-28 22:32:03 -07:00
|
|
|
|
// Check parent for null to avoid running this against things like video backdrops
|
2014-02-05 21:39:16 -07:00
|
|
|
|
return video != null && !(item is Episode) && !video.IsOwnedItem;
|
2013-06-09 09:23:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 16:01:03 -07:00
|
|
|
|
return false;
|
2013-06-09 09:23:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-01 09:00:20 -07:00
|
|
|
|
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
2013-07-01 09:12:03 -07:00
|
|
|
|
|
2013-06-09 09:23:06 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public void Save(IHasMetadata item, CancellationToken cancellationToken)
|
2013-06-09 09:23:06 -07:00
|
|
|
|
{
|
2014-02-02 06:36:31 -07:00
|
|
|
|
var video = (Video)item;
|
|
|
|
|
|
2013-06-23 10:48:30 -07:00
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
builder.Append("<Title>");
|
|
|
|
|
|
2014-02-02 06:36:31 -07:00
|
|
|
|
XmlSaverHelpers.AddCommonNodes(video, builder);
|
2013-07-01 09:00:20 -07:00
|
|
|
|
|
2014-02-02 06:36:31 -07:00
|
|
|
|
if (video.CommunityRating.HasValue)
|
2013-07-01 09:00:20 -07:00
|
|
|
|
{
|
2014-02-02 06:36:31 -07:00
|
|
|
|
builder.Append("<IMDBrating>" + SecurityElement.Escape(video.CommunityRating.Value.ToString(UsCulture)) + "</IMDBrating>");
|
2013-07-01 09:00:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 06:36:31 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(video.Overview))
|
2013-07-01 09:00:20 -07:00
|
|
|
|
{
|
2014-02-02 06:36:31 -07:00
|
|
|
|
builder.Append("<Description><![CDATA[" + video.Overview + "]]></Description>");
|
2013-07-01 09:00:20 -07:00
|
|
|
|
}
|
2013-07-01 09:12:03 -07:00
|
|
|
|
|
2013-07-10 13:25:47 -07:00
|
|
|
|
var musicVideo = item as MusicVideo;
|
|
|
|
|
|
|
|
|
|
if (musicVideo != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(musicVideo.Artist))
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<Artist>" + SecurityElement.Escape(musicVideo.Artist) + "</Artist>");
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(musicVideo.Album))
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<Album>" + SecurityElement.Escape(musicVideo.Album) + "</Album>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-17 08:34:47 -07:00
|
|
|
|
var movie = item as Movie;
|
|
|
|
|
|
|
|
|
|
if (movie != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(movie.TmdbCollectionName))
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<TmdbCollectionName>" + SecurityElement.Escape(movie.TmdbCollectionName) + "</TmdbCollectionName>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-30 16:55:17 -07:00
|
|
|
|
XmlSaverHelpers.AddMediaInfo(video, builder, _itemRepository);
|
2013-08-12 12:18:31 -07:00
|
|
|
|
|
2013-06-23 10:48:30 -07:00
|
|
|
|
builder.Append("</Title>");
|
2013-06-09 18:40:53 -07:00
|
|
|
|
|
2013-06-21 11:50:44 -07:00
|
|
|
|
var xmlFilePath = GetSavePath(item);
|
2013-06-09 18:40:53 -07:00
|
|
|
|
|
2013-09-25 08:11:23 -07:00
|
|
|
|
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string>
|
2013-07-01 09:00:20 -07:00
|
|
|
|
{
|
|
|
|
|
"IMDBrating",
|
2013-07-12 12:56:40 -07:00
|
|
|
|
"Description",
|
|
|
|
|
"Artist",
|
2013-11-21 09:02:31 -07:00
|
|
|
|
"Album",
|
|
|
|
|
"TmdbCollectionName"
|
2013-07-01 09:00:20 -07:00
|
|
|
|
});
|
2013-06-23 10:48:30 -07:00
|
|
|
|
}
|
2013-06-21 11:50:44 -07:00
|
|
|
|
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public string GetSavePath(IHasMetadata item)
|
2013-10-01 11:24:27 -07:00
|
|
|
|
{
|
2014-02-02 06:36:31 -07:00
|
|
|
|
return GetMovieSavePath((Video)item);
|
2013-10-01 11:24:27 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public static string GetMovieSavePath(Video item)
|
2013-06-21 11:50:44 -07:00
|
|
|
|
{
|
2013-08-26 08:14:59 -07:00
|
|
|
|
if (item.IsInMixedFolder)
|
|
|
|
|
{
|
|
|
|
|
return Path.ChangeExtension(item.Path, ".xml");
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 21:39:16 -07:00
|
|
|
|
return Path.Combine(item.ContainingFolderPath, "movie.xml");
|
2013-06-21 11:50:44 -07:00
|
|
|
|
}
|
2013-06-09 09:23:06 -07:00
|
|
|
|
}
|
|
|
|
|
}
|