jellyfin/MediaBrowser.XbmcMetadata/Savers/MovieNfoSaver.cs

140 lines
4.6 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
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;
using MediaBrowser.Model.Entities;
2016-10-25 12:02:04 -07:00
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Savers
{
/// <summary>
/// Nfo saver for movies.
/// </summary>
2014-07-08 17:46:11 -07:00
public class MovieNfoSaver : BaseNfoSaver
{
/// <summary>
/// Initializes a new instance of the <see cref="MovieNfoSaver"/> class.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="configurationManager">the server configuration manager.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="userManager">The user manager.</param>
/// <param name="userDataManager">The user data manager.</param>
/// <param name="logger">The logger.</param>
public MovieNfoSaver(
IFileSystem fileSystem,
IServerConfigurationManager configurationManager,
ILibraryManager libraryManager,
IUserManager userManager,
IUserDataManager userDataManager,
ILogger<MovieNfoSaver> logger)
: base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
/// <inheritdoc />
protected override string GetLocalSavePath(BaseItem item)
=> GetMovieSavePaths(new ItemInfo(item)).FirstOrDefault() ?? Path.ChangeExtension(item.Path, ".nfo");
internal static IEnumerable<string> GetMovieSavePaths(ItemInfo item)
{
2015-10-08 09:22:14 -07:00
if (item.VideoType == VideoType.Dvd && !item.IsPlaceHolder)
{
var path = item.ContainingFolderPath;
yield return Path.Combine(path, "VIDEO_TS", "VIDEO_TS.nfo");
}
2017-08-07 13:36:41 -07:00
if (!item.IsPlaceHolder && (item.VideoType == VideoType.Dvd || item.VideoType == VideoType.BluRay))
2015-05-15 08:46:20 -07:00
{
var path = item.ContainingFolderPath;
yield return Path.Combine(path, Path.GetFileName(path) + ".nfo");
2015-05-15 08:46:20 -07:00
}
else
{
yield return Path.ChangeExtension(item.Path, ".nfo");
2017-07-21 12:05:52 -07:00
if (!item.IsInMixedFolder)
{
yield return Path.Combine(item.ContainingFolderPath, "movie.nfo");
2017-07-21 12:05:52 -07:00
}
2015-05-15 08:46:20 -07:00
}
}
/// <inheritdoc />
2018-09-12 10:26:21 -07:00
protected override string GetRootElementName(BaseItem item)
=> item is MusicVideo ? "musicvideo" : "movie";
/// <inheritdoc />
2018-09-12 10:26:21 -07:00
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
2014-07-08 17:46:11 -07:00
{
if (!item.SupportsLocalMetadata)
{
return false;
}
2014-07-08 17:46:11 -07:00
// Check parent for null to avoid running this against things like video backdrops
if (item is Video video && !(item is Episode) && !video.ExtraType.HasValue)
2014-07-08 17:46:11 -07:00
{
return updateType >= MinimumUpdateType;
2014-07-08 17:46:11 -07:00
}
2014-07-08 17:46:11 -07:00
return false;
}
/// <inheritdoc />
2018-09-12 10:26:21 -07:00
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
2014-07-08 17:46:11 -07:00
{
2020-06-06 12:17:49 -07:00
var imdb = item.GetProviderId(MetadataProvider.Imdb);
if (!string.IsNullOrEmpty(imdb))
{
2014-07-08 17:46:11 -07:00
writer.WriteElementString("id", imdb);
}
if (item is MusicVideo musicVideo)
{
2014-10-20 13:23:40 -07:00
foreach (var artist in musicVideo.Artists)
{
2014-10-20 13:23:40 -07:00
writer.WriteElementString("artist", artist);
}
if (!string.IsNullOrEmpty(musicVideo.Album))
{
2014-07-08 17:46:11 -07:00
writer.WriteElementString("album", musicVideo.Album);
}
}
if (item is Movie movie)
{
2016-03-13 18:34:24 -07:00
if (!string.IsNullOrEmpty(movie.CollectionName))
{
2016-03-13 18:34:24 -07:00
writer.WriteElementString("set", movie.CollectionName);
}
}
2014-07-08 17:46:11 -07:00
}
/// <inheritdoc />
2021-03-08 19:04:47 -07:00
protected override IEnumerable<string> GetTagsUsed(BaseItem item)
2014-07-08 17:46:11 -07:00
{
2021-03-08 19:04:47 -07:00
foreach (var tag in base.GetTagsUsed(item))
2014-07-08 17:46:11 -07:00
{
2021-03-08 19:04:47 -07:00
yield return tag;
}
2016-10-25 19:53:47 -07:00
2021-03-08 19:04:47 -07:00
yield return "album";
yield return "artist";
yield return "set";
yield return "id";
2016-10-25 19:53:47 -07:00
}
}
}