Fixed: Set part numbers using alphabetical file ordering if not set in tags

pull/1470/head
ta264 2 years ago
parent 3ec451e85e
commit 01a5c456c4

@ -326,6 +326,8 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
.With(x => x.Author = author)
.Build();
edition.BookFiles = new List<BookFile> { file };
return file;
}

@ -66,6 +66,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Author = author,
Book = book,
Edition = edition,
Part = 1,
Path = Path.Combine(author.Path, "Alien Ant Farm - 01 - Pilot.mp3"),
Quality = new QualityModel(Quality.MP3),
FileTrackInfo = new ParsedTrackInfo
@ -177,6 +178,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Author = lqDecision.Item.Author,
Book = lqDecision.Item.Book,
Edition = lqDecision.Item.Edition,
Part = 1,
Path = @"C:\Test\Music\Alien Ant Farm\Alien Ant Farm - 01 - Pilot.mp3".AsOsAgnostic(),
Quality = new QualityModel(Quality.AZW3),
Size = 1.Megabytes(),
@ -209,6 +211,7 @@ namespace NzbDrone.Core.Test.MediaFiles
Author = fileDecision.Item.Author,
Book = fileDecision.Item.Book,
Edition = fileDecision.Item.Edition,
Part = 1,
Path = @"C:\Test\Music\Alien Ant Farm\Alien Ant Farm - 01 - Pilot.mp3".AsOsAgnostic(),
Quality = new QualityModel(Quality.MP3),
Size = 80.Megabytes()

@ -73,6 +73,7 @@ namespace NzbDrone.Core.MediaFiles
var edition = trackfile.Edition.Value;
var book = edition.Book.Value;
var author = book.Author.Value;
var partCount = edition.BookFiles.Value.Count;
var fileTags = ReadAudioTag(trackfile.Path);
@ -99,8 +100,8 @@ namespace NzbDrone.Core.MediaFiles
Title = edition.Title,
Performers = new[] { author.Name },
BookAuthors = new[] { author.Name },
Track = fileTags.Track,
TrackCount = fileTags.TrackCount,
Track = (uint)trackfile.Part,
TrackCount = (uint)partCount,
Book = book.Title,
Disc = fileTags.Disc,
DiscCount = fileTags.DiscCount,
@ -219,14 +220,14 @@ namespace NzbDrone.Core.MediaFiles
{
var files = _mediaFileService.GetFilesByAuthor(authorId);
return GetPreviews(files).ToList();
return GetPreviews(files).OrderBy(b => b.BookId).ThenBy(b => b.Path).ToList();
}
public List<RetagBookFilePreview> GetRetagPreviewsByBook(int bookId)
{
var files = _mediaFileService.GetFilesByBook(bookId);
return GetPreviews(files).ToList();
return GetPreviews(files).OrderBy(b => b.BookId).ThenBy(b => b.Path).ToList();
}
private IEnumerable<RetagBookFilePreview> GetPreviews(List<BookFile> files)

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
@ -15,6 +17,7 @@ using NzbDrone.Core.Extras;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.RootFolders;
@ -28,6 +31,8 @@ namespace NzbDrone.Core.MediaFiles.BookImport
public class ImportApprovedBooks : IImportApprovedBooks
{
private static readonly RegexReplace PadNumbers = new RegexReplace(@"\d+", n => n.Value.PadLeft(9, '0'), RegexOptions.Compiled);
private readonly IUpgradeMediaFiles _bookFileUpgrader;
private readonly IMediaFileService _mediaFileService;
private readonly IMetadataTagService _metadataTagService;
@ -121,6 +126,17 @@ namespace NzbDrone.Core.MediaFiles.BookImport
// RemoveExistingTrackFiles(author, book);
// }
// make sure part numbers are populated for audio books
// If all audio files and all part numbers are zero, set them by filename order
if (decisionList.All(b => MediaFileExtensions.AudioExtensions.Contains(Path.GetExtension(b.Item.Path)) && b.Item.Part == 0))
{
var part = 1;
foreach (var d in decisionList.OrderBy(x => PadNumbers.Replace(x.Item.Path)))
{
d.Item.Part = part++;
}
}
// set the correct release to be monitored before importing the new files
var newRelease = bookDecision.First().Item.Edition;
_logger.Debug("Updating release to {0}", newRelease);

Loading…
Cancel
Save