mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-25 22:36:59 -04:00
New: Readarr 0.1
This commit is contained in:
@@ -18,7 +18,7 @@ namespace NzbDrone.Core.Extras
|
||||
{
|
||||
public interface IExtraService
|
||||
{
|
||||
void ImportTrack(LocalTrack localTrack, TrackFile trackFile, bool isReadOnly);
|
||||
void ImportTrack(LocalTrack localTrack, BookFile trackFile, bool isReadOnly);
|
||||
}
|
||||
|
||||
public class ExtraService : IExtraService,
|
||||
@@ -28,7 +28,6 @@ namespace NzbDrone.Core.Extras
|
||||
{
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly IAlbumService _albumService;
|
||||
private readonly ITrackService _trackService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly List<IManageExtraFiles> _extraFileManagers;
|
||||
@@ -36,7 +35,6 @@ namespace NzbDrone.Core.Extras
|
||||
|
||||
public ExtraService(IMediaFileService mediaFileService,
|
||||
IAlbumService albumService,
|
||||
ITrackService trackService,
|
||||
IDiskProvider diskProvider,
|
||||
IConfigService configService,
|
||||
List<IManageExtraFiles> extraFileManagers,
|
||||
@@ -44,21 +42,20 @@ namespace NzbDrone.Core.Extras
|
||||
{
|
||||
_mediaFileService = mediaFileService;
|
||||
_albumService = albumService;
|
||||
_trackService = trackService;
|
||||
_diskProvider = diskProvider;
|
||||
_configService = configService;
|
||||
_extraFileManagers = extraFileManagers.OrderBy(e => e.Order).ToList();
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void ImportTrack(LocalTrack localTrack, TrackFile trackFile, bool isReadOnly)
|
||||
public void ImportTrack(LocalTrack localTrack, BookFile trackFile, bool isReadOnly)
|
||||
{
|
||||
ImportExtraFiles(localTrack, trackFile, isReadOnly);
|
||||
|
||||
CreateAfterImport(localTrack.Artist, trackFile);
|
||||
}
|
||||
|
||||
public void ImportExtraFiles(LocalTrack localTrack, TrackFile trackFile, bool isReadOnly)
|
||||
public void ImportExtraFiles(LocalTrack localTrack, BookFile trackFile, bool isReadOnly)
|
||||
{
|
||||
if (!_configService.ImportExtraFiles)
|
||||
{
|
||||
@@ -123,7 +120,7 @@ namespace NzbDrone.Core.Extras
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateAfterImport(Artist artist, TrackFile trackFile)
|
||||
private void CreateAfterImport(Author artist, BookFile trackFile)
|
||||
{
|
||||
foreach (var extraFileManager in _extraFileManagers)
|
||||
{
|
||||
@@ -146,7 +143,7 @@ namespace NzbDrone.Core.Extras
|
||||
public void Handle(TrackFolderCreatedEvent message)
|
||||
{
|
||||
var artist = message.Artist;
|
||||
var album = _albumService.GetAlbum(message.TrackFile.AlbumId);
|
||||
var album = _albumService.GetAlbum(message.TrackFile.BookId);
|
||||
|
||||
foreach (var extraFileManager in _extraFileManagers)
|
||||
{
|
||||
@@ -165,18 +162,9 @@ namespace NzbDrone.Core.Extras
|
||||
}
|
||||
}
|
||||
|
||||
private List<TrackFile> GetTrackFiles(int artistId)
|
||||
private List<BookFile> GetTrackFiles(int authorId)
|
||||
{
|
||||
var trackFiles = _mediaFileService.GetFilesByArtist(artistId);
|
||||
var tracks = _trackService.GetTracksByArtist(artistId);
|
||||
|
||||
foreach (var trackFile in trackFiles)
|
||||
{
|
||||
var localTrackFile = trackFile;
|
||||
trackFile.Tracks = tracks.Where(e => e.TrackFileId == localTrackFile.Id).ToList();
|
||||
}
|
||||
|
||||
return trackFiles;
|
||||
return _mediaFileService.GetFilesByArtist(authorId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace NzbDrone.Core.Extras.Files
|
||||
{
|
||||
public abstract class ExtraFile : ModelBase
|
||||
{
|
||||
public int ArtistId { get; set; }
|
||||
public int AuthorId { get; set; }
|
||||
public int? TrackFileId { get; set; }
|
||||
public int? AlbumId { get; set; }
|
||||
public int? BookId { get; set; }
|
||||
public string RelativePath { get; set; }
|
||||
public DateTime Added { get; set; }
|
||||
public DateTime LastUpdated { get; set; }
|
||||
|
||||
@@ -14,11 +14,11 @@ namespace NzbDrone.Core.Extras.Files
|
||||
public interface IManageExtraFiles
|
||||
{
|
||||
int Order { get; }
|
||||
IEnumerable<ExtraFile> CreateAfterArtistScan(Artist artist, List<TrackFile> trackFiles);
|
||||
IEnumerable<ExtraFile> CreateAfterTrackImport(Artist artist, TrackFile trackFile);
|
||||
IEnumerable<ExtraFile> CreateAfterTrackImport(Artist artist, Album album, string artistFolder, string albumFolder);
|
||||
IEnumerable<ExtraFile> MoveFilesAfterRename(Artist artist, List<TrackFile> trackFiles);
|
||||
ExtraFile Import(Artist artist, TrackFile trackFile, string path, string extension, bool readOnly);
|
||||
IEnumerable<ExtraFile> CreateAfterArtistScan(Author artist, List<BookFile> trackFiles);
|
||||
IEnumerable<ExtraFile> CreateAfterTrackImport(Author artist, BookFile trackFile);
|
||||
IEnumerable<ExtraFile> CreateAfterTrackImport(Author artist, Book album, string artistFolder, string albumFolder);
|
||||
IEnumerable<ExtraFile> MoveFilesAfterRename(Author artist, List<BookFile> trackFiles);
|
||||
ExtraFile Import(Author artist, BookFile trackFile, string path, string extension, bool readOnly);
|
||||
}
|
||||
|
||||
public abstract class ExtraFileManager<TExtraFile> : IManageExtraFiles
|
||||
@@ -41,13 +41,13 @@ namespace NzbDrone.Core.Extras.Files
|
||||
}
|
||||
|
||||
public abstract int Order { get; }
|
||||
public abstract IEnumerable<ExtraFile> CreateAfterArtistScan(Artist artist, List<TrackFile> trackFiles);
|
||||
public abstract IEnumerable<ExtraFile> CreateAfterTrackImport(Artist artist, TrackFile trackFile);
|
||||
public abstract IEnumerable<ExtraFile> CreateAfterTrackImport(Artist artist, Album album, string artistFolder, string albumFolder);
|
||||
public abstract IEnumerable<ExtraFile> MoveFilesAfterRename(Artist artist, List<TrackFile> trackFiles);
|
||||
public abstract ExtraFile Import(Artist artist, TrackFile trackFile, string path, string extension, bool readOnly);
|
||||
public abstract IEnumerable<ExtraFile> CreateAfterArtistScan(Author artist, List<BookFile> trackFiles);
|
||||
public abstract IEnumerable<ExtraFile> CreateAfterTrackImport(Author artist, BookFile trackFile);
|
||||
public abstract IEnumerable<ExtraFile> CreateAfterTrackImport(Author artist, Book album, string artistFolder, string albumFolder);
|
||||
public abstract IEnumerable<ExtraFile> MoveFilesAfterRename(Author artist, List<BookFile> trackFiles);
|
||||
public abstract ExtraFile Import(Author artist, BookFile trackFile, string path, string extension, bool readOnly);
|
||||
|
||||
protected TExtraFile ImportFile(Artist artist, TrackFile trackFile, string path, bool readOnly, string extension, string fileNameSuffix = null)
|
||||
protected TExtraFile ImportFile(Author artist, BookFile trackFile, string path, bool readOnly, string extension, string fileNameSuffix = null)
|
||||
{
|
||||
var newFolder = Path.GetDirectoryName(trackFile.Path);
|
||||
var filenameBuilder = new StringBuilder(Path.GetFileNameWithoutExtension(trackFile.Path));
|
||||
@@ -71,15 +71,15 @@ namespace NzbDrone.Core.Extras.Files
|
||||
|
||||
return new TExtraFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
AlbumId = trackFile.AlbumId,
|
||||
AuthorId = artist.Id,
|
||||
BookId = trackFile.BookId,
|
||||
TrackFileId = trackFile.Id,
|
||||
RelativePath = artist.Path.GetRelativePath(newFileName),
|
||||
Extension = extension
|
||||
};
|
||||
}
|
||||
|
||||
protected TExtraFile MoveFile(Artist artist, TrackFile trackFile, TExtraFile extraFile, string fileNameSuffix = null)
|
||||
protected TExtraFile MoveFile(Author artist, BookFile trackFile, TExtraFile extraFile, string fileNameSuffix = null)
|
||||
{
|
||||
var newFolder = Path.GetDirectoryName(trackFile.Path);
|
||||
var filenameBuilder = new StringBuilder(Path.GetFileNameWithoutExtension(trackFile.Path));
|
||||
|
||||
@@ -8,11 +8,11 @@ namespace NzbDrone.Core.Extras.Files
|
||||
public interface IExtraFileRepository<TExtraFile> : IBasicRepository<TExtraFile>
|
||||
where TExtraFile : ExtraFile, new()
|
||||
{
|
||||
void DeleteForArtist(int artistId);
|
||||
void DeleteForAlbum(int artistId, int albumId);
|
||||
void DeleteForArtist(int authorId);
|
||||
void DeleteForAlbum(int authorId, int bookId);
|
||||
void DeleteForTrackFile(int trackFileId);
|
||||
List<TExtraFile> GetFilesByArtist(int artistId);
|
||||
List<TExtraFile> GetFilesByAlbum(int artistId, int albumId);
|
||||
List<TExtraFile> GetFilesByArtist(int authorId);
|
||||
List<TExtraFile> GetFilesByAlbum(int authorId, int bookId);
|
||||
List<TExtraFile> GetFilesByTrackFile(int trackFileId);
|
||||
TExtraFile FindByPath(string path);
|
||||
}
|
||||
@@ -25,14 +25,14 @@ namespace NzbDrone.Core.Extras.Files
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteForArtist(int artistId)
|
||||
public void DeleteForArtist(int authorId)
|
||||
{
|
||||
Delete(c => c.ArtistId == artistId);
|
||||
Delete(c => c.AuthorId == authorId);
|
||||
}
|
||||
|
||||
public void DeleteForAlbum(int artistId, int albumId)
|
||||
public void DeleteForAlbum(int authorId, int bookId)
|
||||
{
|
||||
Delete(c => c.ArtistId == artistId && c.AlbumId == albumId);
|
||||
Delete(c => c.AuthorId == authorId && c.BookId == bookId);
|
||||
}
|
||||
|
||||
public void DeleteForTrackFile(int trackFileId)
|
||||
@@ -40,14 +40,14 @@ namespace NzbDrone.Core.Extras.Files
|
||||
Delete(c => c.TrackFileId == trackFileId);
|
||||
}
|
||||
|
||||
public List<TExtraFile> GetFilesByArtist(int artistId)
|
||||
public List<TExtraFile> GetFilesByArtist(int authorId)
|
||||
{
|
||||
return Query(c => c.ArtistId == artistId);
|
||||
return Query(c => c.AuthorId == authorId);
|
||||
}
|
||||
|
||||
public List<TExtraFile> GetFilesByAlbum(int artistId, int albumId)
|
||||
public List<TExtraFile> GetFilesByAlbum(int authorId, int bookId)
|
||||
{
|
||||
return Query(c => c.ArtistId == artistId && c.AlbumId == albumId);
|
||||
return Query(c => c.AuthorId == authorId && c.BookId == bookId);
|
||||
}
|
||||
|
||||
public List<TExtraFile> GetFilesByTrackFile(int trackFileId)
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace NzbDrone.Core.Extras.Files
|
||||
public interface IExtraFileService<TExtraFile>
|
||||
where TExtraFile : ExtraFile, new()
|
||||
{
|
||||
List<TExtraFile> GetFilesByArtist(int artistId);
|
||||
List<TExtraFile> GetFilesByArtist(int authorId);
|
||||
List<TExtraFile> GetFilesByTrackFile(int trackFileId);
|
||||
TExtraFile FindByPath(string path);
|
||||
void Upsert(TExtraFile extraFile);
|
||||
@@ -49,9 +49,9 @@ namespace NzbDrone.Core.Extras.Files
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<TExtraFile> GetFilesByArtist(int artistId)
|
||||
public List<TExtraFile> GetFilesByArtist(int authorId)
|
||||
{
|
||||
return _repository.GetFilesByArtist(artistId);
|
||||
return _repository.GetFilesByArtist(authorId);
|
||||
}
|
||||
|
||||
public List<TExtraFile> GetFilesByTrackFile(int trackFileId)
|
||||
|
||||
@@ -7,6 +7,6 @@ namespace NzbDrone.Core.Extras
|
||||
public interface IImportExistingExtraFiles
|
||||
{
|
||||
int Order { get; }
|
||||
IEnumerable<ExtraFile> ProcessFiles(Artist artist, List<string> filesOnDisk, List<string> importedFiles);
|
||||
IEnumerable<ExtraFile> ProcessFiles(Author artist, List<string> filesOnDisk, List<string> importedFiles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace NzbDrone.Core.Extras
|
||||
}
|
||||
|
||||
public abstract int Order { get; }
|
||||
public abstract IEnumerable<ExtraFile> ProcessFiles(Artist artist, List<string> filesOnDisk, List<string> importedFiles);
|
||||
public abstract IEnumerable<ExtraFile> ProcessFiles(Author artist, List<string> filesOnDisk, List<string> importedFiles);
|
||||
|
||||
public virtual ImportExistingExtraFileFilterResult<TExtraFile> FilterAndClean(Artist artist, List<string> filesOnDisk, List<string> importedFiles)
|
||||
public virtual ImportExistingExtraFileFilterResult<TExtraFile> FilterAndClean(Author artist, List<string> filesOnDisk, List<string> importedFiles)
|
||||
{
|
||||
var artistFiles = _extraFileService.GetFilesByArtist(artist.Id);
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace NzbDrone.Core.Extras
|
||||
return Filter(artist, filesOnDisk, importedFiles, artistFiles);
|
||||
}
|
||||
|
||||
private ImportExistingExtraFileFilterResult<TExtraFile> Filter(Artist artist, List<string> filesOnDisk, List<string> importedFiles, List<TExtraFile> artistFiles)
|
||||
private ImportExistingExtraFileFilterResult<TExtraFile> Filter(Author artist, List<string> filesOnDisk, List<string> importedFiles, List<TExtraFile> artistFiles)
|
||||
{
|
||||
var previouslyImported = artistFiles.IntersectBy(s => Path.Combine(artist.Path, s.RelativePath), filesOnDisk, f => f, PathEqualityComparer.Instance).ToList();
|
||||
var filteredFiles = filesOnDisk.Except(previouslyImported.Select(f => Path.Combine(artist.Path, f.RelativePath)).ToList(), PathEqualityComparer.Instance)
|
||||
@@ -42,7 +42,7 @@ namespace NzbDrone.Core.Extras
|
||||
return new ImportExistingExtraFileFilterResult<TExtraFile>(previouslyImported, filteredFiles);
|
||||
}
|
||||
|
||||
private void Clean(Artist artist, List<string> filesOnDisk, List<string> importedFiles, List<TExtraFile> artistFiles)
|
||||
private void Clean(Author artist, List<string> filesOnDisk, List<string> importedFiles, List<TExtraFile> artistFiles)
|
||||
{
|
||||
var alreadyImportedFileIds = artistFiles.IntersectBy(f => Path.Combine(artist.Path, f.RelativePath), importedFiles, i => i, PathEqualityComparer.Instance)
|
||||
.Select(f => f.Id);
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Extras.Files;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Lyrics
|
||||
{
|
||||
public class ExistingLyricImporter : ImportExistingExtraFilesBase<LyricFile>
|
||||
{
|
||||
private readonly IExtraFileService<LyricFile> _lyricFileService;
|
||||
private readonly IAugmentingService _augmentingService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ExistingLyricImporter(IExtraFileService<LyricFile> lyricFileService,
|
||||
IAugmentingService augmentingService,
|
||||
Logger logger)
|
||||
: base(lyricFileService)
|
||||
{
|
||||
_lyricFileService = lyricFileService;
|
||||
_augmentingService = augmentingService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override int Order => 1;
|
||||
|
||||
public override IEnumerable<ExtraFile> ProcessFiles(Artist artist, List<string> filesOnDisk, List<string> importedFiles)
|
||||
{
|
||||
_logger.Debug("Looking for existing lyrics files in {0}", artist.Path);
|
||||
|
||||
var subtitleFiles = new List<LyricFile>();
|
||||
var filterResult = FilterAndClean(artist, filesOnDisk, importedFiles);
|
||||
|
||||
foreach (var possibleLyricFile in filterResult.FilesOnDisk)
|
||||
{
|
||||
var extension = Path.GetExtension(possibleLyricFile);
|
||||
|
||||
if (LyricFileExtensions.Extensions.Contains(extension))
|
||||
{
|
||||
var localTrack = new LocalTrack
|
||||
{
|
||||
FileTrackInfo = Parser.Parser.ParseMusicPath(possibleLyricFile),
|
||||
Artist = artist,
|
||||
Path = possibleLyricFile
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
_augmentingService.Augment(localTrack, false);
|
||||
}
|
||||
catch (AugmentingFailedException)
|
||||
{
|
||||
_logger.Debug("Unable to parse lyric file: {0}", possibleLyricFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (localTrack.Tracks.Empty())
|
||||
{
|
||||
_logger.Debug("Cannot find related tracks for: {0}", possibleLyricFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (localTrack.Tracks.DistinctBy(e => e.TrackFileId).Count() > 1)
|
||||
{
|
||||
_logger.Debug("Lyric file: {0} does not match existing files.", possibleLyricFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
var subtitleFile = new LyricFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
AlbumId = localTrack.Album.Id,
|
||||
TrackFileId = localTrack.Tracks.First().TrackFileId,
|
||||
RelativePath = artist.Path.GetRelativePath(possibleLyricFile),
|
||||
Extension = extension
|
||||
};
|
||||
|
||||
subtitleFiles.Add(subtitleFile);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Info("Found {0} existing lyric files", subtitleFiles.Count);
|
||||
_lyricFileService.Upsert(subtitleFiles);
|
||||
|
||||
// Return files that were just imported along with files that were
|
||||
// previously imported so previously imported files aren't imported twice
|
||||
return subtitleFiles.Concat(filterResult.PreviouslyImported);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Extras.Files;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Lyrics
|
||||
{
|
||||
public class ImportedLyricFiles
|
||||
{
|
||||
public List<string> SourceFiles { get; set; }
|
||||
public List<ExtraFile> LyricFiles { get; set; }
|
||||
|
||||
public ImportedLyricFiles()
|
||||
{
|
||||
SourceFiles = new List<string>();
|
||||
LyricFiles = new List<ExtraFile>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using NzbDrone.Core.Extras.Files;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Lyrics
|
||||
{
|
||||
public class LyricFile : ExtraFile
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Lyrics
|
||||
{
|
||||
public static class LyricFileExtensions
|
||||
{
|
||||
private static HashSet<string> _fileExtensions;
|
||||
|
||||
static LyricFileExtensions()
|
||||
{
|
||||
_fileExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
".lrc",
|
||||
".txt",
|
||||
".utf",
|
||||
".utf8",
|
||||
".utf-8"
|
||||
};
|
||||
}
|
||||
|
||||
public static HashSet<string> Extensions => _fileExtensions;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Extras.Files;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Lyrics
|
||||
{
|
||||
public interface ILyricFileRepository : IExtraFileRepository<LyricFile>
|
||||
{
|
||||
}
|
||||
|
||||
public class LyricFileRepository : ExtraFileRepository<LyricFile>, ILyricFileRepository
|
||||
{
|
||||
public LyricFileRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
||||
: base(database, eventAggregator)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Extras.Files;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Lyrics
|
||||
{
|
||||
public interface ILyricFileService : IExtraFileService<LyricFile>
|
||||
{
|
||||
}
|
||||
|
||||
public class LyricFileService : ExtraFileService<LyricFile>, ILyricFileService
|
||||
{
|
||||
public LyricFileService(IExtraFileRepository<LyricFile> repository, IArtistService artistService, IDiskProvider diskProvider, IRecycleBinProvider recycleBinProvider, Logger logger)
|
||||
: base(repository, artistService, diskProvider, recycleBinProvider, logger)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
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.Configuration;
|
||||
using NzbDrone.Core.Extras.Files;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Lyrics
|
||||
{
|
||||
public class LyricService : ExtraFileManager<LyricFile>
|
||||
{
|
||||
private readonly ILyricFileService _lyricFileService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public LyricService(IConfigService configService,
|
||||
IDiskProvider diskProvider,
|
||||
IDiskTransferService diskTransferService,
|
||||
ILyricFileService lyricFileService,
|
||||
Logger logger)
|
||||
: base(configService, diskProvider, diskTransferService, logger)
|
||||
{
|
||||
_lyricFileService = lyricFileService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override int Order => 1;
|
||||
|
||||
public override IEnumerable<ExtraFile> CreateAfterArtistScan(Artist artist, List<TrackFile> trackFiles)
|
||||
{
|
||||
return Enumerable.Empty<LyricFile>();
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> CreateAfterTrackImport(Artist artist, TrackFile trackFile)
|
||||
{
|
||||
return Enumerable.Empty<LyricFile>();
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> CreateAfterTrackImport(Artist artist, Album album, string artistFolder, string albumFolder)
|
||||
{
|
||||
return Enumerable.Empty<LyricFile>();
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> MoveFilesAfterRename(Artist artist, List<TrackFile> trackFiles)
|
||||
{
|
||||
var subtitleFiles = _lyricFileService.GetFilesByArtist(artist.Id);
|
||||
|
||||
var movedFiles = new List<LyricFile>();
|
||||
|
||||
foreach (var trackFile in trackFiles)
|
||||
{
|
||||
var groupedExtraFilesForTrackFile = subtitleFiles.Where(m => m.TrackFileId == trackFile.Id)
|
||||
.GroupBy(s => s.Extension).ToList();
|
||||
|
||||
foreach (var group in groupedExtraFilesForTrackFile)
|
||||
{
|
||||
var groupCount = group.Count();
|
||||
var copy = 1;
|
||||
|
||||
if (groupCount > 1)
|
||||
{
|
||||
_logger.Warn("Multiple lyric files found with the same extension for {0}", trackFile.Path);
|
||||
}
|
||||
|
||||
foreach (var subtitleFile in group)
|
||||
{
|
||||
var suffix = GetSuffix(copy, groupCount > 1);
|
||||
movedFiles.AddIfNotNull(MoveFile(artist, trackFile, subtitleFile, suffix));
|
||||
|
||||
copy++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_lyricFileService.Upsert(movedFiles);
|
||||
|
||||
return movedFiles;
|
||||
}
|
||||
|
||||
public override ExtraFile Import(Artist artist, TrackFile trackFile, string path, string extension, bool readOnly)
|
||||
{
|
||||
if (LyricFileExtensions.Extensions.Contains(Path.GetExtension(path)))
|
||||
{
|
||||
var suffix = GetSuffix(1, false);
|
||||
var subtitleFile = ImportFile(artist, trackFile, path, readOnly, extension, suffix);
|
||||
|
||||
_lyricFileService.Upsert(subtitleFile);
|
||||
|
||||
return subtitleFile;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string GetSuffix(int copy, bool multipleCopies = false)
|
||||
{
|
||||
var suffixBuilder = new StringBuilder();
|
||||
|
||||
if (multipleCopies)
|
||||
{
|
||||
suffixBuilder.Append(".");
|
||||
suffixBuilder.Append(copy);
|
||||
}
|
||||
|
||||
return suffixBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Extras.Metadata.Files;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Metadata.Consumers.Roksbox
|
||||
{
|
||||
public class RoksboxMetadata : MetadataBase<RoksboxMetadataSettings>
|
||||
{
|
||||
private readonly IMapCoversToLocal _mediaCoverService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public RoksboxMetadata(IMapCoversToLocal mediaCoverService,
|
||||
IDiskProvider diskProvider,
|
||||
Logger logger)
|
||||
{
|
||||
_mediaCoverService = mediaCoverService;
|
||||
_diskProvider = diskProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private static readonly Regex SeasonImagesRegex = new Regex(@"^(season (?<season>\d+))|(?<specials>specials)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public override string Name => "Roksbox";
|
||||
|
||||
public override string GetFilenameAfterMove(Artist artist, TrackFile trackFile, MetadataFile metadataFile)
|
||||
{
|
||||
var trackFilePath = trackFile.Path;
|
||||
|
||||
if (metadataFile.Type == MetadataType.TrackMetadata)
|
||||
{
|
||||
return GetTrackMetadataFilename(trackFilePath);
|
||||
}
|
||||
|
||||
_logger.Debug("Unknown track file metadata: {0}", metadataFile.RelativePath);
|
||||
return Path.Combine(artist.Path, metadataFile.RelativePath);
|
||||
}
|
||||
|
||||
public override MetadataFile FindMetadataFile(Artist artist, string path)
|
||||
{
|
||||
var filename = Path.GetFileName(path);
|
||||
|
||||
if (filename == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var parentdir = Directory.GetParent(path);
|
||||
|
||||
var metadata = new MetadataFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
Consumer = GetType().Name,
|
||||
RelativePath = artist.Path.GetRelativePath(path)
|
||||
};
|
||||
|
||||
//Series and season images are both named folder.jpg, only season ones sit in season folders
|
||||
if (Path.GetFileNameWithoutExtension(filename).Equals(parentdir.Name, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var seasonMatch = SeasonImagesRegex.Match(parentdir.Name);
|
||||
|
||||
if (seasonMatch.Success)
|
||||
{
|
||||
metadata.Type = MetadataType.AlbumImage;
|
||||
|
||||
if (seasonMatch.Groups["specials"].Success)
|
||||
{
|
||||
metadata.AlbumId = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
metadata.AlbumId = Convert.ToInt32(seasonMatch.Groups["season"].Value);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
metadata.Type = MetadataType.ArtistImage;
|
||||
return metadata;
|
||||
}
|
||||
|
||||
var parseResult = Parser.Parser.ParseMusicTitle(filename);
|
||||
|
||||
if (parseResult != null)
|
||||
{
|
||||
var extension = Path.GetExtension(filename).ToLowerInvariant();
|
||||
|
||||
if (extension == ".xml")
|
||||
{
|
||||
metadata.Type = MetadataType.TrackMetadata;
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override MetadataFileResult ArtistMetadata(Artist artist)
|
||||
{
|
||||
//Artist metadata is not supported
|
||||
return null;
|
||||
}
|
||||
|
||||
public override MetadataFileResult AlbumMetadata(Artist artist, Album album, string albumPath)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override MetadataFileResult TrackMetadata(Artist artist, TrackFile trackFile)
|
||||
{
|
||||
if (!Settings.TrackMetadata)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.Debug("Generating Track Metadata for: {0}", trackFile.Path);
|
||||
|
||||
var xmlResult = string.Empty;
|
||||
foreach (var track in trackFile.Tracks.Value)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var xws = new XmlWriterSettings();
|
||||
xws.OmitXmlDeclaration = true;
|
||||
xws.Indent = false;
|
||||
|
||||
using (var xw = XmlWriter.Create(sb, xws))
|
||||
{
|
||||
var doc = new XDocument();
|
||||
|
||||
var details = new XElement("song");
|
||||
details.Add(new XElement("title", track.Title));
|
||||
details.Add(new XElement("performingartist", artist.Name));
|
||||
|
||||
doc.Add(details);
|
||||
doc.Save(xw);
|
||||
|
||||
xmlResult += doc.ToString();
|
||||
xmlResult += Environment.NewLine;
|
||||
}
|
||||
}
|
||||
|
||||
return new MetadataFileResult(GetTrackMetadataFilename(artist.Path.GetRelativePath(trackFile.Path)), xmlResult.Trim(Environment.NewLine.ToCharArray()));
|
||||
}
|
||||
|
||||
public override List<ImageFileResult> ArtistImages(Artist artist)
|
||||
{
|
||||
if (!Settings.ArtistImages)
|
||||
{
|
||||
return new List<ImageFileResult>();
|
||||
}
|
||||
|
||||
var image = artist.Metadata.Value.Images.SingleOrDefault(c => c.CoverType == MediaCoverTypes.Poster) ?? artist.Metadata.Value.Images.FirstOrDefault();
|
||||
if (image == null)
|
||||
{
|
||||
_logger.Trace("Failed to find suitable Artist image for artist {0}.", artist.Name);
|
||||
return new List<ImageFileResult>();
|
||||
}
|
||||
|
||||
var source = _mediaCoverService.GetCoverPath(artist.Id, MediaCoverEntity.Artist, image.CoverType, image.Extension);
|
||||
var destination = Path.GetFileName(artist.Path) + Path.GetExtension(source);
|
||||
|
||||
return new List<ImageFileResult> { new ImageFileResult(destination, source) };
|
||||
}
|
||||
|
||||
public override List<ImageFileResult> AlbumImages(Artist artist, Album album, string albumFolder)
|
||||
{
|
||||
return new List<ImageFileResult>();
|
||||
}
|
||||
|
||||
public override List<ImageFileResult> TrackImages(Artist artist, TrackFile trackFile)
|
||||
{
|
||||
return new List<ImageFileResult>();
|
||||
}
|
||||
|
||||
private string GetTrackMetadataFilename(string trackFilePath)
|
||||
{
|
||||
return Path.ChangeExtension(trackFilePath, "xml");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using FluentValidation;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Metadata.Consumers.Roksbox
|
||||
{
|
||||
public class RoksboxSettingsValidator : AbstractValidator<RoksboxMetadataSettings>
|
||||
{
|
||||
}
|
||||
|
||||
public class RoksboxMetadataSettings : IProviderConfig
|
||||
{
|
||||
private static readonly RoksboxSettingsValidator Validator = new RoksboxSettingsValidator();
|
||||
|
||||
public RoksboxMetadataSettings()
|
||||
{
|
||||
TrackMetadata = true;
|
||||
ArtistImages = true;
|
||||
AlbumImages = true;
|
||||
}
|
||||
|
||||
[FieldDefinition(0, Label = "Track Metadata", Type = FieldType.Checkbox, Section = MetadataSectionType.Metadata, HelpText = "Album\\filename.xml")]
|
||||
public bool TrackMetadata { get; set; }
|
||||
|
||||
[FieldDefinition(1, Label = "Artist Images", Type = FieldType.Checkbox, Section = MetadataSectionType.Image, HelpText = "Artist Title.jpg")]
|
||||
public bool ArtistImages { get; set; }
|
||||
|
||||
[FieldDefinition(2, Label = "Album Images", Type = FieldType.Checkbox, Section = MetadataSectionType.Image, HelpText = "Album Title.jpg")]
|
||||
public bool AlbumImages { get; set; }
|
||||
|
||||
public bool IsValid => true;
|
||||
|
||||
public NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Extras.Metadata.Files;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Metadata.Consumers.Wdtv
|
||||
{
|
||||
public class WdtvMetadata : MetadataBase<WdtvMetadataSettings>
|
||||
{
|
||||
private readonly IMapCoversToLocal _mediaCoverService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public WdtvMetadata(IMapCoversToLocal mediaCoverService,
|
||||
IDiskProvider diskProvider,
|
||||
Logger logger)
|
||||
{
|
||||
_mediaCoverService = mediaCoverService;
|
||||
_diskProvider = diskProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override string Name => "WDTV";
|
||||
|
||||
public override string GetFilenameAfterMove(Artist artist, TrackFile trackFile, MetadataFile metadataFile)
|
||||
{
|
||||
var trackFilePath = trackFile.Path;
|
||||
|
||||
if (metadataFile.Type == MetadataType.TrackMetadata)
|
||||
{
|
||||
return GetTrackMetadataFilename(trackFilePath);
|
||||
}
|
||||
|
||||
_logger.Debug("Unknown track file metadata: {0}", metadataFile.RelativePath);
|
||||
return Path.Combine(artist.Path, metadataFile.RelativePath);
|
||||
}
|
||||
|
||||
public override MetadataFile FindMetadataFile(Artist artist, string path)
|
||||
{
|
||||
var filename = Path.GetFileName(path);
|
||||
|
||||
if (filename == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var metadata = new MetadataFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
Consumer = GetType().Name,
|
||||
RelativePath = artist.Path.GetRelativePath(path)
|
||||
};
|
||||
|
||||
var parseResult = Parser.Parser.ParseMusicTitle(filename);
|
||||
|
||||
if (parseResult != null)
|
||||
{
|
||||
switch (Path.GetExtension(filename).ToLowerInvariant())
|
||||
{
|
||||
case ".xml":
|
||||
metadata.Type = MetadataType.TrackMetadata;
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override MetadataFileResult ArtistMetadata(Artist artist)
|
||||
{
|
||||
//Artist metadata is not supported
|
||||
return null;
|
||||
}
|
||||
|
||||
public override MetadataFileResult AlbumMetadata(Artist artist, Album album, string albumPath)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override MetadataFileResult TrackMetadata(Artist artist, TrackFile trackFile)
|
||||
{
|
||||
if (!Settings.TrackMetadata)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.Debug("Generating Track Metadata for: {0}", trackFile.Path);
|
||||
|
||||
var xmlResult = string.Empty;
|
||||
foreach (var track in trackFile.Tracks.Value)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var xws = new XmlWriterSettings();
|
||||
xws.OmitXmlDeclaration = true;
|
||||
xws.Indent = false;
|
||||
|
||||
using (var xw = XmlWriter.Create(sb, xws))
|
||||
{
|
||||
var doc = new XDocument();
|
||||
|
||||
var details = new XElement("details");
|
||||
details.Add(new XElement("id", artist.Id));
|
||||
details.Add(new XElement("title", string.Format("{0} - {1} - {2}", artist.Name, track.TrackNumber, track.Title)));
|
||||
details.Add(new XElement("artist_name", artist.Metadata.Value.Name));
|
||||
details.Add(new XElement("track_name", track.Title));
|
||||
details.Add(new XElement("track_number", track.AbsoluteTrackNumber.ToString("00")));
|
||||
details.Add(new XElement("member", string.Join(" / ", artist.Metadata.Value.Members.ConvertAll(c => c.Name + " - " + c.Instrument))));
|
||||
|
||||
doc.Add(details);
|
||||
doc.Save(xw);
|
||||
|
||||
xmlResult += doc.ToString();
|
||||
xmlResult += Environment.NewLine;
|
||||
}
|
||||
}
|
||||
|
||||
var filename = GetTrackMetadataFilename(artist.Path.GetRelativePath(trackFile.Path));
|
||||
|
||||
return new MetadataFileResult(filename, xmlResult.Trim(Environment.NewLine.ToCharArray()));
|
||||
}
|
||||
|
||||
public override List<ImageFileResult> ArtistImages(Artist artist)
|
||||
{
|
||||
return new List<ImageFileResult>();
|
||||
}
|
||||
|
||||
public override List<ImageFileResult> AlbumImages(Artist artist, Album album, string albumFolder)
|
||||
{
|
||||
return new List<ImageFileResult>();
|
||||
}
|
||||
|
||||
public override List<ImageFileResult> TrackImages(Artist artist, TrackFile trackFile)
|
||||
{
|
||||
return new List<ImageFileResult>();
|
||||
}
|
||||
|
||||
private string GetTrackMetadataFilename(string trackFilePath)
|
||||
{
|
||||
return Path.ChangeExtension(trackFilePath, "xml");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using FluentValidation;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Metadata.Consumers.Wdtv
|
||||
{
|
||||
public class WdtvSettingsValidator : AbstractValidator<WdtvMetadataSettings>
|
||||
{
|
||||
}
|
||||
|
||||
public class WdtvMetadataSettings : IProviderConfig
|
||||
{
|
||||
private static readonly WdtvSettingsValidator Validator = new WdtvSettingsValidator();
|
||||
|
||||
public WdtvMetadataSettings()
|
||||
{
|
||||
TrackMetadata = true;
|
||||
}
|
||||
|
||||
[FieldDefinition(0, Label = "Track Metadata", Type = FieldType.Checkbox, Section = MetadataSectionType.Metadata)]
|
||||
public bool TrackMetadata { get; set; }
|
||||
|
||||
public bool IsValid => true;
|
||||
|
||||
public NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,252 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Extras.Metadata.Files;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
|
||||
{
|
||||
public class XbmcMetadata : MetadataBase<XbmcMetadataSettings>
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
private readonly IMapCoversToLocal _mediaCoverService;
|
||||
private readonly IDetectXbmcNfo _detectNfo;
|
||||
|
||||
public XbmcMetadata(IDetectXbmcNfo detectNfo,
|
||||
IMapCoversToLocal mediaCoverService,
|
||||
Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_mediaCoverService = mediaCoverService;
|
||||
_detectNfo = detectNfo;
|
||||
}
|
||||
|
||||
private static readonly Regex ArtistImagesRegex = new Regex(@"^(?<type>folder|banner|fanart|logo)\.(?:png|jpg|jpeg)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
private static readonly Regex AlbumImagesRegex = new Regex(@"^(?<type>cover|disc)\.(?:png|jpg|jpeg)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public override string Name => "Kodi (XBMC) / Emby";
|
||||
|
||||
public override string GetFilenameAfterMove(Artist artist, TrackFile trackFile, MetadataFile metadataFile)
|
||||
{
|
||||
var trackFilePath = trackFile.Path;
|
||||
|
||||
if (metadataFile.Type == MetadataType.TrackMetadata)
|
||||
{
|
||||
return GetTrackMetadataFilename(trackFilePath);
|
||||
}
|
||||
|
||||
_logger.Debug("Unknown track file metadata: {0}", metadataFile.RelativePath);
|
||||
return Path.Combine(artist.Path, metadataFile.RelativePath);
|
||||
}
|
||||
|
||||
public override MetadataFile FindMetadataFile(Artist artist, string path)
|
||||
{
|
||||
var filename = Path.GetFileName(path);
|
||||
|
||||
if (filename == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var metadata = new MetadataFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
Consumer = GetType().Name,
|
||||
RelativePath = artist.Path.GetRelativePath(path)
|
||||
};
|
||||
|
||||
if (ArtistImagesRegex.IsMatch(filename))
|
||||
{
|
||||
metadata.Type = MetadataType.ArtistImage;
|
||||
return metadata;
|
||||
}
|
||||
|
||||
var albumMatch = AlbumImagesRegex.Match(filename);
|
||||
|
||||
if (albumMatch.Success)
|
||||
{
|
||||
metadata.Type = MetadataType.AlbumImage;
|
||||
return metadata;
|
||||
}
|
||||
|
||||
var isXbmcNfoFile = _detectNfo.IsXbmcNfoFile(path);
|
||||
|
||||
if (filename.Equals("artist.nfo", StringComparison.OrdinalIgnoreCase) &&
|
||||
isXbmcNfoFile)
|
||||
{
|
||||
metadata.Type = MetadataType.ArtistMetadata;
|
||||
return metadata;
|
||||
}
|
||||
|
||||
if (filename.Equals("album.nfo", StringComparison.OrdinalIgnoreCase) &&
|
||||
isXbmcNfoFile)
|
||||
{
|
||||
metadata.Type = MetadataType.AlbumMetadata;
|
||||
return metadata;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override MetadataFileResult ArtistMetadata(Artist artist)
|
||||
{
|
||||
if (!Settings.ArtistMetadata)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.Debug("Generating artist.nfo for: {0}", artist.Name);
|
||||
var sb = new StringBuilder();
|
||||
var xws = new XmlWriterSettings();
|
||||
xws.OmitXmlDeclaration = true;
|
||||
xws.Indent = false;
|
||||
|
||||
using (var xw = XmlWriter.Create(sb, xws))
|
||||
{
|
||||
var artistElement = new XElement("artist");
|
||||
|
||||
artistElement.Add(new XElement("title", artist.Name));
|
||||
|
||||
if (artist.Metadata.Value.Ratings != null && artist.Metadata.Value.Ratings.Votes > 0)
|
||||
{
|
||||
artistElement.Add(new XElement("rating", artist.Metadata.Value.Ratings.Value));
|
||||
}
|
||||
|
||||
artistElement.Add(new XElement("musicbrainzartistid", artist.Metadata.Value.ForeignArtistId));
|
||||
artistElement.Add(new XElement("biography", artist.Metadata.Value.Overview));
|
||||
artistElement.Add(new XElement("outline", artist.Metadata.Value.Overview));
|
||||
|
||||
var doc = new XDocument(artistElement);
|
||||
doc.Save(xw);
|
||||
|
||||
_logger.Debug("Saving artist.nfo for {0}", artist.Metadata.Value.Name);
|
||||
|
||||
return new MetadataFileResult("artist.nfo", doc.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public override MetadataFileResult AlbumMetadata(Artist artist, Album album, string albumPath)
|
||||
{
|
||||
if (!Settings.AlbumMetadata)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.Debug("Generating album.nfo for: {0}", album.Title);
|
||||
var sb = new StringBuilder();
|
||||
var xws = new XmlWriterSettings();
|
||||
xws.OmitXmlDeclaration = true;
|
||||
xws.Indent = false;
|
||||
|
||||
using (var xw = XmlWriter.Create(sb, xws))
|
||||
{
|
||||
var albumElement = new XElement("album");
|
||||
|
||||
albumElement.Add(new XElement("title", album.Title));
|
||||
|
||||
if (album.Ratings != null && album.Ratings.Votes > 0)
|
||||
{
|
||||
albumElement.Add(new XElement("rating", album.Ratings.Value));
|
||||
}
|
||||
|
||||
albumElement.Add(new XElement("musicbrainzalbumid", album.ForeignAlbumId));
|
||||
albumElement.Add(new XElement("artistdesc", artist.Metadata.Value.Overview));
|
||||
albumElement.Add(new XElement("releasedate", album.ReleaseDate.Value.ToShortDateString()));
|
||||
|
||||
var doc = new XDocument(albumElement);
|
||||
doc.Save(xw);
|
||||
|
||||
_logger.Debug("Saving album.nfo for {0}", album.Title);
|
||||
|
||||
var fileName = Path.Combine(albumPath, "album.nfo");
|
||||
|
||||
return new MetadataFileResult(fileName, doc.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public override MetadataFileResult TrackMetadata(Artist artist, TrackFile trackFile)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override List<ImageFileResult> ArtistImages(Artist artist)
|
||||
{
|
||||
if (!Settings.ArtistImages)
|
||||
{
|
||||
return new List<ImageFileResult>();
|
||||
}
|
||||
|
||||
return ProcessArtistImages(artist).ToList();
|
||||
}
|
||||
|
||||
public override List<ImageFileResult> AlbumImages(Artist artist, Album album, string albumPath)
|
||||
{
|
||||
if (!Settings.AlbumImages)
|
||||
{
|
||||
return new List<ImageFileResult>();
|
||||
}
|
||||
|
||||
return ProcessAlbumImages(artist, album, albumPath).ToList();
|
||||
}
|
||||
|
||||
public override List<ImageFileResult> TrackImages(Artist artist, TrackFile trackFile)
|
||||
{
|
||||
return new List<ImageFileResult>();
|
||||
}
|
||||
|
||||
private IEnumerable<ImageFileResult> ProcessArtistImages(Artist artist)
|
||||
{
|
||||
foreach (var image in artist.Metadata.Value.Images)
|
||||
{
|
||||
var source = _mediaCoverService.GetCoverPath(artist.Id, MediaCoverEntity.Artist, image.CoverType, image.Extension);
|
||||
var destination = image.CoverType.ToString().ToLowerInvariant() + image.Extension;
|
||||
if (image.CoverType == MediaCoverTypes.Poster)
|
||||
{
|
||||
destination = "folder" + image.Extension;
|
||||
}
|
||||
|
||||
yield return new ImageFileResult(destination, source);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<ImageFileResult> ProcessAlbumImages(Artist artist, Album album, string albumPath)
|
||||
{
|
||||
foreach (var image in album.Images)
|
||||
{
|
||||
// TODO: Make Source fallback to URL if local does not exist
|
||||
// var source = _mediaCoverService.GetCoverPath(album.ArtistId, image.CoverType, null, album.Id);
|
||||
string filename;
|
||||
|
||||
switch (image.CoverType)
|
||||
{
|
||||
case MediaCoverTypes.Cover:
|
||||
filename = "folder";
|
||||
break;
|
||||
case MediaCoverTypes.Disc:
|
||||
filename = "discart";
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
var destination = Path.Combine(albumPath, filename + image.Extension);
|
||||
|
||||
yield return new ImageFileResult(destination, image.Url);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetTrackMetadataFilename(string trackFilePath)
|
||||
{
|
||||
return Path.ChangeExtension(trackFilePath, "nfo");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
using FluentValidation;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
|
||||
{
|
||||
public class XbmcSettingsValidator : AbstractValidator<XbmcMetadataSettings>
|
||||
{
|
||||
}
|
||||
|
||||
public class XbmcMetadataSettings : IProviderConfig
|
||||
{
|
||||
private static readonly XbmcSettingsValidator Validator = new XbmcSettingsValidator();
|
||||
|
||||
public XbmcMetadataSettings()
|
||||
{
|
||||
ArtistMetadata = true;
|
||||
AlbumMetadata = true;
|
||||
ArtistImages = true;
|
||||
AlbumImages = true;
|
||||
}
|
||||
|
||||
[FieldDefinition(0, Label = "Artist Metadata", Type = FieldType.Checkbox, Section = MetadataSectionType.Metadata, HelpText = "artist.nfo")]
|
||||
public bool ArtistMetadata { get; set; }
|
||||
|
||||
[FieldDefinition(1, Label = "Album Metadata", Type = FieldType.Checkbox, Section = MetadataSectionType.Metadata, HelpText = "album.nfo")]
|
||||
public bool AlbumMetadata { get; set; }
|
||||
|
||||
[FieldDefinition(3, Label = "Artist Images", Type = FieldType.Checkbox, Section = MetadataSectionType.Image)]
|
||||
public bool ArtistImages { get; set; }
|
||||
|
||||
[FieldDefinition(4, Label = "Album Images", Type = FieldType.Checkbox, Section = MetadataSectionType.Image)]
|
||||
public bool AlbumImages { get; set; }
|
||||
|
||||
public bool IsValid => true;
|
||||
|
||||
public NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Extras.Files;
|
||||
using NzbDrone.Core.Extras.Lyrics;
|
||||
using NzbDrone.Core.Extras.Metadata.Files;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation;
|
||||
using NzbDrone.Core.Music;
|
||||
@@ -37,7 +36,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
|
||||
public override int Order => 0;
|
||||
|
||||
public override IEnumerable<ExtraFile> ProcessFiles(Artist artist, List<string> filesOnDisk, List<string> importedFiles)
|
||||
public override IEnumerable<ExtraFile> ProcessFiles(Author artist, List<string> filesOnDisk, List<string> importedFiles)
|
||||
{
|
||||
_logger.Debug("Looking for existing metadata in {0}", artist.Path);
|
||||
|
||||
@@ -46,12 +45,6 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
|
||||
foreach (var possibleMetadataFile in filterResult.FilesOnDisk)
|
||||
{
|
||||
// Don't process files that have known Subtitle file extensions (saves a bit of unecessary processing)
|
||||
if (LyricFileExtensions.Extensions.Contains(Path.GetExtension(possibleMetadataFile)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var consumer in _consumers)
|
||||
{
|
||||
var metadata = consumer.FindMetadataFile(artist, possibleMetadataFile);
|
||||
@@ -71,7 +64,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
continue;
|
||||
}
|
||||
|
||||
metadata.AlbumId = localAlbum.Id;
|
||||
metadata.BookId = localAlbum.Id;
|
||||
}
|
||||
|
||||
if (metadata.Type == MetadataType.TrackMetadata)
|
||||
@@ -93,19 +86,11 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
continue;
|
||||
}
|
||||
|
||||
if (localTrack.Tracks.Empty())
|
||||
if (localTrack.Album == null)
|
||||
{
|
||||
_logger.Debug("Cannot find related tracks for: {0}", possibleMetadataFile);
|
||||
_logger.Debug("Cannot find related book for: {0}", possibleMetadataFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (localTrack.Tracks.DistinctBy(e => e.TrackFileId).Count() > 1)
|
||||
{
|
||||
_logger.Debug("Extra file: {0} does not match existing files.", possibleMetadataFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
metadata.TrackFileId = localTrack.Tracks.First().TrackFileId;
|
||||
}
|
||||
|
||||
metadata.Extension = Path.GetExtension(possibleMetadataFile);
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace NzbDrone.Core.Extras.Metadata.Files
|
||||
{
|
||||
public interface ICleanMetadataService
|
||||
{
|
||||
void Clean(Artist artist);
|
||||
void Clean(Author artist);
|
||||
}
|
||||
|
||||
public class CleanExtraFileService : ICleanMetadataService
|
||||
@@ -25,7 +25,7 @@ namespace NzbDrone.Core.Extras.Metadata.Files
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Clean(Artist artist)
|
||||
public void Clean(Author artist)
|
||||
{
|
||||
_logger.Debug("Cleaning missing metadata files for artist: {0}", artist.Name);
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
{
|
||||
public interface IMetadata : IProvider
|
||||
{
|
||||
string GetFilenameAfterMove(Artist artist, TrackFile trackFile, MetadataFile metadataFile);
|
||||
string GetFilenameAfterMove(Artist artist, string albumPath, MetadataFile metadataFile);
|
||||
MetadataFile FindMetadataFile(Artist artist, string path);
|
||||
MetadataFileResult ArtistMetadata(Artist artist);
|
||||
MetadataFileResult AlbumMetadata(Artist artist, Album album, string albumPath);
|
||||
MetadataFileResult TrackMetadata(Artist artist, TrackFile trackFile);
|
||||
List<ImageFileResult> ArtistImages(Artist artist);
|
||||
List<ImageFileResult> AlbumImages(Artist artist, Album album, string albumPath);
|
||||
List<ImageFileResult> TrackImages(Artist artist, TrackFile trackFile);
|
||||
string GetFilenameAfterMove(Author artist, BookFile trackFile, MetadataFile metadataFile);
|
||||
string GetFilenameAfterMove(Author artist, string albumPath, MetadataFile metadataFile);
|
||||
MetadataFile FindMetadataFile(Author artist, string path);
|
||||
MetadataFileResult ArtistMetadata(Author artist);
|
||||
MetadataFileResult AlbumMetadata(Author artist, Book album, string albumPath);
|
||||
MetadataFileResult TrackMetadata(Author artist, BookFile trackFile);
|
||||
List<ImageFileResult> ArtistImages(Author artist);
|
||||
List<ImageFileResult> AlbumImages(Author artist, Book album, string albumPath);
|
||||
List<ImageFileResult> TrackImages(Author artist, BookFile trackFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return new ValidationResult();
|
||||
}
|
||||
|
||||
public virtual string GetFilenameAfterMove(Artist artist, TrackFile trackFile, MetadataFile metadataFile)
|
||||
public virtual string GetFilenameAfterMove(Author artist, BookFile trackFile, MetadataFile metadataFile)
|
||||
{
|
||||
var existingFilename = Path.Combine(artist.Path, metadataFile.RelativePath);
|
||||
var extension = Path.GetExtension(existingFilename).TrimStart('.');
|
||||
@@ -36,7 +36,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return newFileName;
|
||||
}
|
||||
|
||||
public virtual string GetFilenameAfterMove(Artist artist, string albumPath, MetadataFile metadataFile)
|
||||
public virtual string GetFilenameAfterMove(Author artist, string albumPath, MetadataFile metadataFile)
|
||||
{
|
||||
var existingFilename = Path.GetFileName(metadataFile.RelativePath);
|
||||
var newFileName = Path.Combine(artist.Path, albumPath, existingFilename);
|
||||
@@ -44,14 +44,14 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return newFileName;
|
||||
}
|
||||
|
||||
public abstract MetadataFile FindMetadataFile(Artist artist, string path);
|
||||
public abstract MetadataFile FindMetadataFile(Author artist, string path);
|
||||
|
||||
public abstract MetadataFileResult ArtistMetadata(Artist artist);
|
||||
public abstract MetadataFileResult AlbumMetadata(Artist artist, Album album, string albumPath);
|
||||
public abstract MetadataFileResult TrackMetadata(Artist artist, TrackFile trackFile);
|
||||
public abstract List<ImageFileResult> ArtistImages(Artist artist);
|
||||
public abstract List<ImageFileResult> AlbumImages(Artist artist, Album album, string albumPath);
|
||||
public abstract List<ImageFileResult> TrackImages(Artist artist, TrackFile trackFile);
|
||||
public abstract MetadataFileResult ArtistMetadata(Author artist);
|
||||
public abstract MetadataFileResult AlbumMetadata(Author artist, Book album, string albumPath);
|
||||
public abstract MetadataFileResult TrackMetadata(Author artist, BookFile trackFile);
|
||||
public abstract List<ImageFileResult> ArtistImages(Author artist);
|
||||
public abstract List<ImageFileResult> AlbumImages(Author artist, Book album, string albumPath);
|
||||
public abstract List<ImageFileResult> TrackImages(Author artist, BookFile trackFile);
|
||||
|
||||
public virtual object RequestAction(string action, IDictionary<string, string> query)
|
||||
{
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
|
||||
public override int Order => 0;
|
||||
|
||||
public override IEnumerable<ExtraFile> CreateAfterArtistScan(Artist artist, List<TrackFile> trackFiles)
|
||||
public override IEnumerable<ExtraFile> CreateAfterArtistScan(Author artist, List<BookFile> trackFiles)
|
||||
{
|
||||
var metadataFiles = _metadataFileService.GetFilesByArtist(artist.Id);
|
||||
_cleanMetadataService.Clean(artist);
|
||||
@@ -83,7 +83,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
|
||||
foreach (var group in albumGroups)
|
||||
{
|
||||
var album = _albumService.GetAlbum(group.First().AlbumId);
|
||||
var album = _albumService.GetAlbum(group.First().BookId);
|
||||
var albumFolder = group.Key;
|
||||
files.AddIfNotNull(ProcessAlbumMetadata(consumer, artist, album, albumFolder, consumerFiles));
|
||||
files.AddRange(ProcessAlbumImages(consumer, artist, album, albumFolder, consumerFiles));
|
||||
@@ -100,7 +100,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return files;
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> CreateAfterTrackImport(Artist artist, TrackFile trackFile)
|
||||
public override IEnumerable<ExtraFile> CreateAfterTrackImport(Author artist, BookFile trackFile)
|
||||
{
|
||||
var files = new List<MetadataFile>();
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return files;
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> CreateAfterTrackImport(Artist artist, Album album, string artistFolder, string albumFolder)
|
||||
public override IEnumerable<ExtraFile> CreateAfterTrackImport(Author artist, Book album, string artistFolder, string albumFolder)
|
||||
{
|
||||
var metadataFiles = _metadataFileService.GetFilesByArtist(artist.Id);
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return files;
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> MoveFilesAfterRename(Artist artist, List<TrackFile> trackFiles)
|
||||
public override IEnumerable<ExtraFile> MoveFilesAfterRename(Author artist, List<BookFile> trackFiles)
|
||||
{
|
||||
var metadataFiles = _metadataFileService.GetFilesByArtist(artist.Id);
|
||||
var movedFiles = new List<MetadataFile>();
|
||||
@@ -154,7 +154,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
foreach (var filePath in distinctTrackFilePaths)
|
||||
{
|
||||
var metadataFilesForConsumer = GetMetadataFilesForConsumer(consumer, metadataFiles)
|
||||
.Where(m => m.AlbumId == filePath.AlbumId)
|
||||
.Where(m => m.BookId == filePath.BookId)
|
||||
.Where(m => m.Type == MetadataType.AlbumImage || m.Type == MetadataType.AlbumMetadata)
|
||||
.ToList();
|
||||
|
||||
@@ -210,7 +210,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return movedFiles;
|
||||
}
|
||||
|
||||
public override ExtraFile Import(Artist artist, TrackFile trackFile, string path, string extension, bool readOnly)
|
||||
public override ExtraFile Import(Author artist, BookFile trackFile, string path, string extension, bool readOnly)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -220,7 +220,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return artistMetadata.Where(c => c.Consumer == consumer.GetType().Name).ToList();
|
||||
}
|
||||
|
||||
private MetadataFile ProcessArtistMetadata(IMetadata consumer, Artist artist, List<MetadataFile> existingMetadataFiles)
|
||||
private MetadataFile ProcessArtistMetadata(IMetadata consumer, Author artist, List<MetadataFile> existingMetadataFiles)
|
||||
{
|
||||
var artistMetadata = consumer.ArtistMetadata(artist);
|
||||
|
||||
@@ -234,7 +234,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
var metadata = GetMetadataFile(artist, existingMetadataFiles, e => e.Type == MetadataType.ArtistMetadata) ??
|
||||
new MetadataFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
AuthorId = artist.Id,
|
||||
Consumer = consumer.GetType().Name,
|
||||
Type = MetadataType.ArtistMetadata
|
||||
};
|
||||
@@ -265,7 +265,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private MetadataFile ProcessAlbumMetadata(IMetadata consumer, Artist artist, Album album, string albumPath, List<MetadataFile> existingMetadataFiles)
|
||||
private MetadataFile ProcessAlbumMetadata(IMetadata consumer, Author artist, Book album, string albumPath, List<MetadataFile> existingMetadataFiles)
|
||||
{
|
||||
var albumMetadata = consumer.AlbumMetadata(artist, album, albumPath);
|
||||
|
||||
@@ -276,11 +276,11 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
|
||||
var hash = albumMetadata.Contents.SHA256Hash();
|
||||
|
||||
var metadata = GetMetadataFile(artist, existingMetadataFiles, e => e.Type == MetadataType.AlbumMetadata && e.AlbumId == album.Id) ??
|
||||
var metadata = GetMetadataFile(artist, existingMetadataFiles, e => e.Type == MetadataType.AlbumMetadata && e.BookId == album.Id) ??
|
||||
new MetadataFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
AlbumId = album.Id,
|
||||
AuthorId = artist.Id,
|
||||
BookId = album.Id,
|
||||
Consumer = consumer.GetType().Name,
|
||||
Type = MetadataType.AlbumMetadata
|
||||
};
|
||||
@@ -311,7 +311,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private MetadataFile ProcessTrackMetadata(IMetadata consumer, Artist artist, TrackFile trackFile, List<MetadataFile> existingMetadataFiles)
|
||||
private MetadataFile ProcessTrackMetadata(IMetadata consumer, Author artist, BookFile trackFile, List<MetadataFile> existingMetadataFiles)
|
||||
{
|
||||
var trackMetadata = consumer.TrackMetadata(artist, trackFile);
|
||||
|
||||
@@ -342,8 +342,8 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
var metadata = existingMetadata ??
|
||||
new MetadataFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
AlbumId = trackFile.AlbumId,
|
||||
AuthorId = artist.Id,
|
||||
BookId = trackFile.BookId,
|
||||
TrackFileId = trackFile.Id,
|
||||
Consumer = consumer.GetType().Name,
|
||||
Type = MetadataType.TrackMetadata,
|
||||
@@ -364,7 +364,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private List<MetadataFile> ProcessArtistImages(IMetadata consumer, Artist artist, List<MetadataFile> existingMetadataFiles)
|
||||
private List<MetadataFile> ProcessArtistImages(IMetadata consumer, Author artist, List<MetadataFile> existingMetadataFiles)
|
||||
{
|
||||
var result = new List<MetadataFile>();
|
||||
|
||||
@@ -384,7 +384,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
c.RelativePath == image.RelativePath) ??
|
||||
new MetadataFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
AuthorId = artist.Id,
|
||||
Consumer = consumer.GetType().Name,
|
||||
Type = MetadataType.ArtistImage,
|
||||
RelativePath = image.RelativePath,
|
||||
@@ -399,7 +399,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<MetadataFile> ProcessAlbumImages(IMetadata consumer, Artist artist, Album album, string albumFolder, List<MetadataFile> existingMetadataFiles)
|
||||
private List<MetadataFile> ProcessAlbumImages(IMetadata consumer, Author artist, Book album, string albumFolder, List<MetadataFile> existingMetadataFiles)
|
||||
{
|
||||
var result = new List<MetadataFile>();
|
||||
|
||||
@@ -416,12 +416,12 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
_otherExtraFileRenamer.RenameOtherExtraFile(artist, fullPath);
|
||||
|
||||
var metadata = GetMetadataFile(artist, existingMetadataFiles, c => c.Type == MetadataType.AlbumImage &&
|
||||
c.AlbumId == album.Id &&
|
||||
c.BookId == album.Id &&
|
||||
c.RelativePath == image.RelativePath) ??
|
||||
new MetadataFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
AlbumId = album.Id,
|
||||
AuthorId = artist.Id,
|
||||
BookId = album.Id,
|
||||
Consumer = consumer.GetType().Name,
|
||||
Type = MetadataType.AlbumImage,
|
||||
RelativePath = image.RelativePath,
|
||||
@@ -436,7 +436,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
return result;
|
||||
}
|
||||
|
||||
private void DownloadImage(Artist artist, ImageFileResult image)
|
||||
private void DownloadImage(Author artist, ImageFileResult image)
|
||||
{
|
||||
var fullPath = Path.Combine(artist.Path, image.RelativePath);
|
||||
|
||||
@@ -469,7 +469,7 @@ namespace NzbDrone.Core.Extras.Metadata
|
||||
_mediaFileAttributeService.SetFilePermissions(path);
|
||||
}
|
||||
|
||||
private MetadataFile GetMetadataFile(Artist artist, List<MetadataFile> existingMetadataFiles, Func<MetadataFile, bool> predicate)
|
||||
private MetadataFile GetMetadataFile(Author artist, List<MetadataFile> existingMetadataFiles, Func<MetadataFile, bool> predicate)
|
||||
{
|
||||
var matchingMetadataFiles = existingMetadataFiles.Where(predicate).ToList();
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace NzbDrone.Core.Extras.Others
|
||||
|
||||
public override int Order => 2;
|
||||
|
||||
public override IEnumerable<ExtraFile> ProcessFiles(Artist artist, List<string> filesOnDisk, List<string> importedFiles)
|
||||
public override IEnumerable<ExtraFile> ProcessFiles(Author artist, List<string> filesOnDisk, List<string> importedFiles)
|
||||
{
|
||||
_logger.Debug("Looking for existing extra files in {0}", artist.Path);
|
||||
|
||||
@@ -62,23 +62,16 @@ namespace NzbDrone.Core.Extras.Others
|
||||
continue;
|
||||
}
|
||||
|
||||
if (localTrack.Tracks.Empty())
|
||||
if (localTrack.Album == null)
|
||||
{
|
||||
_logger.Debug("Cannot find related tracks for: {0}", possibleExtraFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (localTrack.Tracks.DistinctBy(e => e.TrackFileId).Count() > 1)
|
||||
{
|
||||
_logger.Debug("Extra file: {0} does not match existing files.", possibleExtraFile);
|
||||
_logger.Debug("Cannot find related book for: {0}", possibleExtraFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
var extraFile = new OtherExtraFile
|
||||
{
|
||||
ArtistId = artist.Id,
|
||||
AlbumId = localTrack.Album.Id,
|
||||
TrackFileId = localTrack.Tracks.First().TrackFileId,
|
||||
AuthorId = artist.Id,
|
||||
BookId = localTrack.Album.Id,
|
||||
RelativePath = artist.Path.GetRelativePath(possibleExtraFile),
|
||||
Extension = extension
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace NzbDrone.Core.Extras.Others
|
||||
{
|
||||
public interface IOtherExtraFileRenamer
|
||||
{
|
||||
void RenameOtherExtraFile(Artist artist, string path);
|
||||
void RenameOtherExtraFile(Author artist, string path);
|
||||
}
|
||||
|
||||
public class OtherExtraFileRenamer : IOtherExtraFileRenamer
|
||||
@@ -33,7 +33,7 @@ namespace NzbDrone.Core.Extras.Others
|
||||
_otherExtraFileService = otherExtraFileService;
|
||||
}
|
||||
|
||||
public void RenameOtherExtraFile(Artist artist, string path)
|
||||
public void RenameOtherExtraFile(Author artist, string path)
|
||||
{
|
||||
if (!_diskProvider.FileExists(path))
|
||||
{
|
||||
@@ -58,7 +58,7 @@ namespace NzbDrone.Core.Extras.Others
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveOtherExtraFile(Artist artist, string path)
|
||||
private void RemoveOtherExtraFile(Author artist, string path)
|
||||
{
|
||||
if (!_diskProvider.FileExists(path))
|
||||
{
|
||||
|
||||
@@ -26,22 +26,22 @@ namespace NzbDrone.Core.Extras.Others
|
||||
|
||||
public override int Order => 2;
|
||||
|
||||
public override IEnumerable<ExtraFile> CreateAfterArtistScan(Artist artist, List<TrackFile> trackFiles)
|
||||
public override IEnumerable<ExtraFile> CreateAfterArtistScan(Author artist, List<BookFile> trackFiles)
|
||||
{
|
||||
return Enumerable.Empty<ExtraFile>();
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> CreateAfterTrackImport(Artist artist, TrackFile trackFile)
|
||||
public override IEnumerable<ExtraFile> CreateAfterTrackImport(Author artist, BookFile trackFile)
|
||||
{
|
||||
return Enumerable.Empty<ExtraFile>();
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> CreateAfterTrackImport(Artist artist, Album album, string artistFolder, string albumFolder)
|
||||
public override IEnumerable<ExtraFile> CreateAfterTrackImport(Author artist, Book album, string artistFolder, string albumFolder)
|
||||
{
|
||||
return Enumerable.Empty<ExtraFile>();
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> MoveFilesAfterRename(Artist artist, List<TrackFile> trackFiles)
|
||||
public override IEnumerable<ExtraFile> MoveFilesAfterRename(Author artist, List<BookFile> trackFiles)
|
||||
{
|
||||
var extraFiles = _otherExtraFileService.GetFilesByArtist(artist.Id);
|
||||
var movedFiles = new List<OtherExtraFile>();
|
||||
@@ -61,7 +61,7 @@ namespace NzbDrone.Core.Extras.Others
|
||||
return movedFiles;
|
||||
}
|
||||
|
||||
public override ExtraFile Import(Artist artist, TrackFile trackFile, string path, string extension, bool readOnly)
|
||||
public override ExtraFile Import(Author artist, BookFile trackFile, string path, string extension, bool readOnly)
|
||||
{
|
||||
var extraFile = ImportFile(artist, trackFile, path, readOnly, extension, null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user