Fixed: Misc Extra File Improvements (This changes mapping of backdrop images to Fanart instead of Banner) (#2642)
Fixes #2556 Fixes #2639 Fixes #2547pull/2658/merge
parent
0f6c5533f1
commit
39346b6127
@ -0,0 +1,65 @@
|
||||
using System.IO;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Extras.Metadata;
|
||||
using NzbDrone.Core.Extras.Metadata.Consumers.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Extras.Metadata.Consumers.Xbmc
|
||||
{
|
||||
[TestFixture]
|
||||
public class FindMetadataFileFixture : CoreTest<XbmcMetadata>
|
||||
{
|
||||
private Movie _movie;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_movie = Builder<Movie>.CreateNew()
|
||||
.With(s => s.Path = @"C:\Test\Movies\The.Movie".AsOsAgnostic())
|
||||
.Build();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_null_if_filename_is_not_handled()
|
||||
{
|
||||
var path = Path.Combine(_movie.Path, "file.jpg");
|
||||
|
||||
Subject.FindMetadataFile(_movie, path).Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_metadata_for_xbmc_nfo()
|
||||
{
|
||||
var path = Path.Combine(_movie.Path, "the.movie.2017.nfo");
|
||||
|
||||
Mocker.GetMock<IDetectXbmcNfo>()
|
||||
.Setup(v => v.IsXbmcNfoFile(path))
|
||||
.Returns(true);
|
||||
|
||||
Subject.FindMetadataFile(_movie, path).Type.Should().Be(MetadataType.MovieMetadata);
|
||||
|
||||
Mocker.GetMock<IDetectXbmcNfo>()
|
||||
.Verify(v => v.IsXbmcNfoFile(It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_null_for_scene_nfo()
|
||||
{
|
||||
var path = Path.Combine(_movie.Path, "the.movie.2017.nfo");
|
||||
|
||||
Mocker.GetMock<IDetectXbmcNfo>()
|
||||
.Setup(v => v.IsXbmcNfoFile(path))
|
||||
.Returns(false);
|
||||
|
||||
Subject.FindMetadataFile(_movie, path).Should().BeNull();
|
||||
|
||||
Mocker.GetMock<IDetectXbmcNfo>()
|
||||
.Verify(v => v.IsXbmcNfoFile(It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(145)]
|
||||
public class banner_to_fanart : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Execute.Sql("UPDATE Movies SET Images = replace(Images, \'\"coverType\": \"banner\"\', \'\"coverType\": \"fanart\"\')");
|
||||
|
||||
// Remove Link for images to specific MovieFiles, Images are now related to the Movie object only
|
||||
Execute.Sql("UPDATE MetadataFiles SET MovieFileId = null WHERE Type = 2");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Common.Disk;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
|
||||
{
|
||||
public interface IDetectXbmcNfo
|
||||
{
|
||||
bool IsXbmcNfoFile(string path);
|
||||
}
|
||||
|
||||
public class XbmcNfoDetector : IDetectXbmcNfo
|
||||
{
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
|
||||
private readonly Regex _regex = new Regex("<(movie|tvshow|episodedetails|artist|album|musicvideo)>", RegexOptions.Compiled);
|
||||
|
||||
public XbmcNfoDetector(IDiskProvider diskProvider)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
}
|
||||
|
||||
public bool IsXbmcNfoFile(string path)
|
||||
{
|
||||
// Lets make sure we're not reading huge files.
|
||||
if (_diskProvider.GetFileSize(path) > 10.Megabytes())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if it contains some of the kodi/xbmc xml tags
|
||||
var content = _diskProvider.ReadAllText(path);
|
||||
|
||||
return _regex.IsMatch(content);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Movies;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Others
|
||||
{
|
||||
public interface IOtherExtraFileRenamer
|
||||
{
|
||||
void RenameOtherExtraFile(Movie movie, string path);
|
||||
}
|
||||
|
||||
public class OtherExtraFileRenamer : IOtherExtraFileRenamer
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IRecycleBinProvider _recycleBinProvider;
|
||||
private readonly IMovieService _movieService;
|
||||
private readonly IOtherExtraFileService _otherExtraFileService;
|
||||
|
||||
public OtherExtraFileRenamer(IOtherExtraFileService otherExtraFileService,
|
||||
IMovieService movieService,
|
||||
IRecycleBinProvider recycleBinProvider,
|
||||
IDiskProvider diskProvider,
|
||||
Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_diskProvider = diskProvider;
|
||||
_recycleBinProvider = recycleBinProvider;
|
||||
_movieService = movieService;
|
||||
_otherExtraFileService = otherExtraFileService;
|
||||
}
|
||||
|
||||
public void RenameOtherExtraFile(Movie movie, string path)
|
||||
{
|
||||
if (!_diskProvider.FileExists(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var relativePath = movie.Path.GetRelativePath(path);
|
||||
|
||||
var otherExtraFile = _otherExtraFileService.FindByPath(relativePath);
|
||||
if (otherExtraFile != null)
|
||||
{
|
||||
var newPath = path + "-orig";
|
||||
|
||||
// Recycle an existing -orig file.
|
||||
RemoveOtherExtraFile(movie, newPath);
|
||||
|
||||
// Rename the file to .*-orig
|
||||
_diskProvider.MoveFile(path, newPath);
|
||||
otherExtraFile.RelativePath = relativePath + "-orig";
|
||||
otherExtraFile.Extension += "-orig";
|
||||
_otherExtraFileService.Upsert(otherExtraFile);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveOtherExtraFile(Movie movie, string path)
|
||||
{
|
||||
if (!_diskProvider.FileExists(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var relativePath = movie.Path.GetRelativePath(path);
|
||||
|
||||
var otherExtraFile = _otherExtraFileService.FindByPath(relativePath);
|
||||
if (otherExtraFile != null)
|
||||
{
|
||||
_recycleBinProvider.DeleteFile(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue