Skip to content

Commit

Permalink
Re-add media tagging as an option in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Apr 15, 2022
1 parent 725d535 commit 8c3c08e
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 23 deletions.
11 changes: 0 additions & 11 deletions YoutubeDownloader.Core/Downloading/VideoDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading;
using System.Threading.Tasks;
using Gress;
using YoutubeDownloader.Core.Downloading.Tagging;
using YoutubeDownloader.Core.Utils;
using YoutubeExplode;
using YoutubeExplode.Converter;
Expand All @@ -16,7 +15,6 @@ namespace YoutubeDownloader.Core.Downloading;
public class VideoDownloader
{
private readonly YoutubeClient _youtube = new(Http.Client);
private readonly MediaTagInjector _tagInjector = new();

public async Task<IReadOnlyList<VideoDownloadOption>> GetDownloadOptionsAsync(
VideoId videoId,
Expand Down Expand Up @@ -64,14 +62,5 @@ await _youtube.Videos.DownloadAsync(
progress?.ToDoubleBased(),
cancellationToken
);

try
{
await _tagInjector.InjectTagsAsync(filePath, video, cancellationToken);
}
catch
{
// Not critical, ignore
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using TagLib;
using TagFile = TagLib.File;

namespace YoutubeDownloader.Core.Downloading.Tagging;
namespace YoutubeDownloader.Core.Tagging;

internal partial class MediaFile : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using YoutubeDownloader.Core.Utils.Extensions;
using YoutubeExplode.Videos;

namespace YoutubeDownloader.Core.Downloading.Tagging;
namespace YoutubeDownloader.Core.Tagging;

internal class MediaTagInjector
public class MediaTagInjector
{
private readonly MusicBrainzClient _musicBrainz = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
using JsonExtensions.Http;
using JsonExtensions.Reading;
using YoutubeDownloader.Core.Utils;
using YoutubeDownloader.Core.Utils.Extensions;

namespace YoutubeDownloader.Core.Downloading.Tagging;
namespace YoutubeDownloader.Core.Tagging;

internal class MusicBrainzClient
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace YoutubeDownloader.Core.Downloading.Tagging;
namespace YoutubeDownloader.Core.Tagging;

internal record MusicBrainzRecording(
string Artist,
Expand Down
2 changes: 2 additions & 0 deletions YoutubeDownloader/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public partial class SettingsService : SettingsManager

public bool IsDarkModeEnabled { get; set; } = IsDarkModeEnabledByDefault();

public bool ShouldInjectTags { get; set; } = true;

public bool ShouldSkipExistingFiles { get; set; }

public string FileNameTemplate { get; set; } = "$title";
Expand Down
22 changes: 21 additions & 1 deletion YoutubeDownloader/ViewModels/Components/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Stylet;
using YoutubeDownloader.Core.Downloading;
using YoutubeDownloader.Core.Resolving;
using YoutubeDownloader.Core.Tagging;
using YoutubeDownloader.Services;
using YoutubeDownloader.Utils;
using YoutubeDownloader.ViewModels.Dialogs;
Expand All @@ -19,12 +20,14 @@ public class DashboardViewModel : PropertyChangedBase
{
private readonly IViewModelFactory _viewModelFactory;
private readonly DialogManager _dialogManager;
private readonly SettingsService _settingsService;

private readonly AutoResetProgressMuxer _progressMuxer;
private readonly ResizableSemaphore _downloadSemaphore = new();

private readonly QueryResolver _queryResolver = new();
private readonly VideoDownloader _videoDownloader = new();
private readonly MediaTagInjector _mediaTagInjector = new();

public bool IsBusy { get; private set; }

Expand All @@ -43,10 +46,11 @@ public DashboardViewModel(
{
_viewModelFactory = viewModelFactory;
_dialogManager = dialogManager;
_settingsService = settingsService;

_progressMuxer = Progress.CreateMuxer().WithAutoReset();

settingsService.BindAndInvoke(o => o.ParallelLimit, (_, e) => _downloadSemaphore.MaxCount = e.NewValue);
_settingsService.BindAndInvoke(o => o.ParallelLimit, (_, e) => _downloadSemaphore.MaxCount = e.NewValue);
Progress.Bind(o => o.Current, (_, _) => NotifyOfPropertyChange(() => IsProgressIndeterminate));
}

Expand Down Expand Up @@ -84,6 +88,22 @@ await _videoDownloader.DownloadAsync(
download.CancellationToken
);

if (_settingsService.ShouldInjectTags)
{
try
{
await _mediaTagInjector.InjectTagsAsync(
download.FilePath!,
download.Video!,
download.CancellationToken
);
}
catch
{
// Media tagging is not critical
}
}

download.Status = DownloadStatus.Completed;
}
catch (Exception ex)
Expand Down
6 changes: 6 additions & 0 deletions YoutubeDownloader/ViewModels/Dialogs/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public bool IsDarkModeEnabled
set => _settingsService.IsDarkModeEnabled = value;
}

public bool ShouldInjectTags
{
get => _settingsService.ShouldInjectTags;
set => _settingsService.ShouldInjectTags = value;
}

public bool ShouldSkipExistingFiles
{
get => _settingsService.ShouldSkipExistingFiles;
Expand Down
21 changes: 18 additions & 3 deletions YoutubeDownloader/Views/Dialogs/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<Run Text="Perform automatic updates on every launch" />
<LineBreak />
<Run FontWeight="SemiBold" Text="Warning:" />
<Run Text="disabling this is NOT recommended because the application will stop working when integration with YouTube inevitably breaks in the future" />
<Run Text="it's recommended to leave this option enabled to ensure that the app is compatible with the latest version of YouTube" />
</TextBlock>
</DockPanel.ToolTip>
<TextBlock
Expand Down Expand Up @@ -73,11 +73,26 @@
Unchecked="DarkModeToggleButton_Unchecked" />
</DockPanel>

<!-- Inject tags -->
<DockPanel
Background="Transparent"
LastChildFill="False"
ToolTip="Inject media tags into downloaded files">
<TextBlock
Margin="16,8"
DockPanel.Dock="Left"
Text="Inject media tags" />
<ToggleButton
Margin="16,8"
DockPanel.Dock="Right"
IsChecked="{Binding ShouldInjectTags}" />
</DockPanel>

<!-- Skip existing files -->
<DockPanel
Background="Transparent"
LastChildFill="False"
ToolTip="When selecting multiple videos to download, skip those that already have a matching file in the target directory">
ToolTip="When selecting multiple videos to download, skip those that already have matching files in the target directory">
<TextBlock
Margin="16,8"
DockPanel.Dock="Left"
Expand Down Expand Up @@ -129,7 +144,7 @@
Margin="16,8"
Background="Transparent"
LastChildFill="False"
ToolTip="How many downloads can be active at one time">
ToolTip="How many downloads can be active at the same time">
<TextBlock
VerticalAlignment="Center"
DockPanel.Dock="Left"
Expand Down

0 comments on commit 8c3c08e

Please sign in to comment.