| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.IO; |
| | 3 | | using System.Linq; |
| | 4 | | using System.Xml; |
| | 5 | | using Jellyfin.Extensions; |
| | 6 | | using MediaBrowser.Controller.Configuration; |
| | 7 | | using MediaBrowser.Controller.Entities; |
| | 8 | | using MediaBrowser.Controller.Entities.Movies; |
| | 9 | | using MediaBrowser.Controller.Entities.TV; |
| | 10 | | using MediaBrowser.Controller.Library; |
| | 11 | | using MediaBrowser.Controller.Providers; |
| | 12 | | using MediaBrowser.Model.Entities; |
| | 13 | | using MediaBrowser.Model.IO; |
| | 14 | | using Microsoft.Extensions.Logging; |
| | 15 | |
|
| | 16 | | namespace MediaBrowser.XbmcMetadata.Savers |
| | 17 | | { |
| | 18 | | /// <summary> |
| | 19 | | /// Nfo saver for movies. |
| | 20 | | /// </summary> |
| | 21 | | public class MovieNfoSaver : BaseNfoSaver |
| | 22 | | { |
| | 23 | | /// <summary> |
| | 24 | | /// Initializes a new instance of the <see cref="MovieNfoSaver"/> class. |
| | 25 | | /// </summary> |
| | 26 | | /// <param name="fileSystem">The file system.</param> |
| | 27 | | /// <param name="configurationManager">the server configuration manager.</param> |
| | 28 | | /// <param name="libraryManager">The library manager.</param> |
| | 29 | | /// <param name="userManager">The user manager.</param> |
| | 30 | | /// <param name="userDataManager">The user data manager.</param> |
| | 31 | | /// <param name="logger">The logger.</param> |
| | 32 | | public MovieNfoSaver( |
| | 33 | | IFileSystem fileSystem, |
| | 34 | | IServerConfigurationManager configurationManager, |
| | 35 | | ILibraryManager libraryManager, |
| | 36 | | IUserManager userManager, |
| | 37 | | IUserDataManager userDataManager, |
| | 38 | | ILogger<MovieNfoSaver> logger) |
| 21 | 39 | | : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger) |
| | 40 | | { |
| 21 | 41 | | } |
| | 42 | |
|
| | 43 | | /// <inheritdoc /> |
| | 44 | | protected override string GetLocalSavePath(BaseItem item) |
| 0 | 45 | | => GetMovieSavePaths(new ItemInfo(item)).FirstOrDefault() ?? Path.ChangeExtension(item.Path, ".nfo"); |
| | 46 | |
|
| | 47 | | internal static IEnumerable<string> GetMovieSavePaths(ItemInfo item) |
| | 48 | | { |
| | 49 | | var path = item.ContainingFolderPath; |
| | 50 | | if (item.VideoType == VideoType.Dvd && !item.IsPlaceHolder) |
| | 51 | | { |
| | 52 | | yield return Path.Combine(path, "VIDEO_TS", "VIDEO_TS.nfo"); |
| | 53 | | } |
| | 54 | |
|
| | 55 | | // only allow movie object to read movie.nfo, not owned videos (which will be itemtype video, not movie) |
| | 56 | | if (!item.IsInMixedFolder && item.ItemType == typeof(Movie)) |
| | 57 | | { |
| | 58 | | yield return Path.Combine(path, "movie.nfo"); |
| | 59 | | } |
| | 60 | |
|
| | 61 | | if (!item.IsPlaceHolder && (item.VideoType == VideoType.Dvd || item.VideoType == VideoType.BluRay)) |
| | 62 | | { |
| | 63 | | yield return Path.Combine(path, Path.GetFileName(path) + ".nfo"); |
| | 64 | | } |
| | 65 | | else |
| | 66 | | { |
| | 67 | | yield return Path.ChangeExtension(item.Path, ".nfo"); |
| | 68 | | } |
| | 69 | | } |
| | 70 | |
|
| | 71 | | /// <inheritdoc /> |
| | 72 | | protected override string GetRootElementName(BaseItem item) |
| 0 | 73 | | => item is MusicVideo ? "musicvideo" : "movie"; |
| | 74 | |
|
| | 75 | | /// <inheritdoc /> |
| | 76 | | public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType) |
| | 77 | | { |
| 131 | 78 | | if (!item.SupportsLocalMetadata) |
| | 79 | | { |
| 0 | 80 | | return false; |
| | 81 | | } |
| | 82 | |
|
| | 83 | | // Check parent for null to avoid running this against things like video backdrops |
| 131 | 84 | | if (item is Video video && item is not Episode && !video.ExtraType.HasValue) |
| | 85 | | { |
| 0 | 86 | | return updateType >= MinimumUpdateType; |
| | 87 | | } |
| | 88 | |
|
| 131 | 89 | | return false; |
| | 90 | | } |
| | 91 | |
|
| | 92 | | /// <inheritdoc /> |
| | 93 | | protected override void WriteCustomElements(BaseItem item, XmlWriter writer) |
| | 94 | | { |
| 0 | 95 | | if (item.TryGetProviderId(MetadataProvider.Imdb, out var imdb)) |
| | 96 | | { |
| 0 | 97 | | writer.WriteElementString("id", imdb); |
| | 98 | | } |
| | 99 | |
|
| 0 | 100 | | if (item is MusicVideo musicVideo) |
| | 101 | | { |
| 0 | 102 | | foreach (var artist in musicVideo.Artists.Trimmed().OrderBy(artist => artist)) |
| | 103 | | { |
| 0 | 104 | | writer.WriteElementString("artist", artist); |
| | 105 | | } |
| | 106 | |
|
| 0 | 107 | | if (!string.IsNullOrEmpty(musicVideo.Album)) |
| | 108 | | { |
| 0 | 109 | | writer.WriteElementString("album", musicVideo.Album); |
| | 110 | | } |
| | 111 | | } |
| | 112 | |
|
| 0 | 113 | | if (item is Movie movie) |
| | 114 | | { |
| 0 | 115 | | if (!string.IsNullOrEmpty(movie.CollectionName)) |
| | 116 | | { |
| 0 | 117 | | writer.WriteStartElement("set"); |
| 0 | 118 | | writer.WriteElementString("name", movie.CollectionName); |
| 0 | 119 | | writer.WriteEndElement(); |
| | 120 | | } |
| | 121 | | } |
| 0 | 122 | | } |
| | 123 | |
|
| | 124 | | /// <inheritdoc /> |
| | 125 | | protected override IEnumerable<string> GetTagsUsed(BaseItem item) |
| | 126 | | { |
| | 127 | | foreach (var tag in base.GetTagsUsed(item)) |
| | 128 | | { |
| | 129 | | yield return tag; |
| | 130 | | } |
| | 131 | |
|
| | 132 | | yield return "album"; |
| | 133 | | yield return "artist"; |
| | 134 | | yield return "set"; |
| | 135 | | yield return "id"; |
| | 136 | | } |
| | 137 | | } |
| | 138 | | } |