2019-01-13 20:03:10 +00:00
using System.Collections.Generic ;
2019-01-13 19:26:56 +00:00
using System.IO ;
2019-08-18 17:54:07 +00:00
using System.Linq ;
2019-01-13 19:26:56 +00:00
using System.Xml ;
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 ;
2015-05-15 15:46:20 +00:00
using MediaBrowser.Controller.Providers ;
2014-06-30 03:04:50 +00:00
using MediaBrowser.Model.Entities ;
2016-10-25 19:02:04 +00:00
using MediaBrowser.Model.IO ;
2019-01-13 19:26:56 +00:00
using Microsoft.Extensions.Logging ;
2014-06-30 03:04:50 +00:00
namespace MediaBrowser.XbmcMetadata.Savers
{
2014-07-09 00:46:11 +00:00
public class MovieNfoSaver : BaseNfoSaver
2014-06-30 03:04:50 +00:00
{
2020-03-03 22:07:10 +00:00
public MovieNfoSaver (
IFileSystem fileSystem ,
IServerConfigurationManager configurationManager ,
ILibraryManager libraryManager ,
IUserManager userManager ,
IUserDataManager userDataManager ,
ILogger < MovieNfoSaver > logger )
2019-08-18 17:54:07 +00:00
: base ( fileSystem , configurationManager , libraryManager , userManager , userDataManager , logger )
2014-06-30 03:04:50 +00:00
{
}
2019-08-18 17:54:07 +00:00
/// <inheritdoc />
protected override string GetLocalSavePath ( BaseItem item )
= > GetMovieSavePaths ( new ItemInfo ( item ) ) . FirstOrDefault ( ) ;
2014-06-30 03:04:50 +00:00
2019-08-18 17:54:07 +00:00
public static IEnumerable < string > GetMovieSavePaths ( ItemInfo item )
{
2015-10-08 16:22:14 +00:00
if ( item . VideoType = = VideoType . Dvd & & ! item . IsPlaceHolder )
2014-06-30 03:04:50 +00:00
{
var path = item . ContainingFolderPath ;
2019-08-18 17:54:07 +00:00
yield return Path . Combine ( path , "VIDEO_TS" , "VIDEO_TS.nfo" ) ;
2014-06-30 03:04:50 +00:00
}
2017-08-07 20:36:41 +00:00
if ( ! item . IsPlaceHolder & & ( item . VideoType = = VideoType . Dvd | | item . VideoType = = VideoType . BluRay ) )
2015-05-15 15:46:20 +00:00
{
var path = item . ContainingFolderPath ;
2019-08-18 17:54:07 +00:00
yield return Path . Combine ( path , Path . GetFileName ( path ) + ".nfo" ) ;
2015-05-15 15:46:20 +00:00
}
else
{
2016-06-16 02:37:06 +00:00
// http://kodi.wiki/view/NFO_files/Movies
// movie.nfo will override all and any .nfo files in the same folder as the media files if you use the "Use foldernames for lookups" setting. If you don't, then moviename.nfo is used
//if (!item.IsInMixedFolder && item.ItemType == typeof(Movie))
2016-06-15 20:14:04 +00:00
//{
// list.Add(Path.Combine(item.ContainingFolderPath, "movie.nfo"));
//}
2019-08-18 17:54:07 +00:00
yield return Path . ChangeExtension ( item . Path , ".nfo" ) ;
2017-07-21 19:05:52 +00:00
if ( ! item . IsInMixedFolder )
{
2019-08-18 17:54:07 +00:00
yield return Path . Combine ( item . ContainingFolderPath , "movie.nfo" ) ;
2017-07-21 19:05:52 +00:00
}
2015-05-15 15:46:20 +00:00
}
2014-06-30 03:04:50 +00:00
}
2019-08-18 17:54:07 +00:00
/// <inheritdoc />
2018-09-12 17:26:21 +00:00
protected override string GetRootElementName ( BaseItem item )
2019-08-18 17:54:07 +00:00
= > item is MusicVideo ? "musicvideo" : "movie" ;
2014-06-30 03:04:50 +00:00
2019-08-18 17:54:07 +00:00
/// <inheritdoc />
2018-09-12 17:26:21 +00:00
public override bool IsEnabledFor ( BaseItem item , ItemUpdateType updateType )
2014-07-09 00:46:11 +00:00
{
if ( ! item . SupportsLocalMetadata )
{
return false ;
}
2014-06-30 03:04:50 +00:00
2014-07-09 00:46:11 +00:00
// Check parent for null to avoid running this against things like video backdrops
2019-08-18 17:54:07 +00:00
if ( item is Video video & & ! ( item is Episode ) & & ! video . ExtraType . HasValue )
2014-07-09 00:46:11 +00:00
{
2015-01-04 05:55:34 +00:00
return updateType > = MinimumUpdateType ;
2014-07-09 00:46:11 +00:00
}
2014-06-30 03:04:50 +00:00
2014-07-09 00:46:11 +00:00
return false ;
}
2014-06-30 03:04:50 +00:00
2019-08-18 17:54:07 +00:00
/// <inheritdoc />
2018-09-12 17:26:21 +00:00
protected override void WriteCustomElements ( BaseItem item , XmlWriter writer )
2014-07-09 00:46:11 +00:00
{
2014-06-30 03:04:50 +00:00
var imdb = item . GetProviderId ( MetadataProviders . Imdb ) ;
if ( ! string . IsNullOrEmpty ( imdb ) )
{
2014-07-09 00:46:11 +00:00
writer . WriteElementString ( "id" , imdb ) ;
2014-06-30 03:04:50 +00:00
}
2019-08-18 17:54:07 +00:00
if ( item is MusicVideo musicVideo )
2014-06-30 03:04:50 +00:00
{
2014-10-20 20:23:40 +00:00
foreach ( var artist in musicVideo . Artists )
2014-06-30 03:04:50 +00:00
{
2014-10-20 20:23:40 +00:00
writer . WriteElementString ( "artist" , artist ) ;
2014-06-30 03:04:50 +00:00
}
if ( ! string . IsNullOrEmpty ( musicVideo . Album ) )
{
2014-07-09 00:46:11 +00:00
writer . WriteElementString ( "album" , musicVideo . Album ) ;
2014-06-30 03:04:50 +00:00
}
}
2019-08-18 17:54:07 +00:00
if ( item is Movie movie )
2014-06-30 03:04:50 +00:00
{
2016-03-14 01:34:24 +00:00
if ( ! string . IsNullOrEmpty ( movie . CollectionName ) )
2014-06-30 03:04:50 +00:00
{
2016-03-14 01:34:24 +00:00
writer . WriteElementString ( "set" , movie . CollectionName ) ;
2014-06-30 03:04:50 +00:00
}
}
2014-07-09 00:46:11 +00:00
}
2014-06-30 03:04:50 +00:00
2019-08-18 17:54:07 +00:00
/// <inheritdoc />
2018-09-12 17:26:21 +00:00
protected override List < string > GetTagsUsed ( BaseItem item )
2014-07-09 00:46:11 +00:00
{
2017-01-27 23:28:21 +00:00
var list = base . GetTagsUsed ( item ) ;
list . AddRange ( new string [ ]
2014-07-09 00:46:11 +00:00
{
2017-01-27 23:28:21 +00:00
"album" ,
"artist" ,
"set" ,
"id"
} ) ;
2016-10-26 02:53:47 +00:00
2019-08-18 17:54:07 +00:00
return list ;
2016-10-26 02:53:47 +00:00
}
2014-06-30 03:04:50 +00:00
}
}