Add Locate Audiobooks function (#485)
This commit is contained in:
parent
c4acd5d208
commit
bba9c2ba7b
30
Source/LibationAvalonia/Dialogs/LocateAudiobooksDialog.axaml
Normal file
30
Source/LibationAvalonia/Dialogs/LocateAudiobooksDialog.axaml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450"
|
||||||
|
Width="600" Height="450"
|
||||||
|
x:Class="LibationAvalonia.Dialogs.LocateAudiobooksDialog"
|
||||||
|
Title="Locate Audiobooks"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
Icon="/Assets/libation.ico">
|
||||||
|
|
||||||
|
<Grid Margin="5" ColumnDefinitions="*,Auto" RowDefinitions="Auto,*">
|
||||||
|
<TextBlock Grid.Column="0" Text="Found Audiobooks" />
|
||||||
|
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||||
|
|
||||||
|
<TextBlock Text="IDs Found: " />
|
||||||
|
<TextBlock Text="{Binding FoundAsins}" />
|
||||||
|
</StackPanel>
|
||||||
|
<ListBox Margin="0,5,0,0" Grid.Row="1" Grid.ColumnSpan="2" Name="foundAudiobooksLB" Items="{Binding FoundFiles}" AutoScrollToSelectedItem="true">
|
||||||
|
<ListBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Grid ColumnDefinitions="Auto,*">
|
||||||
|
<TextBlock Grid.Column="0" Margin="0,0,10,0" Text="{Binding Item1}" />
|
||||||
|
<TextBlock Grid.Column="1" Text="{Binding Item2}" />
|
||||||
|
</Grid>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListBox.ItemTemplate>
|
||||||
|
</ListBox>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
115
Source/LibationAvalonia/Dialogs/LocateAudiobooksDialog.axaml.cs
Normal file
115
Source/LibationAvalonia/Dialogs/LocateAudiobooksDialog.axaml.cs
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
using ApplicationServices;
|
||||||
|
using Avalonia.Collections;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
|
using Avalonia.Platform.Storage.FileIO;
|
||||||
|
using DataLayer;
|
||||||
|
using LibationAvalonia.ViewModels;
|
||||||
|
using LibationFileManager;
|
||||||
|
using ReactiveUI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibationAvalonia.Dialogs
|
||||||
|
{
|
||||||
|
public partial class LocateAudiobooksDialog : DialogWindow
|
||||||
|
{
|
||||||
|
private event EventHandler<FilePathCache.CacheEntry> FileFound;
|
||||||
|
private readonly CancellationTokenSource tokenSource = new();
|
||||||
|
private readonly List<string> foundAsins = new();
|
||||||
|
private readonly LocatedAudiobooksViewModel _viewModel;
|
||||||
|
public LocateAudiobooksDialog()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
DataContext = _viewModel = new();
|
||||||
|
this.RestoreSizeAndLocation(Configuration.Instance);
|
||||||
|
|
||||||
|
if (Design.IsDesignMode)
|
||||||
|
{
|
||||||
|
_viewModel.FoundFiles.Add(new("[0000001]", "Filename 1.m4b"));
|
||||||
|
_viewModel.FoundFiles.Add(new("[0000002]", "Filename 2.m4b"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Opened += LocateAudiobooksDialog_Opened;
|
||||||
|
FileFound += LocateAudiobooks_FileFound;
|
||||||
|
Closing += LocateAudiobooksDialog_Closing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LocateAudiobooksDialog_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||||
|
{
|
||||||
|
tokenSource.Cancel();
|
||||||
|
//If this dialog is closed before it's completed, Closing is fired
|
||||||
|
//once for the form clising and again for the MessageBox closing.
|
||||||
|
Closing -= LocateAudiobooksDialog_Closing;
|
||||||
|
this.SaveSizeAndLocation(Configuration.Instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LocateAudiobooks_FileFound(object sender, FilePathCache.CacheEntry e)
|
||||||
|
{
|
||||||
|
var newItem = new Tuple<string,string>($"[{e.Id}]", Path.GetFileName(e.Path));
|
||||||
|
_viewModel.FoundFiles.Add(newItem);
|
||||||
|
foundAudiobooksLB.SelectedItem = newItem;
|
||||||
|
|
||||||
|
if (!foundAsins.Any(asin => asin == e.Id))
|
||||||
|
{
|
||||||
|
foundAsins.Add(e.Id);
|
||||||
|
_viewModel.FoundAsins = foundAsins.Count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void LocateAudiobooksDialog_Opened(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var folderPicker = new FolderPickerOpenOptions
|
||||||
|
{
|
||||||
|
Title = "Select the folder to search for audiobooks",
|
||||||
|
AllowMultiple = false,
|
||||||
|
SuggestedStartLocation = new BclStorageFolder(Configuration.Instance.Books.PathWithoutPrefix)
|
||||||
|
};
|
||||||
|
|
||||||
|
var selectedFolder = await StorageProvider.OpenFolderPickerAsync(folderPicker);
|
||||||
|
|
||||||
|
if (selectedFolder.FirstOrDefault().TryGetUri(out var uri) is not true || !Directory.Exists(uri.LocalPath))
|
||||||
|
{
|
||||||
|
await CancelAndCloseAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = DbContexts.GetContext();
|
||||||
|
|
||||||
|
await foreach (var book in AudioFileLocator.FindAudiobooks(uri.LocalPath, tokenSource.Token))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FilePathCache.Insert(book);
|
||||||
|
|
||||||
|
var lb = context.GetLibraryBook_Flat_NoTracking(book.Id);
|
||||||
|
if (lb.Book.UserDefinedItem.BookStatus is not LiberatedStatus.Liberated)
|
||||||
|
await Task.Run(() => lb.UpdateBookStatus(LiberatedStatus.Liberated));
|
||||||
|
|
||||||
|
FileFound?.Invoke(this, book);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Error(ex, "Error adding found audiobook file to Libation. {@audioFile}", book);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await MessageBox.Show(this, $"Libation has found {foundAsins.Count} unique audiobooks and added them to its database. ", $"Found {foundAsins.Count} Audiobooks");
|
||||||
|
await SaveAndCloseAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LocatedAudiobooksViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
private int _foundAsins = 0;
|
||||||
|
public AvaloniaList<Tuple<string, string>> FoundFiles { get; } = new();
|
||||||
|
public int FoundAsins { get => _foundAsins; set => this.RaiseAndSetIfChanged(ref _foundAsins, value); }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -35,13 +35,13 @@
|
|||||||
</DockPanel.Styles>
|
</DockPanel.Styles>
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="5" DockPanel.Dock="Bottom">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="5" DockPanel.Dock="Bottom">
|
||||||
<Button Grid.Column="0" MinWidth="75" MinHeight="28" Name="Button1" Click="Button1_Click" Margin="5">
|
<Button Grid.Column="0" MinWidth="75" MinHeight="28" Name="Button1" Click="Button1_Click" Margin="5">
|
||||||
<TextBlock VerticalAlignment="Center" Text="{Binding Button1Text}"/>
|
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Button1Text}"/>
|
||||||
</Button>
|
</Button>
|
||||||
<Button Grid.Column="1" IsVisible="{Binding HasButton2}" MinWidth="75" MinHeight="28" Name="Button2" Click="Button2_Click" Margin="5">
|
<Button Grid.Column="1" IsVisible="{Binding HasButton2}" MinWidth="75" MinHeight="28" Name="Button2" Click="Button2_Click" Margin="5">
|
||||||
<TextBlock VerticalAlignment="Center" Text="{Binding Button2Text}"/>
|
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Button2Text}"/>
|
||||||
</Button>
|
</Button>
|
||||||
<Button Grid.Column="2" IsVisible="{Binding HasButton3}" MinWidth="75" MinHeight="28" Name="Button3" Click="Button3_Click" Content="Cancel" Margin="5">
|
<Button Grid.Column="2" IsVisible="{Binding HasButton3}" MinWidth="75" MinHeight="28" Name="Button3" Click="Button3_Click" Content="Cancel" Margin="5">
|
||||||
<TextBlock VerticalAlignment="Center" Text="{Binding Button3Text}"/>
|
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Button3Text}"/>
|
||||||
</Button>
|
</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
|||||||
@ -154,6 +154,7 @@ Libation.
|
|||||||
|
|
||||||
private static async Task<DialogResult> ShowCoreAsync(Window owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool saveAndRestorePosition = true)
|
private static async Task<DialogResult> ShowCoreAsync(Window owner, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool saveAndRestorePosition = true)
|
||||||
{
|
{
|
||||||
|
owner = owner?.IsLoaded is true ? owner : null;
|
||||||
var dialog = await Dispatcher.UIThread.InvokeAsync(() => CreateMessageBox(owner, message, caption, buttons, icon, defaultButton, saveAndRestorePosition));
|
var dialog = await Dispatcher.UIThread.InvokeAsync(() => CreateMessageBox(owner, message, caption, buttons, icon, defaultButton, saveAndRestorePosition));
|
||||||
|
|
||||||
return await DisplayWindow(dialog, owner);
|
return await DisplayWindow(dialog, owner);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
|
using FileManager;
|
||||||
using LibationFileManager;
|
using LibationFileManager;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -20,14 +21,14 @@ namespace LibationAvalonia.Views
|
|||||||
{
|
{
|
||||||
Title = "Where to export Library",
|
Title = "Where to export Library",
|
||||||
SuggestedStartLocation = new Avalonia.Platform.Storage.FileIO.BclStorageFolder(Configuration.Instance.Books.PathWithoutPrefix),
|
SuggestedStartLocation = new Avalonia.Platform.Storage.FileIO.BclStorageFolder(Configuration.Instance.Books.PathWithoutPrefix),
|
||||||
SuggestedFileName = $"Libation Library Export {DateTime.Now:yyyy-MM-dd}.xlsx",
|
SuggestedFileName = $"Libation Library Export {DateTime.Now:yyyy-MM-dd}",
|
||||||
DefaultExtension = "xlsx",
|
DefaultExtension = "xlsx",
|
||||||
ShowOverwritePrompt = true,
|
ShowOverwritePrompt = true,
|
||||||
FileTypeChoices = new FilePickerFileType[]
|
FileTypeChoices = new FilePickerFileType[]
|
||||||
{
|
{
|
||||||
new("Excel Workbook (*.xlsx)") { Patterns = new[] { "xlsx" } },
|
new("Excel Workbook (*.xlsx)") { Patterns = new[] { "*.xlsx" } },
|
||||||
new("CSV files (*.csv)") { Patterns = new[] { "csv" } },
|
new("CSV files (*.csv)") { Patterns = new[] { "*.csv" } },
|
||||||
new("JSON files (*.json)") { Patterns = new[] { "json" } },
|
new("JSON files (*.json)") { Patterns = new[] { "*.json" } },
|
||||||
new("All files (*.*)") { Patterns = new[] { "*" } },
|
new("All files (*.*)") { Patterns = new[] { "*" } },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -36,17 +37,17 @@ namespace LibationAvalonia.Views
|
|||||||
|
|
||||||
if (selectedFile?.TryGetUri(out var uri) is not true) return;
|
if (selectedFile?.TryGetUri(out var uri) is not true) return;
|
||||||
|
|
||||||
var ext = System.IO.Path.GetExtension(uri.LocalPath);
|
var ext = FileUtility.GetStandardizedExtension(System.IO.Path.GetExtension(uri.LocalPath));
|
||||||
switch (ext)
|
switch (ext)
|
||||||
{
|
{
|
||||||
case "xlsx": // xlsx
|
case ".xlsx": // xlsx
|
||||||
default:
|
default:
|
||||||
LibraryExporter.ToXlsx(uri.LocalPath);
|
LibraryExporter.ToXlsx(uri.LocalPath);
|
||||||
break;
|
break;
|
||||||
case "csv": // csv
|
case ".csv": // csv
|
||||||
LibraryExporter.ToCsv(uri.LocalPath);
|
LibraryExporter.ToCsv(uri.LocalPath);
|
||||||
break;
|
break;
|
||||||
case "json": // json
|
case ".json": // json
|
||||||
LibraryExporter.ToJson(uri.LocalPath);
|
LibraryExporter.ToJson(uri.LocalPath);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
using AudibleUtilities;
|
using AudibleUtilities;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using LibationAvalonia.Dialogs;
|
||||||
using LibationFileManager;
|
using LibationFileManager;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -77,5 +78,11 @@ namespace LibationAvalonia.Views
|
|||||||
ex);
|
ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void locateAudiobooksToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var locateDialog = new LocateAudiobooksDialog();
|
||||||
|
await locateDialog.ShowDialog(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,9 @@
|
|||||||
<MenuItem IsVisible="{Binding MultipleAccounts}" IsEnabled="{Binding RemoveMenuItemsEnabled}" Click="removeAllAccountsToolStripMenuItem_Click" Header="_Remove Books from All Accounts" />
|
<MenuItem IsVisible="{Binding MultipleAccounts}" IsEnabled="{Binding RemoveMenuItemsEnabled}" Click="removeAllAccountsToolStripMenuItem_Click" Header="_Remove Books from All Accounts" />
|
||||||
<MenuItem IsVisible="{Binding MultipleAccounts}" IsEnabled="{Binding RemoveMenuItemsEnabled}" Click="removeSomeAccountsToolStripMenuItem_Click" Header="_Remove Books from Some Accounts" />
|
<MenuItem IsVisible="{Binding MultipleAccounts}" IsEnabled="{Binding RemoveMenuItemsEnabled}" Click="removeSomeAccountsToolStripMenuItem_Click" Header="_Remove Books from Some Accounts" />
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
<MenuItem Click="locateAudiobooksToolStripMenuItem_Click" Header="Locate Audiobooks" />
|
||||||
|
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
<!-- Liberate Menu -->
|
<!-- Liberate Menu -->
|
||||||
|
|||||||
60
Source/LibationFileManager/AudioFileLocator.cs
Normal file
60
Source/LibationFileManager/AudioFileLocator.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using AAXClean;
|
||||||
|
using Dinah.Core;
|
||||||
|
using FileManager;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LibationFileManager
|
||||||
|
{
|
||||||
|
public static class AudioFileLocator
|
||||||
|
{
|
||||||
|
private static EnumerationOptions enumerationOptions { get; } = new()
|
||||||
|
{
|
||||||
|
RecurseSubdirectories = true,
|
||||||
|
IgnoreInaccessible = true,
|
||||||
|
MatchCasing = MatchCasing.CaseInsensitive
|
||||||
|
};
|
||||||
|
|
||||||
|
public static async IAsyncEnumerable<FilePathCache.CacheEntry> FindAudiobooks(LongPath searchDirectory, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
ArgumentValidator.EnsureNotNull(searchDirectory, nameof(searchDirectory));
|
||||||
|
|
||||||
|
foreach (LongPath path in Directory.EnumerateFiles(searchDirectory, "*.M4B", enumerationOptions))
|
||||||
|
{
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
int generation = 0;
|
||||||
|
FilePathCache.CacheEntry audioFile = default;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var fileStream = File.OpenRead(path);
|
||||||
|
|
||||||
|
var mp4File = await Task.Run(() => new Mp4File(fileStream), cancellationToken);
|
||||||
|
|
||||||
|
generation = GC.GetGeneration(mp4File);
|
||||||
|
|
||||||
|
if (mp4File?.AppleTags?.Asin is not null)
|
||||||
|
audioFile = new FilePathCache.CacheEntry(mp4File.AppleTags.Asin, FileType.Audio, path);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Error(ex, "Error checking for asin in {@file}", path);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
GC.Collect(generation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (audioFile is not null)
|
||||||
|
yield return audioFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -86,7 +86,11 @@ namespace LibationFileManager
|
|||||||
public static void Insert(string id, string path)
|
public static void Insert(string id, string path)
|
||||||
{
|
{
|
||||||
var type = FileTypes.GetFileTypeFromPath(path);
|
var type = FileTypes.GetFileTypeFromPath(path);
|
||||||
var entry = new CacheEntry(id, type, path);
|
Insert(new CacheEntry(id, type, path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Insert(CacheEntry entry)
|
||||||
|
{
|
||||||
cache.Add(entry);
|
cache.Add(entry);
|
||||||
Inserted?.Invoke(null, entry);
|
Inserted?.Invoke(null, entry);
|
||||||
save();
|
save();
|
||||||
|
|||||||
107
Source/LibationWinForms/Dialogs/LocateAudiobooksDialog.Designer.cs
generated
Normal file
107
Source/LibationWinForms/Dialogs/LocateAudiobooksDialog.Designer.cs
generated
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
namespace LibationWinForms.Dialogs
|
||||||
|
{
|
||||||
|
partial class LocateAudiobooksDialog
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
|
this.foundAudiobooksLV = new System.Windows.Forms.ListView();
|
||||||
|
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
|
||||||
|
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
|
||||||
|
this.booksFoundLbl = new System.Windows.Forms.Label();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(12, 9);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(108, 15);
|
||||||
|
this.label1.TabIndex = 1;
|
||||||
|
this.label1.Text = "Found Audiobooks";
|
||||||
|
//
|
||||||
|
// foundAudiobooksLV
|
||||||
|
//
|
||||||
|
this.foundAudiobooksLV.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Left)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.foundAudiobooksLV.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||||
|
this.columnHeader1,
|
||||||
|
this.columnHeader2});
|
||||||
|
this.foundAudiobooksLV.FullRowSelect = true;
|
||||||
|
this.foundAudiobooksLV.Location = new System.Drawing.Point(12, 33);
|
||||||
|
this.foundAudiobooksLV.Name = "foundAudiobooksLV";
|
||||||
|
this.foundAudiobooksLV.Size = new System.Drawing.Size(321, 261);
|
||||||
|
this.foundAudiobooksLV.TabIndex = 2;
|
||||||
|
this.foundAudiobooksLV.UseCompatibleStateImageBehavior = false;
|
||||||
|
this.foundAudiobooksLV.View = System.Windows.Forms.View.Details;
|
||||||
|
//
|
||||||
|
// columnHeader1
|
||||||
|
//
|
||||||
|
this.columnHeader1.Text = "Book ID";
|
||||||
|
this.columnHeader1.Width = 85;
|
||||||
|
//
|
||||||
|
// columnHeader2
|
||||||
|
//
|
||||||
|
this.columnHeader2.Text = "Title";
|
||||||
|
//
|
||||||
|
// booksFoundLbl
|
||||||
|
//
|
||||||
|
this.booksFoundLbl.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.booksFoundLbl.AutoSize = true;
|
||||||
|
this.booksFoundLbl.Location = new System.Drawing.Point(253, 9);
|
||||||
|
this.booksFoundLbl.Name = "booksFoundLbl";
|
||||||
|
this.booksFoundLbl.Size = new System.Drawing.Size(80, 15);
|
||||||
|
this.booksFoundLbl.TabIndex = 3;
|
||||||
|
this.booksFoundLbl.Text = "IDs Found: {0}";
|
||||||
|
this.booksFoundLbl.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
||||||
|
//
|
||||||
|
// LocateAudiobooksDialog
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(345, 306);
|
||||||
|
this.Controls.Add(this.booksFoundLbl);
|
||||||
|
this.Controls.Add(this.foundAudiobooksLV);
|
||||||
|
this.Controls.Add(this.label1);
|
||||||
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
|
||||||
|
this.Name = "LocateAudiobooksDialog";
|
||||||
|
this.Text = "Locate Audiobooks";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Label label1;
|
||||||
|
private System.Windows.Forms.ListView foundAudiobooksLV;
|
||||||
|
private System.Windows.Forms.ColumnHeader columnHeader1;
|
||||||
|
private System.Windows.Forms.ColumnHeader columnHeader2;
|
||||||
|
private System.Windows.Forms.Label booksFoundLbl;
|
||||||
|
}
|
||||||
|
}
|
||||||
98
Source/LibationWinForms/Dialogs/LocateAudiobooksDialog.cs
Normal file
98
Source/LibationWinForms/Dialogs/LocateAudiobooksDialog.cs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
using ApplicationServices;
|
||||||
|
using DataLayer;
|
||||||
|
using LibationFileManager;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace LibationWinForms.Dialogs
|
||||||
|
{
|
||||||
|
public partial class LocateAudiobooksDialog : Form
|
||||||
|
{
|
||||||
|
private event EventHandler<FilePathCache.CacheEntry> FileFound;
|
||||||
|
private readonly CancellationTokenSource tokenSource = new();
|
||||||
|
private readonly List<string> foundAsins = new();
|
||||||
|
private readonly string labelFormatText;
|
||||||
|
public LocateAudiobooksDialog()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
labelFormatText = booksFoundLbl.Text;
|
||||||
|
setFoundBookCount(0);
|
||||||
|
|
||||||
|
this.SetLibationIcon();
|
||||||
|
this.RestoreSizeAndLocation(Configuration.Instance);
|
||||||
|
|
||||||
|
Shown += LocateAudiobooks_Shown;
|
||||||
|
FileFound += LocateAudiobooks_FileFound;
|
||||||
|
FormClosing += LocateAudiobooks_FormClosing;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFoundBookCount(int count)
|
||||||
|
=> booksFoundLbl.Text = string.Format(labelFormatText, count);
|
||||||
|
|
||||||
|
private void LocateAudiobooks_FileFound(object sender, FilePathCache.CacheEntry e)
|
||||||
|
{
|
||||||
|
foundAudiobooksLV.Items
|
||||||
|
.Add(new ListViewItem(new string[] { $"[{e.Id}]", Path.GetFileName(e.Path) }))
|
||||||
|
.EnsureVisible();
|
||||||
|
|
||||||
|
foundAudiobooksLV.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
|
||||||
|
|
||||||
|
if (!foundAsins.Any(asin => asin == e.Id))
|
||||||
|
{
|
||||||
|
foundAsins.Add(e.Id);
|
||||||
|
setFoundBookCount(foundAsins.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LocateAudiobooks_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
tokenSource.Cancel();
|
||||||
|
this.SaveSizeAndLocation(Configuration.Instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void LocateAudiobooks_Shown(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var fbd = new FolderBrowserDialog
|
||||||
|
{
|
||||||
|
Description = "Select the folder to search for audiobooks",
|
||||||
|
UseDescriptionForTitle = true,
|
||||||
|
InitialDirectory = Configuration.Instance.Books
|
||||||
|
};
|
||||||
|
|
||||||
|
if (fbd.ShowDialog() != DialogResult.OK || !Directory.Exists(fbd.SelectedPath))
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var context = DbContexts.GetContext();
|
||||||
|
|
||||||
|
await foreach (var book in AudioFileLocator.FindAudiobooks(fbd.SelectedPath, tokenSource.Token))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FilePathCache.Insert(book);
|
||||||
|
|
||||||
|
var lb = context.GetLibraryBook_Flat_NoTracking(book.Id);
|
||||||
|
if (lb.Book.UserDefinedItem.BookStatus is not LiberatedStatus.Liberated)
|
||||||
|
await Task.Run(() => lb.UpdateBookStatus(LiberatedStatus.Liberated));
|
||||||
|
|
||||||
|
this.Invoke(FileFound, this, book);
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
Serilog.Log.Error(ex, "Error adding found audiobook file to Libation. {@audioFile}", book);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show(this, $"Libation has found {foundAsins.Count} unique audiobooks and added them to its database. ", $"Found {foundAsins.Count} Audiobooks");
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
60
Source/LibationWinForms/Dialogs/LocateAudiobooksDialog.resx
Normal file
60
Source/LibationWinForms/Dialogs/LocateAudiobooksDialog.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
||||||
20
Source/LibationWinForms/Form1.Designer.cs
generated
20
Source/LibationWinForms/Form1.Designer.cs
generated
@ -60,7 +60,9 @@
|
|||||||
this.setBookDownloadedManualToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.setBookDownloadedManualToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.setPdfDownloadedManualToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.setPdfDownloadedManualToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.setDownloadedAutoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.setDownloadedAutoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
|
||||||
this.removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.locateAudiobooksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.accountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.accountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.basicSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.basicSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
@ -149,7 +151,9 @@
|
|||||||
this.scanLibraryToolStripMenuItem,
|
this.scanLibraryToolStripMenuItem,
|
||||||
this.scanLibraryOfAllAccountsToolStripMenuItem,
|
this.scanLibraryOfAllAccountsToolStripMenuItem,
|
||||||
this.scanLibraryOfSomeAccountsToolStripMenuItem,
|
this.scanLibraryOfSomeAccountsToolStripMenuItem,
|
||||||
this.removeLibraryBooksToolStripMenuItem});
|
this.removeLibraryBooksToolStripMenuItem,
|
||||||
|
this.toolStripSeparator3,
|
||||||
|
this.locateAudiobooksToolStripMenuItem});
|
||||||
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
|
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
|
||||||
this.importToolStripMenuItem.Size = new System.Drawing.Size(55, 20);
|
this.importToolStripMenuItem.Size = new System.Drawing.Size(55, 20);
|
||||||
this.importToolStripMenuItem.Text = "&Import";
|
this.importToolStripMenuItem.Text = "&Import";
|
||||||
@ -560,6 +564,18 @@
|
|||||||
this.processBookQueue1.Name = "processBookQueue1";
|
this.processBookQueue1.Name = "processBookQueue1";
|
||||||
this.processBookQueue1.Size = new System.Drawing.Size(430, 640);
|
this.processBookQueue1.Size = new System.Drawing.Size(430, 640);
|
||||||
this.processBookQueue1.TabIndex = 0;
|
this.processBookQueue1.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// locateAudiobooksToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.locateAudiobooksToolStripMenuItem.Name = "locateAudiobooksToolStripMenuItem";
|
||||||
|
this.locateAudiobooksToolStripMenuItem.Size = new System.Drawing.Size(247, 22);
|
||||||
|
this.locateAudiobooksToolStripMenuItem.Text = "Locate Audiobooks";
|
||||||
|
this.locateAudiobooksToolStripMenuItem.Click += new System.EventHandler(this.locateAudiobooksToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// toolStripSeparator3
|
||||||
|
//
|
||||||
|
this.toolStripSeparator3.Name = "toolStripSeparator3";
|
||||||
|
this.toolStripSeparator3.Size = new System.Drawing.Size(244, 6);
|
||||||
//
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
@ -630,6 +646,8 @@
|
|||||||
private System.Windows.Forms.ToolStripMenuItem setBookDownloadedManualToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem setBookDownloadedManualToolStripMenuItem;
|
||||||
private System.Windows.Forms.ToolStripMenuItem setDownloadedAutoToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem setDownloadedAutoToolStripMenuItem;
|
||||||
private System.Windows.Forms.ToolStripMenuItem removeToolStripMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem removeToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem locateAudiobooksToolStripMenuItem;
|
||||||
private LibationWinForms.FormattableToolStripMenuItem liberateVisibleToolStripMenuItem_LiberateMenu;
|
private LibationWinForms.FormattableToolStripMenuItem liberateVisibleToolStripMenuItem_LiberateMenu;
|
||||||
private System.Windows.Forms.SplitContainer splitContainer1;
|
private System.Windows.Forms.SplitContainer splitContainer1;
|
||||||
private LibationWinForms.ProcessQueue.ProcessQueueControl processBookQueue1;
|
private LibationWinForms.ProcessQueue.ProcessQueueControl processBookQueue1;
|
||||||
|
|||||||
@ -89,5 +89,10 @@ namespace LibationWinForms
|
|||||||
ex);
|
ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void locateAudiobooksToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
new LocateAudiobooksDialog().ShowDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ using ApplicationServices;
|
|||||||
using Dinah.Core;
|
using Dinah.Core;
|
||||||
using Dinah.Core.Threading;
|
using Dinah.Core.Threading;
|
||||||
using LibationFileManager;
|
using LibationFileManager;
|
||||||
|
using LibationWinForms.Dialogs;
|
||||||
|
|
||||||
namespace LibationWinForms
|
namespace LibationWinForms
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user