1.0-dev9 (Videos list improvements and queue bugs removed)
This commit is contained in:
@@ -59,8 +59,8 @@ At the moment, the application is in the **early stage of development**. Only so
|
||||
|
||||
#### App development plans
|
||||
|
||||
- **1.0-prerelease1** - with Twitch support only, all video and playlist download options and playlist subscription (Q1/Q2 2022)
|
||||
- **1.0-prerelease2** - Youtube support and issues from 1.0-prelease1 closed *[Q2 2022]*
|
||||
- **1.0-prerelease1** - with Twitch support only, all video and playlist download options and playlist subscription *[Q2 2022]*
|
||||
- **1.0-prerelease2** - Youtube support and issues from 1.0-prelease1 closed *[Q3 2022]*
|
||||
- **1.0** - issues from 1.0-prelease2 closed and support for Polish (and maybe German) language *[Q3 2022]*
|
||||
- **1.?** - new video services and language support and closing issues from previous versions. *[?]*
|
||||
- **2.0** - switch from Universal Windows Platform to Windows App SDK *[when Windows App SDK will be more developed and will offer elements which I use in UWP (e.g. Mica)]*
|
||||
|
||||
@@ -231,7 +231,6 @@ namespace VDownload.Core.Services.Sources.Twitch
|
||||
|
||||
// Get playlist
|
||||
string response = await client.DownloadStringTaskAsync(streamUrl);
|
||||
Debug.WriteLine(response);
|
||||
// Create dictionary
|
||||
List<(Uri ChunkUrl, TimeSpan ChunkDuration)> chunks = new List<(Uri ChunkUrl, TimeSpan ChunkDuration)>();
|
||||
|
||||
|
||||
38
VDownload.Core/Services/TaskId.cs
Normal file
38
VDownload.Core/Services/TaskId.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDownload.Core.Services
|
||||
{
|
||||
public class TaskId
|
||||
{
|
||||
// VARIABLES
|
||||
private static readonly Random Random = new Random();
|
||||
private static readonly char[] CharsID = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
|
||||
private static readonly int LengthID = 10;
|
||||
private static readonly List<string> UsedIDs = new List<string>();
|
||||
|
||||
// METHOD
|
||||
public static string Get()
|
||||
{
|
||||
string id;
|
||||
do
|
||||
{
|
||||
id = "";
|
||||
while (id.Length < LengthID)
|
||||
{
|
||||
id += CharsID[Random.Next(0, CharsID.Length)];
|
||||
}
|
||||
} while (UsedIDs.Contains(id));
|
||||
UsedIDs.Add(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
public static void Dispose(string id)
|
||||
{
|
||||
UsedIDs.Remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,6 +145,7 @@
|
||||
<Compile Include="Services\Sources\Twitch\Channel.cs" />
|
||||
<Compile Include="Services\Sources\Twitch\Clip.cs" />
|
||||
<Compile Include="Services\Sources\Twitch\Vod.cs" />
|
||||
<Compile Include="Services\TaskId.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||
|
||||
@@ -1 +1 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 6667 6667" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><path d="M5899.29,2.12l757.274,756.327l-5905.76,5897.97l-757.274,-756.328l5905.76,-5897.97Z" style="fill:#f44336;fill-rule:nonzero;"/><path d="M6656.01,5900.61l-757.241,756.057l-5904.98,-5899.05l757.241,-756.057l5904.98,5899.05Z" style="fill:#f44336;fill-rule:nonzero;"/></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="1600px" height="1600px"><g fill="#f44336"><path d="m20.132 17.303-13.435-13.435c-.586-.586-1.536-.586-2.121 0l-.708.707c-.586.586-.586 1.536 0 2.121l13.435 13.435c.586.586 1.536.586 2.121 0l.707-.707c.587-.585.587-1.535.001-2.121z"/><path d="m17.303 3.868-13.435 13.435c-.586.586-.586 1.536 0 2.121l.707.707c.586.586 1.536.586 2.121 0l13.436-13.434c.586-.586.586-1.536 0-2.121l-.707-.707c-.586-.587-1.536-.587-2.122-.001z"/></g></svg>
|
||||
|
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 502 B |
@@ -140,10 +140,10 @@
|
||||
<Compile Include="Views\Home\HomeVideoAddingPanel.xaml.cs">
|
||||
<DependentUpon>HomeVideoAddingPanel.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\Home\HomeVideosList.cs" />
|
||||
<Compile Include="Views\Home\HomeVideoPanel.xaml.cs">
|
||||
<DependentUpon>HomeVideoPanel.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\Home\HomeVideosList.cs" />
|
||||
<Compile Include="Views\MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -59,7 +59,9 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- VIDEOS LIST -->
|
||||
<StackPanel x:Name="HomeVideosList"/>
|
||||
<ScrollViewer Margin="0,0,0,10" CornerRadius="{ThemeResource ControlCornerRadius}">
|
||||
<StackPanel x:Name="HomeVideosList" Spacing="10"/>
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- OPTIONS BAR AND ADDING PANEL -->
|
||||
<Grid Grid.Row="1" CornerRadius="{ThemeResource ControlCornerRadius}" Background="{ThemeResource HomeBackgroundColor}">
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Core.Enums;
|
||||
using VDownload.Core.EventArgsObjects;
|
||||
using VDownload.Core.Exceptions;
|
||||
using VDownload.Core.Interfaces;
|
||||
using VDownload.Core.Services;
|
||||
using Windows.ApplicationModel.Resources;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
namespace VDownload.Views.Home
|
||||
{
|
||||
@@ -34,13 +38,26 @@ namespace VDownload.Views.Home
|
||||
private readonly Microsoft.UI.Xaml.Controls.ProgressRing HomeOptionsBarSearchingStatusProgressRing = new Microsoft.UI.Xaml.Controls.ProgressRing { Width = 15, Height = 15, Margin = new Thickness(5), IsActive = true };
|
||||
private readonly Image HomeOptionsBarSearchingStatusErrorImage = new Image { Width = 15, Height = 15, Margin = new Thickness(5), Source = (SvgImageSource)new ResourceDictionary { Source = new Uri("ms-appx:///Resources/Icons.xaml") }["ErrorIcon"] };
|
||||
|
||||
CancellationTokenSource SearchingCancellationToken = new CancellationTokenSource();
|
||||
// CANCELLATON TOKEN
|
||||
private CancellationTokenSource SearchingCancellationToken = new CancellationTokenSource();
|
||||
|
||||
// HOME VIDEOS LIST
|
||||
private static StackPanel HomeVideosListOldPanel = null;
|
||||
public static List<HomeVideoPanel> VideoPanelsList = new List<HomeVideoPanel>();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region BUTTONS EVENTS
|
||||
#region EVENT HANDLERS VOIDS
|
||||
|
||||
// ON NAVIGATED TO
|
||||
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
if (HomeVideosListOldPanel != null) HomeVideosListOldPanel.Children.Clear();
|
||||
HomeVideosListOldPanel = HomeVideosList;
|
||||
foreach (HomeVideoPanel homeVideoPanel in VideoPanelsList) HomeVideosList.Children.Add(homeVideoPanel);
|
||||
}
|
||||
|
||||
// ADD VIDEO BUTTON CHECKED
|
||||
private void HomeOptionsBarAddVideoButton_Checked(object sender, RoutedEventArgs e)
|
||||
@@ -159,13 +176,13 @@ namespace VDownload.Views.Home
|
||||
videoPanel.VideoRemovingRequested += (s, a) =>
|
||||
{
|
||||
// Remove video panel/task from videos list
|
||||
VideoPanelsList.Remove(videoPanel);
|
||||
HomeVideosList.Children.Remove(videoPanel);
|
||||
Home.HomeVideosList.VideoList.Remove(videoPanel);
|
||||
};
|
||||
|
||||
// Add video panel/task to videos list
|
||||
HomeVideosList.Children.Add(videoPanel);
|
||||
Home.HomeVideosList.VideoList.Add(videoPanel);
|
||||
VideoPanelsList.Add(videoPanel);
|
||||
}
|
||||
|
||||
|
||||
@@ -277,12 +294,32 @@ namespace VDownload.Views.Home
|
||||
HomeOptionsBarSearchingStatusControl.Content = null;
|
||||
}
|
||||
|
||||
|
||||
// DOWNLOAD ALL BUTTON CLICKED
|
||||
private async void HomeOptionsBarDownloadAllButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
foreach (HomeVideoPanel videoPanel in Home.HomeVideosList.VideoList.Where(video => video.VideoStatus == VideoStatus.Idle)) await videoPanel.Start();
|
||||
foreach (HomeVideoPanel videoPanel in HomeVideosList.Children.Where(video => ((HomeVideoPanel)video).VideoStatus == VideoStatus.Idle))
|
||||
{
|
||||
await Task.Delay(50);
|
||||
videoPanel.Start();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region METHODS
|
||||
|
||||
// WAIT IN QUEUE
|
||||
public static async Task WaitInQueue(CancellationToken token)
|
||||
{
|
||||
while (VideoPanelsList.Where(video => video.VideoStatus == VideoStatus.InProgress).Count() >= (int)Config.GetValue("max_active_video_task") && !token.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ namespace VDownload.Views.Home
|
||||
{ new Regex(@"<duration:(?<format>.*)>"), VideoService.Duration },
|
||||
};
|
||||
foreach (KeyValuePair<Regex, IFormattable> template in filenameFormatTemplates) foreach (Match templateMatch in template.Key.Matches(temporaryFilename)) temporaryFilename = temporaryFilename.Replace(templateMatch.Value, template.Value.ToString(templateMatch.Groups["format"].Value, null));
|
||||
foreach (char c in System.IO.Path.GetInvalidFileNameChars()) temporaryFilename = temporaryFilename.Replace(c, ' ');
|
||||
HomeVideoAddingFilenameTextBox.Text = temporaryFilename;
|
||||
Filename = temporaryFilename;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
|
||||
mc:Ignorable="d"
|
||||
CornerRadius="{ThemeResource ControlCornerRadius}"
|
||||
d:DesignHeight="150"
|
||||
d:DesignWidth="800">
|
||||
|
||||
@@ -20,7 +21,7 @@
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid Background="{ThemeResource HomeBackgroundColor}" Padding="10" ColumnSpacing="10">
|
||||
<Grid Background="{ThemeResource HomeBackgroundColor}" CornerRadius="{ThemeResource ControlCornerRadius}" Padding="10" ColumnSpacing="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
|
||||
@@ -129,109 +129,121 @@ namespace VDownload.Views.Home
|
||||
HomeVideoPanelStateProgressBar.IsIndeterminate = true;
|
||||
|
||||
// Wait in queue
|
||||
await HomeVideosList.WaitInQueue(CancellationTokenSource.Token);
|
||||
|
||||
// Get task unique ID
|
||||
string uniqueID = HomeVideosList.GetUniqueID();
|
||||
|
||||
// Get temporary folder
|
||||
StorageFolder tempFolder;
|
||||
if ((bool)Config.GetValue("custom_temp_location") && StorageApplicationPermissions.FutureAccessList.ContainsItem("custom_temp_location"))
|
||||
tempFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("custom_temp_location");
|
||||
else
|
||||
tempFolder = ApplicationData.Current.TemporaryFolder;
|
||||
tempFolder = await tempFolder.CreateFolderAsync(uniqueID);
|
||||
|
||||
try
|
||||
await HomeMain.WaitInQueue(CancellationTokenSource.Token);
|
||||
if (!CancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
// Set cancellation token to throw exception on request
|
||||
CancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
|
||||
// Set video status
|
||||
VideoStatus = VideoStatus.InProgress;
|
||||
|
||||
// Start stopwatch
|
||||
Stopwatch taskStopwatch = Stopwatch.StartNew();
|
||||
// Get task unique ID
|
||||
string uniqueID = TaskId.Get();
|
||||
|
||||
// Set progress event handlers
|
||||
VideoService.DownloadingStarted += (s, a) =>
|
||||
// Get temporary folder
|
||||
StorageFolder tempFolder;
|
||||
if ((bool)Config.GetValue("custom_temp_location") && StorageApplicationPermissions.FutureAccessList.ContainsItem("custom_temp_location"))
|
||||
tempFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("custom_temp_location");
|
||||
else
|
||||
tempFolder = ApplicationData.Current.TemporaryFolder;
|
||||
tempFolder = await tempFolder.CreateFolderAsync(uniqueID);
|
||||
|
||||
try
|
||||
{
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateDownloadingIcon"];
|
||||
HomeVideoPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextDownloading")} (0%)";
|
||||
HomeVideoPanelStateProgressBar.IsIndeterminate = false;
|
||||
HomeVideoPanelStateProgressBar.Value = 0;
|
||||
};
|
||||
VideoService.DownloadingProgressChanged += (s, a) =>
|
||||
// Set cancellation token to throw exception on request
|
||||
CancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
|
||||
// Start stopwatch
|
||||
Stopwatch taskStopwatch = Stopwatch.StartNew();
|
||||
|
||||
// Set progress event handlers
|
||||
VideoService.DownloadingStarted += (s, a) =>
|
||||
{
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateDownloadingIcon"];
|
||||
HomeVideoPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextDownloading")} (0%)";
|
||||
HomeVideoPanelStateProgressBar.IsIndeterminate = false;
|
||||
HomeVideoPanelStateProgressBar.Value = 0;
|
||||
};
|
||||
VideoService.DownloadingProgressChanged += (s, a) =>
|
||||
{
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateDownloadingIcon"];
|
||||
HomeVideoPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextDownloading")} ({a.ProgressPercentage}%)";
|
||||
HomeVideoPanelStateProgressBar.Value = a.ProgressPercentage;
|
||||
};
|
||||
VideoService.ProcessingStarted += (s, a) =>
|
||||
{
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateProcessingIcon"];
|
||||
HomeVideoPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextProcessing")} (0%)";
|
||||
HomeVideoPanelStateProgressBar.Value = 0;
|
||||
};
|
||||
VideoService.ProcessingProgressChanged += (s, a) =>
|
||||
{
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateProcessingIcon"];
|
||||
HomeVideoPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextProcessing")} ({a.ProgressPercentage}%)";
|
||||
HomeVideoPanelStateProgressBar.Value = a.ProgressPercentage;
|
||||
};
|
||||
|
||||
// Request extended session
|
||||
ExtendedExecutionSession session = new ExtendedExecutionSession { Reason = ExtendedExecutionReason.Unspecified };
|
||||
await session.RequestExtensionAsync();
|
||||
|
||||
// Start task
|
||||
StorageFile tempOutputFile = await VideoService.DownloadAndTranscodeAsync(tempFolder, Stream, Extension, MediaType, CancellationTokenSource.Token);
|
||||
|
||||
// Dispose session
|
||||
session.Dispose();
|
||||
|
||||
// Cancel if requested
|
||||
CancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
|
||||
// Set state controls
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateFinalizingIcon"];
|
||||
HomeVideoPanelStateText.Text = ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextFinalizing");
|
||||
HomeVideoPanelStateProgressBar.IsIndeterminate = true;
|
||||
|
||||
// Move to output location
|
||||
StorageFile outputFile;
|
||||
Debug.WriteLine($"{Filename}.{Extension.ToString().ToLower()}");
|
||||
if (Location != null) outputFile = await Location.CreateFileAsync($"{Filename}.{Extension.ToString().ToLower()}", (bool)Config.GetValue("replace_output_file_if_exists") ? CreationCollisionOption.ReplaceExisting : CreationCollisionOption.GenerateUniqueName);
|
||||
else outputFile = await DownloadsFolder.CreateFileAsync($"{Filename}.{Extension.ToString().ToLower()}", (bool)Config.GetValue("replace_output_file_if_exists") ? CreationCollisionOption.ReplaceExisting : CreationCollisionOption.GenerateUniqueName);
|
||||
await tempOutputFile.MoveAndReplaceAsync(outputFile);
|
||||
|
||||
// Stop stopwatch
|
||||
taskStopwatch.Stop();
|
||||
|
||||
// Set state controls
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateDoneIcon"];
|
||||
HomeVideoPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextDone")} ({(Math.Floor(taskStopwatch.Elapsed.TotalHours) > 0 ? $"{ Math.Floor(taskStopwatch.Elapsed.TotalHours):0}:" : "")}{taskStopwatch.Elapsed.Minutes:00}:{taskStopwatch.Elapsed.Seconds:00})";
|
||||
HomeVideoPanelStateProgressBar.Visibility = Visibility.Collapsed;
|
||||
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateDownloadingIcon"];
|
||||
HomeVideoPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextDownloading")} ({a.ProgressPercentage}%)";
|
||||
HomeVideoPanelStateProgressBar.Value = a.ProgressPercentage;
|
||||
};
|
||||
VideoService.ProcessingStarted += (s, a) =>
|
||||
// Set state controls
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateCancelledIcon"];
|
||||
HomeVideoPanelStateText.Text = ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextCancelled");
|
||||
HomeVideoPanelStateProgressBar.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
finally
|
||||
{
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateProcessingIcon"];
|
||||
HomeVideoPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextProcessing")} (0%)";
|
||||
HomeVideoPanelStateProgressBar.Value = 0;
|
||||
};
|
||||
VideoService.ProcessingProgressChanged += (s, a) =>
|
||||
{
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateProcessingIcon"];
|
||||
HomeVideoPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextProcessing")} ({a.ProgressPercentage}%)";
|
||||
HomeVideoPanelStateProgressBar.Value = a.ProgressPercentage;
|
||||
};
|
||||
// Change icon
|
||||
HomeVideoPanelStartStopButton.Icon = new SymbolIcon(Symbol.Download);
|
||||
|
||||
// Request extended session
|
||||
ExtendedExecutionSession session = new ExtendedExecutionSession { Reason = ExtendedExecutionReason.Unspecified };
|
||||
await session.RequestExtensionAsync();
|
||||
// Set video status
|
||||
VideoStatus = VideoStatus.Idle;
|
||||
|
||||
// Start task
|
||||
StorageFile tempOutputFile = await VideoService.DownloadAndTranscodeAsync(tempFolder, Stream, Extension, MediaType, CancellationTokenSource.Token);
|
||||
|
||||
// Dispose session
|
||||
session.Dispose();
|
||||
|
||||
// Cancel if requested
|
||||
CancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
|
||||
// Set state controls
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateFinalizingIcon"];
|
||||
HomeVideoPanelStateText.Text = ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextFinalizing");
|
||||
HomeVideoPanelStateProgressBar.IsIndeterminate = true;
|
||||
|
||||
// Move to output location
|
||||
StorageFile outputFile;
|
||||
if (Location != null) outputFile = await Location.CreateFileAsync($"{Filename}.{Extension.ToString().ToLower()}", (bool)Config.GetValue("replace_output_file_if_exists") ? CreationCollisionOption.ReplaceExisting : CreationCollisionOption.GenerateUniqueName);
|
||||
else outputFile = await DownloadsFolder.CreateFileAsync($"{Filename}.{Extension.ToString().ToLower()}", (bool)Config.GetValue("replace_output_file_if_exists") ? CreationCollisionOption.ReplaceExisting : CreationCollisionOption.GenerateUniqueName);
|
||||
await tempOutputFile.MoveAndReplaceAsync(outputFile);
|
||||
|
||||
// Stop stopwatch
|
||||
taskStopwatch.Stop();
|
||||
|
||||
// Set state controls
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateDoneIcon"];
|
||||
HomeVideoPanelStateText.Text = $"{ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextDone")} ({(Math.Floor(taskStopwatch.Elapsed.TotalHours) > 0 ? $"{ Math.Floor(taskStopwatch.Elapsed.TotalHours):0}:" : "")}{taskStopwatch.Elapsed.Minutes:00}:{taskStopwatch.Elapsed.Seconds:00})";
|
||||
HomeVideoPanelStateProgressBar.Visibility = Visibility.Collapsed;
|
||||
// Delete temporary files
|
||||
await tempFolder.DeleteAsync();
|
||||
|
||||
// Dispose unique id
|
||||
TaskId.Dispose(uniqueID);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
else
|
||||
{
|
||||
// Set state controls
|
||||
HomeVideoPanelStateIcon.Source = (SvgImageSource)IconsRes["StateCancelledIcon"];
|
||||
HomeVideoPanelStateText.Text = ResourceLoader.GetForCurrentView().GetString("HomeVideoPanelStateTextCancelled");
|
||||
HomeVideoPanelStateProgressBar.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
// Change icon
|
||||
HomeVideoPanelStartStopButton.Icon = new SymbolIcon(Symbol.Download);
|
||||
|
||||
// Set video status
|
||||
VideoStatus = VideoStatus.Idle;
|
||||
|
||||
// Delete temporary files
|
||||
await tempFolder.DeleteAsync();
|
||||
|
||||
// Dispose unique id
|
||||
HomeVideosList.DisposeUniqueID(uniqueID);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,58 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Core.Services;
|
||||
|
||||
namespace VDownload.Views.Home
|
||||
{
|
||||
public class HomeVideosList
|
||||
{
|
||||
// VIDEO OBJECTS LIST
|
||||
public static List<HomeVideoPanel> VideoList = new List<HomeVideoPanel>();
|
||||
|
||||
// WAIT IN QUEUE
|
||||
public static async Task WaitInQueue(CancellationToken token)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
while (!(VideoList.Where(video => video.VideoStatus == Core.Enums.VideoStatus.InProgress).Count() < (int)Config.GetValue("max_active_video_task")) && !token.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(50);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#region GET UNIQUE ID
|
||||
|
||||
// VARIABLES
|
||||
private static readonly Random Random = new Random();
|
||||
private static readonly char[] CharsID = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
|
||||
private static readonly int LengthID = 10;
|
||||
private static readonly List<string> UsedIDs = new List<string>();
|
||||
|
||||
// METHOD
|
||||
public static string GetUniqueID()
|
||||
{
|
||||
string id;
|
||||
do
|
||||
{
|
||||
id = "";
|
||||
while (id.Length < LengthID)
|
||||
{
|
||||
id += CharsID[Random.Next(0, CharsID.Length)];
|
||||
}
|
||||
} while (UsedIDs.Contains(id));
|
||||
UsedIDs.Add(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
public static void DisposeUniqueID(string id)
|
||||
{
|
||||
UsedIDs.Remove(id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user