2014-09-06 04:21:23 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-06-30 03:04:50 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
2014-09-06 04:21:23 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Security;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
2013-06-09 16:23:06 +00:00
|
|
|
|
|
2014-06-30 03:04:50 +00:00
|
|
|
|
namespace MediaBrowser.LocalMetadata.Savers
|
2013-06-09 16:23:06 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves movie.xml for movies, trailers and music videos
|
|
|
|
|
/// </summary>
|
2014-02-02 16:59:14 +00:00
|
|
|
|
public class MovieXmlSaver : IMetadataFileSaver
|
2013-06-09 16:23:06 +00:00
|
|
|
|
{
|
2013-08-12 19:18:31 +00:00
|
|
|
|
private readonly IItemRepository _itemRepository;
|
2014-09-06 04:21:23 +00:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
2015-01-04 05:55:34 +00:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-06-23 18:55:30 +00:00
|
|
|
|
|
2015-01-04 05:55:34 +00:00
|
|
|
|
public MovieXmlSaver(IItemRepository itemRepository, IServerConfigurationManager config, ILibraryManager libraryManager)
|
2013-06-23 18:55:30 +00:00
|
|
|
|
{
|
2013-08-12 19:18:31 +00:00
|
|
|
|
_itemRepository = itemRepository;
|
2014-09-06 04:21:23 +00:00
|
|
|
|
_config = config;
|
2015-01-04 05:55:34 +00:00
|
|
|
|
_libraryManager = libraryManager;
|
2013-06-23 18:55:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 13:36:31 +00:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-11-11 03:41:55 +00:00
|
|
|
|
return XmlProviderUtils.Name;
|
2014-02-02 13:36:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-09 16:23:06 +00:00
|
|
|
|
/// <summary>
|
2013-06-27 23:01:03 +00:00
|
|
|
|
/// Determines whether [is enabled for] [the specified item].
|
2013-06-09 16:23:06 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
2013-06-27 23:01:03 +00: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 13:36:31 +00:00
|
|
|
|
public bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType)
|
2013-06-09 16:23:06 +00:00
|
|
|
|
{
|
2014-02-10 20:11:46 +00:00
|
|
|
|
if (!item.SupportsLocalMetadata)
|
2014-02-08 20:02:35 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-11 21:41:01 +00:00
|
|
|
|
var video = item as Video;
|
2013-06-28 14:11:09 +00:00
|
|
|
|
|
2014-02-11 21:41:01 +00:00
|
|
|
|
// Check parent for null to avoid running this against things like video backdrops
|
|
|
|
|
if (video != null && !(item is Episode) && !video.IsOwnedItem)
|
2013-06-09 16:23:06 +00:00
|
|
|
|
{
|
2014-02-11 21:41:01 +00:00
|
|
|
|
return updateType >= ItemUpdateType.MetadataDownload;
|
2013-06-09 16:23:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 23:01:03 +00:00
|
|
|
|
return false;
|
2013-06-09 16:23:06 +00: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 13:36:31 +00:00
|
|
|
|
public void Save(IHasMetadata item, CancellationToken cancellationToken)
|
2013-06-09 16:23:06 +00:00
|
|
|
|
{
|
2014-02-02 13:36:31 +00:00
|
|
|
|
var video = (Video)item;
|
|
|
|
|
|
2013-06-23 17:48:30 +00:00
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
builder.Append("<Title>");
|
|
|
|
|
|
2015-06-21 03:35:22 +00:00
|
|
|
|
XmlSaverHelpers.AddCommonNodes(video, _libraryManager, builder);
|
2013-07-01 16:00:20 +00:00
|
|
|
|
|
2013-07-10 20:25:47 +00:00
|
|
|
|
var musicVideo = item as MusicVideo;
|
|
|
|
|
|
|
|
|
|
if (musicVideo != null)
|
|
|
|
|
{
|
2014-10-20 20:23:40 +00:00
|
|
|
|
if (musicVideo.Artists.Count > 0)
|
2013-07-10 20:25:47 +00:00
|
|
|
|
{
|
2014-10-20 20:23:40 +00:00
|
|
|
|
builder.Append("<Artist>" + SecurityElement.Escape(string.Join(";", musicVideo.Artists.ToArray())) + "</Artist>");
|
2013-07-10 20:25:47 +00:00
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(musicVideo.Album))
|
|
|
|
|
{
|
|
|
|
|
builder.Append("<Album>" + SecurityElement.Escape(musicVideo.Album) + "</Album>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-17 15:34:47 +00: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 23:55:17 +00:00
|
|
|
|
XmlSaverHelpers.AddMediaInfo(video, builder, _itemRepository);
|
2013-08-12 19:18:31 +00:00
|
|
|
|
|
2013-06-23 17:48:30 +00:00
|
|
|
|
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-09-25 15:11:23 +00:00
|
|
|
|
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string>
|
2013-07-01 16:00:20 +00:00
|
|
|
|
{
|
2014-03-25 05:25:03 +00:00
|
|
|
|
// Deprecated. No longer saving in this field.
|
2013-07-01 16:00:20 +00:00
|
|
|
|
"IMDBrating",
|
2014-03-25 05:25:03 +00:00
|
|
|
|
|
|
|
|
|
// Deprecated. No longer saving in this field.
|
2013-07-12 19:56:40 +00:00
|
|
|
|
"Description",
|
2014-03-25 05:25:03 +00:00
|
|
|
|
|
2013-07-12 19:56:40 +00:00
|
|
|
|
"Artist",
|
2013-11-21 16:02:31 +00:00
|
|
|
|
"Album",
|
|
|
|
|
"TmdbCollectionName"
|
2014-09-06 04:21:23 +00:00
|
|
|
|
}, _config);
|
2013-06-23 17:48:30 +00:00
|
|
|
|
}
|
2013-06-21 18:50:44 +00:00
|
|
|
|
|
2014-02-02 13:36:31 +00:00
|
|
|
|
public string GetSavePath(IHasMetadata item)
|
2013-10-01 18:24:27 +00:00
|
|
|
|
{
|
2014-02-02 13:36:31 +00:00
|
|
|
|
return GetMovieSavePath((Video)item);
|
2013-10-01 18:24:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 13:36:31 +00:00
|
|
|
|
public static string GetMovieSavePath(Video item)
|
2013-06-21 18:50:44 +00:00
|
|
|
|
{
|
2013-08-26 15:14:59 +00:00
|
|
|
|
if (item.IsInMixedFolder)
|
|
|
|
|
{
|
|
|
|
|
return Path.ChangeExtension(item.Path, ".xml");
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 04:39:16 +00:00
|
|
|
|
return Path.Combine(item.ContainingFolderPath, "movie.xml");
|
2013-06-21 18:50:44 +00:00
|
|
|
|
}
|
2013-06-09 16:23:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|