mirror of
https://github.com/Readarr/Readarr
synced 2025-12-29 19:54:20 +01:00
Fixed: Set part numbers using alphabetical file ordering if not set in tags
This commit is contained in:
parent
3ec451e85e
commit
01a5c456c4
4 changed files with 26 additions and 4 deletions
|
|
@ -326,6 +326,8 @@ private BookFile GivenPopulatedTrackfile(int mediumOffset)
|
|||
.With(x => x.Author = author)
|
||||
.Build();
|
||||
|
||||
edition.BookFiles = new List<BookFile> { file };
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ public void Setup()
|
|||
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 @@ public void should_import_higher_quality_files_first()
|
|||
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 @@ public void should_import_larger_files_for_same_quality_first()
|
|||
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 @@ public AudioTag GetTrackMetadata(BookFile trackfile)
|
|||
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 @@ public AudioTag GetTrackMetadata(BookFile trackfile)
|
|||
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 @@ public List<RetagBookFilePreview> GetRetagPreviewsByAuthor(int authorId)
|
|||
{
|
||||
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.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 @@ public interface IImportApprovedBooks
|
|||
|
||||
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 @@ public List<ImportResult> Import(List<ImportDecision<LocalBook>> decisions, bool
|
|||
// 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…
Reference in a new issue