![]() |
VOOZH | about |
dotnet add package DoenaSoft.CalculateAudioBookRunningTimes --version 1.0.5
NuGet\Install-Package DoenaSoft.CalculateAudioBookRunningTimes -Version 1.0.5
<PackageReference Include="DoenaSoft.CalculateAudioBookRunningTimes" Version="1.0.5" />
<PackageVersion Include="DoenaSoft.CalculateAudioBookRunningTimes" Version="1.0.5" />Directory.Packages.props
<PackageReference Include="DoenaSoft.CalculateAudioBookRunningTimes" />Project file
paket add DoenaSoft.CalculateAudioBookRunningTimes --version 1.0.5
#r "nuget: DoenaSoft.CalculateAudioBookRunningTimes, 1.0.5"
#:package DoenaSoft.CalculateAudioBookRunningTimes@1.0.5
#addin nuget:?package=DoenaSoft.CalculateAudioBookRunningTimes&version=1.0.5Install as a Cake Addin
#tool nuget:?package=DoenaSoft.CalculateAudioBookRunningTimes&version=1.0.5Install as a Cake Tool
A .NET library for extracting and calculating audiobook metadata including running times, chapters, authors, and narrators from MP3 and MP4 audio files.
This library provides a programmatic interface for processing audiobook collections and generating structured metadata. It abstracts the core functionality of the CalculateAudioBookRunningTimes command-line tool into a reusable library that can be integrated into other applications.
Install-Package DoenaSoft.CalculateAudioBookRunningTimes
dotnet add package DoenaSoft.CalculateAudioBookRunningTimes
<PackageReference Include="DoenaSoft.CalculateAudioBookRunningTimes" Version="*" />
using DoenaSoft.CalculateAudioBookRunningTimes;
using DoenaSoft.AbstractionLayer.IOServices.DefaultImplementations;
// Create an interaction handler
IInteraction interaction = new ConsoleInteraction();
// Create a book processor
var processor = new BookProcessor(
reboot: false, // Set to true to skip already processed books
mp4: false, // Set to true for MP4 files instead of MP3
interaction: interaction
);
// Get folder info
var ioServices = new IOServices();
var folder = ioServices.GetFolderInfo(@"C:\AudioBooks\MyBook");
// Process the audiobook
processor.Process(folder);
using DoenaSoft.CalculateAudioBookRunningTimes;
using DoenaSoft.AbstractionLayer.IOServices.DefaultImplementations;
// Create interaction and book processor
IInteraction interaction = new ConsoleInteraction();
var bookProcessor = new BookProcessor(false, false, interaction);
// Create books processor for batch operations
var booksProcessor = new BooksProcessor(bookProcessor);
// Get root folder
var ioServices = new IOServices();
var rootFolder = ioServices.GetFolderInfo(@"C:\AudioBooks");
// Process all audiobooks in parallel
booksProcessor.Process(rootFolder);
Defines the contract for user interaction and logging:
public interface IInteraction
{
void WriteLine(string message = null);
void Write(string message);
string ReadLine();
}
Purpose: Allows consumers to customize how the library handles:
Example Implementation:
public class ConsoleInteraction : IInteraction
{
public void WriteLine(string message = null)
=> Console.WriteLine(message);
public void Write(string message)
=> Console.Write(message);
public string ReadLine()
=> Console.ReadLine();
}
Processes a single audiobook folder:
Constructor Parameters:
reboot (bool): Skip folders that already have metadata XML filesmp4 (bool): Process MP4 files instead of MP3 filesinteraction (IInteraction): Handler for user interaction and loggingMethods:
Process(IFolderInfo folder): Scans the folder, extracts metadata, and generates XMLBehavior:
reboot is true){FolderName}.xml in the audiobook folderProcesses multiple audiobook folders in parallel:
Constructor Parameters:
bookProcessor (BookProcessor): The processor to use for individual booksMethods:
Process(IFolderInfo rootFolder): Recursively processes audiobook collectionsBehavior:
Provides XSLT stylesheet integration for XML output:
Purpose: Embeds an XSLT stylesheet in the generated XML files for browser-based rendering
Methods:
GetPrefix(): Returns XML header with stylesheet declarationGetSuffix(): Returns embedded XSLT stylesheetCreate a custom interaction handler for GUI applications:
public class GuiInteraction : IInteraction
{
private readonly ILogger _logger;
private readonly IDialogService _dialogService;
public GuiInteraction(ILogger logger, IDialogService dialogService)
{
_logger = logger;
_dialogService = dialogService;
}
public void WriteLine(string message = null)
{
_logger.LogInformation(message);
}
public void Write(string message)
{
_logger.LogInformation(message);
}
public string ReadLine()
{
return _dialogService.ShowInputDialog("Input Required", "");
}
}
public class SilentInteraction : IInteraction
{
private readonly IDictionary<string, string> _predefinedAuthors;
private readonly IDictionary<string, string> _predefinedNarrators;
public void WriteLine(string message = null)
{
// Log to file or ignore
}
public void Write(string message)
{
// Log to file or ignore
}
public string ReadLine()
{
// Return pre-configured values or defaults
return string.Empty;
}
}
The library handles errors gracefully:
try
{
processor.Process(folder);
}
catch (Exception ex)
{
// Errors are logged via IInteraction.WriteLine
// Format: "Error processing '{folder}' {errorMessage}"
}
All exceptions during processing are caught and logged, allowing batch operations to continue.
Generated XML follows the AudioBookMeta schema from DoenaSoft.MediaInfoHelper:
Example Output (BookTitle.xml):
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xml" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
id ID #REQUIRED>
]>
<doc>
<Mp3Meta>
<Title>Book Title</Title>
<Author>John Doe</Author>
<Narrator>Jane Smith</Narrator>
<RunningTime>08:45:32</RunningTime>
</Mp3Meta>
</doc>
C:\AudioBooks\BookTitle\
|-- Chapter01.mp3
|-- Chapter02.mp3
|-- Chapter03.mp3
+-- BookTitle.xml (generated)
C:\AudioBooks\
|-- Book1\
| |-- Chapter01.mp3
| +-- Book1.xml (generated)
|-- Book2\
| |-- Chapter01.mp3
| +-- Book2.xml (generated)
+-- English\
+-- Book3\
|-- Chapter01.mp3
+-- Book3.xml (generated)
Special Handling:
All logging and user interaction operations are protected with locks to ensure thread safety during parallel processing.
Full API documentation is generated via XML documentation comments. Enable XML documentation in your IDE for IntelliSense support.
git clone https://github.com/DJDoena/CalculateAudioBookRunningTimes.git
cd CalculateAudioBookRunningTimes
dotnet build CalculateAudioBookRunningTimesLib/CalculateAudioBookRunningTimesLib.csproj
dotnet pack CalculateAudioBookRunningTimesLib/CalculateAudioBookRunningTimesLib.csproj -c Release
The package will be created in:
CalculateAudioBookRunningTimesLib\bin\Release\DoenaSoft.CalculateAudioBookRunningTimes.{version}.nupkg
The library uses automatic versioning based on build time: yyyy.MM.dd.HHmm
Contributions are welcome! Please:
MIT License - See repository for details
DJDoena (Doena Soft)
Note: This library is designed for personal and professional audiobook library management. Ensure you have appropriate rights to process audiobook files.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net472 net472 is compatible. net48 net48 was computed. net481 net481 is compatible. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.