Fix - Subtitles not moved from temp folder if only subtitles were downloaded https://github.com/Crunchy-DL/Crunchy-Downloader/issues/90
This commit is contained in:
parent
39c24be100
commit
d665bffe5a
|
@ -223,7 +223,7 @@ public class CrunchyrollManager{
|
|||
|
||||
QueueManager.Instance.Queue.Refresh();
|
||||
|
||||
var fileNameAndPath = CrunOptions.DownloadToTempFolder ? Path.Combine(res.TempFolderPath, res.FileName) : Path.Combine(res.FolderPath, res.FileName);
|
||||
var fileNameAndPath = CrunOptions.DownloadToTempFolder ? Path.Combine(res.TempFolderPath ?? string.Empty, res.FileName ?? string.Empty) : Path.Combine(res.FolderPath ?? string.Empty, res.FileName ?? string.Empty);
|
||||
if (CrunOptions is{ DlVideoOnce: false, KeepDubsSeperate: true }){
|
||||
var groupByDub = Helpers.GroupByLanguageWithSubtitles(res.Data);
|
||||
var mergers = new List<Merger>();
|
||||
|
@ -255,7 +255,9 @@ public class CrunchyrollManager{
|
|||
|
||||
foreach (var merger in mergers){
|
||||
merger.CleanUp();
|
||||
await MoveFromTempFolder(merger, data, res.TempFolderPath, res.Data.Where(e => e.Type == DownloadMediaType.Subtitle));
|
||||
if (CrunOptions.DownloadToTempFolder){
|
||||
await MoveFromTempFolder(merger, data, res.TempFolderPath, res.Data.Where(e => e.Type == DownloadMediaType.Subtitle));
|
||||
}
|
||||
}
|
||||
} else{
|
||||
var result = await MuxStreams(res.Data,
|
||||
|
@ -280,7 +282,9 @@ public class CrunchyrollManager{
|
|||
|
||||
if (result is{ merger: not null, isMuxed: true }){
|
||||
result.merger.CleanUp();
|
||||
}
|
||||
|
||||
if (CrunOptions.DownloadToTempFolder){
|
||||
await MoveFromTempFolder(result.merger, data, res.TempFolderPath, res.Data.Where(e => e.Type == DownloadMediaType.Subtitle));
|
||||
}
|
||||
}
|
||||
|
@ -315,7 +319,7 @@ public class CrunchyrollManager{
|
|||
|
||||
#region Temp Files Move
|
||||
|
||||
private async Task MoveFromTempFolder(Merger merger, CrunchyEpMeta data, string tempFolderPath, IEnumerable<DownloadedMedia> subtitles){
|
||||
private async Task MoveFromTempFolder(Merger? merger, CrunchyEpMeta data, string tempFolderPath, IEnumerable<DownloadedMedia> subtitles){
|
||||
if (!CrunOptions.DownloadToTempFolder) return;
|
||||
|
||||
data.DownloadProgress = new DownloadProgress{
|
||||
|
@ -335,19 +339,17 @@ public class CrunchyrollManager{
|
|||
}
|
||||
|
||||
// Move the main output file
|
||||
await MoveFile(merger.options.Output, tempFolderPath, data.DownloadPath);
|
||||
await MoveFile(merger?.options.Output ?? string.Empty, tempFolderPath, data.DownloadPath ?? CfgManager.PathVIDEOS_DIR);
|
||||
|
||||
// Move the subtitle files
|
||||
if (CrunOptions.SkipSubsMux){
|
||||
foreach (var downloadedMedia in subtitles){
|
||||
await MoveFile(downloadedMedia.Path ?? string.Empty, tempFolderPath, data.DownloadPath);
|
||||
}
|
||||
foreach (var downloadedMedia in subtitles){
|
||||
await MoveFile(downloadedMedia.Path ?? string.Empty, tempFolderPath, data.DownloadPath ?? CfgManager.PathVIDEOS_DIR);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task MoveFile(string sourcePath, string tempFolderPath, string downloadPath){
|
||||
if (string.IsNullOrEmpty(sourcePath) || !File.Exists(sourcePath)){
|
||||
Console.Error.WriteLine("Source file does not exist or path is invalid.");
|
||||
// Console.Error.WriteLine("Source file does not exist or path is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -364,7 +366,7 @@ public class CrunchyrollManager{
|
|||
? CrunOptions.DownloadDirPath
|
||||
: CfgManager.PathVIDEOS_DIR;
|
||||
|
||||
var destinationPath = Path.Combine(destinationFolder, fileName);
|
||||
var destinationPath = Path.Combine(destinationFolder ?? string.Empty, fileName ?? string.Empty);
|
||||
|
||||
string destinationDirectory = Path.GetDirectoryName(destinationPath);
|
||||
if (string.IsNullOrEmpty(destinationDirectory)){
|
||||
|
@ -1137,6 +1139,7 @@ public class CrunchyrollManager{
|
|||
Console.WriteLine($"An error occurred: {ex.Message}");
|
||||
}
|
||||
|
||||
dlFailed = true;
|
||||
return new DownloadResponse{
|
||||
Data = files,
|
||||
Error = dlFailed,
|
||||
|
@ -1202,6 +1205,7 @@ public class CrunchyrollManager{
|
|||
Console.WriteLine($"An error occurred: {ex.Message}");
|
||||
}
|
||||
|
||||
dlFailed = true;
|
||||
return new DownloadResponse{
|
||||
Data = files,
|
||||
Error = dlFailed,
|
||||
|
@ -1393,6 +1397,9 @@ public class CrunchyrollManager{
|
|||
!string.IsNullOrEmpty(options.DownloadDirPath) ? options.DownloadDirPath : CfgManager.PathVIDEOS_DIR;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(data.DownloadPath)){
|
||||
data.DownloadPath = fileDir;
|
||||
}
|
||||
|
||||
return new DownloadResponse{
|
||||
Data = files,
|
||||
|
|
|
@ -17,7 +17,7 @@ using YamlDotNet.Serialization.NamingConventions;
|
|||
namespace CRD.Utils;
|
||||
|
||||
public class CfgManager{
|
||||
private static string WorkingDirectory = Directory.GetCurrentDirectory();
|
||||
private static string WorkingDirectory = AppContext.BaseDirectory;
|
||||
|
||||
public static readonly string PathCrToken = Path.Combine(WorkingDirectory, "config", "cr_token.yml");
|
||||
public static readonly string PathCrDownloadOptions = Path.Combine(WorkingDirectory, "config", "settings.yml");
|
||||
|
|
|
@ -66,10 +66,10 @@ public struct Episode{
|
|||
|
||||
public struct DownloadResponse{
|
||||
public List<DownloadedMedia> Data{ get; set; }
|
||||
public string FileName{ get; set; }
|
||||
public string? FileName{ get; set; }
|
||||
|
||||
public string FolderPath{ get; set; }
|
||||
public string TempFolderPath{ get; set; }
|
||||
public string? FolderPath{ get; set; }
|
||||
public string? TempFolderPath{ get; set; }
|
||||
|
||||
public string VideoTitle{ get; set; }
|
||||
public bool Error{ get; set; }
|
||||
|
|
|
@ -7,6 +7,7 @@ using Avalonia.Interactivity;
|
|||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Platform;
|
||||
using CRD.Downloader.Crunchyroll;
|
||||
using CRD.Utils;
|
||||
using CRD.Utils.Files;
|
||||
using CRD.Utils.Structs;
|
||||
|
@ -64,7 +65,7 @@ public partial class MainWindow : AppWindow{
|
|||
TitleBar.Height = TitleBarHeightAdjustment;
|
||||
TitleBar.ExtendsContentIntoTitleBar = true;
|
||||
TitleBar.TitleBarHitTestType = TitleBarHitTestType.Complex;
|
||||
|
||||
|
||||
Opened += OnOpened;
|
||||
Closing += OnClosing;
|
||||
|
||||
|
@ -73,7 +74,7 @@ public partial class MainWindow : AppWindow{
|
|||
PositionChanged += OnPositionChanged;
|
||||
SizeChanged += OnSizeChanged;
|
||||
|
||||
|
||||
|
||||
//select first element as default
|
||||
var nv = this.FindControl<NavigationView>("NavView");
|
||||
nv.SelectedItem = nv.MenuItems.ElementAt(0);
|
||||
|
@ -195,7 +196,6 @@ public partial class MainWindow : AppWindow{
|
|||
var screens = Screens.All;
|
||||
if (settings.ScreenIndex >= 0 && settings.ScreenIndex < screens.Count){
|
||||
var screen = screens[settings.ScreenIndex];
|
||||
var screenBounds = screen.Bounds;
|
||||
|
||||
// Restore the position first
|
||||
Position = new PixelPoint(settings.PosX, settings.PosY + TitleBarHeightAdjustment);
|
||||
|
@ -209,7 +209,7 @@ public partial class MainWindow : AppWindow{
|
|||
_restorePosition = new PixelPoint(settings.PosX, settings.PosY + TitleBarHeightAdjustment);
|
||||
|
||||
// Ensure the window is on the correct screen before maximizing
|
||||
Position = new PixelPoint(settings.PosX, settings.PosY+ TitleBarHeightAdjustment);
|
||||
Position = new PixelPoint(settings.PosX, settings.PosY + TitleBarHeightAdjustment);
|
||||
}
|
||||
|
||||
if (settings.IsMaximized){
|
||||
|
@ -232,15 +232,17 @@ public partial class MainWindow : AppWindow{
|
|||
}
|
||||
|
||||
var settings = new WindowSettings{
|
||||
Width = this.WindowState == WindowState.Maximized ? _restoreSize.Width : Width,
|
||||
Height = this.WindowState == WindowState.Maximized ? _restoreSize.Height : Height,
|
||||
Width = WindowState == WindowState.Maximized ? _restoreSize.Width : Width,
|
||||
Height = WindowState == WindowState.Maximized ? _restoreSize.Height : Height,
|
||||
ScreenIndex = screenIndex,
|
||||
PosX = this.WindowState == WindowState.Maximized ? _restorePosition.X : Position.X,
|
||||
PosY = this.WindowState == WindowState.Maximized ? _restorePosition.Y : Position.Y,
|
||||
IsMaximized = this.WindowState == WindowState.Maximized
|
||||
PosX = WindowState == WindowState.Maximized ? _restorePosition.X : Position.X,
|
||||
PosY = WindowState == WindowState.Maximized ? _restorePosition.Y : Position.Y,
|
||||
IsMaximized = WindowState == WindowState.Maximized
|
||||
};
|
||||
|
||||
File.WriteAllText(CfgManager.PathWindowSettings, JsonConvert.SerializeObject(settings, Formatting.Indented));
|
||||
|
||||
FileNameManager.DeleteEmptyFolders(!string.IsNullOrEmpty(CrunchyrollManager.Instance.CrunOptions.DownloadTempDirPath) ? CrunchyrollManager.Instance.CrunOptions.DownloadTempDirPath : CfgManager.PathTEMP_DIR);
|
||||
}
|
||||
|
||||
private void OnWindowStateChanged(object sender, AvaloniaPropertyChangedEventArgs e){
|
||||
|
|
Loading…
Reference in New Issue