2014-06-29 20:04:50 -07:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2015-05-15 08:46:20 -07:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-07-11 19:31:08 -07:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2015-05-15 08:46:20 -07:00
|
|
|
|
using System.Linq;
|
2014-07-08 17:46:11 -07:00
|
|
|
|
using System.Xml;
|
2015-10-03 21:23:11 -07:00
|
|
|
|
using CommonIO;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.XbmcMetadata.Savers
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
public class MovieNfoSaver : BaseNfoSaver
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-11 19:31:08 -07:00
|
|
|
|
public MovieNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 21:42:26 -07:00
|
|
|
|
protected override string GetLocalSavePath(IHasMetadata item)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2015-05-15 08:46:20 -07:00
|
|
|
|
return GetMovieSavePaths(new ItemInfo(item), FileSystem).FirstOrDefault();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-15 08:46:20 -07:00
|
|
|
|
public static List<string> GetMovieSavePaths(ItemInfo item, IFileSystem fileSystem)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2015-05-15 08:46:20 -07:00
|
|
|
|
var list = new List<string>();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2015-10-08 09:22:14 -07:00
|
|
|
|
if (item.VideoType == VideoType.Dvd && !item.IsPlaceHolder)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
|
|
|
|
var path = item.ContainingFolderPath;
|
|
|
|
|
|
2015-05-21 13:53:14 -07:00
|
|
|
|
list.Add(Path.Combine(path, "VIDEO_TS", "VIDEO_TS.nfo"));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-15 08:46:20 -07:00
|
|
|
|
if (item.VideoType == VideoType.Dvd || item.VideoType == VideoType.BluRay || item.VideoType == VideoType.HdDvd)
|
|
|
|
|
{
|
|
|
|
|
var path = item.ContainingFolderPath;
|
|
|
|
|
|
|
|
|
|
list.Add(Path.Combine(path, Path.GetFileName(path) + ".nfo"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
list.Add(Path.ChangeExtension(item.Path, ".nfo"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
protected override string GetRootElementName(IHasMetadata item)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
return item is MusicVideo ? "musicvideo" : "movie";
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
public override bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType)
|
|
|
|
|
{
|
|
|
|
|
if (!item.SupportsLocalMetadata)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
var video = item as Video;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
// Check parent for null to avoid running this against things like video backdrops
|
|
|
|
|
if (video != null && !(item is Episode) && !video.IsOwnedItem)
|
|
|
|
|
{
|
2015-01-03 22:55:34 -07:00
|
|
|
|
return updateType >= MinimumUpdateType;
|
2014-07-08 17:46:11 -07:00
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
protected override void WriteCustomElements(IHasMetadata item, XmlWriter writer)
|
|
|
|
|
{
|
2014-06-29 20:04:50 -07:00
|
|
|
|
var imdb = item.GetProviderId(MetadataProviders.Imdb);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(imdb))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("id", imdb);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var musicVideo = item as MusicVideo;
|
|
|
|
|
|
|
|
|
|
if (musicVideo != null)
|
|
|
|
|
{
|
2014-10-20 13:23:40 -07:00
|
|
|
|
foreach (var artist in musicVideo.Artists)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-10-20 13:23:40 -07:00
|
|
|
|
writer.WriteElementString("artist", artist);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(musicVideo.Album))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("album", musicVideo.Album);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var movie = item as Movie;
|
|
|
|
|
|
|
|
|
|
if (movie != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(movie.TmdbCollectionName))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("set", movie.TmdbCollectionName);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-08 17:46:11 -07:00
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
protected override List<string> GetTagsUsed()
|
|
|
|
|
{
|
|
|
|
|
var list = new List<string>
|
|
|
|
|
{
|
2014-06-29 20:04:50 -07:00
|
|
|
|
"album",
|
|
|
|
|
"artist",
|
|
|
|
|
"set",
|
|
|
|
|
"id"
|
2014-07-08 17:46:11 -07:00
|
|
|
|
};
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
return list;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|