#224: Fixed
This commit is contained in:
+1
-10
@@ -1,6 +1,4 @@
|
|||||||
using Google.Apis.YouTube.v3;
|
using Google.Apis.YouTube.v3.Data;
|
||||||
using Google.Apis.YouTube.v3.Data;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -9,13 +7,11 @@ using System.Linq;
|
|||||||
using Windows.ApplicationModel;
|
using Windows.ApplicationModel;
|
||||||
using Windows.ApplicationModel.Activation;
|
using Windows.ApplicationModel.Activation;
|
||||||
using Windows.ApplicationModel.Background;
|
using Windows.ApplicationModel.Background;
|
||||||
using Windows.ApplicationModel.Core;
|
|
||||||
using Windows.Globalization;
|
using Windows.Globalization;
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
using Windows.System;
|
using Windows.System;
|
||||||
using Windows.System.Power;
|
using Windows.System.Power;
|
||||||
using Windows.UI.Notifications;
|
using Windows.UI.Notifications;
|
||||||
using Windows.UI.Popups;
|
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
@@ -81,11 +77,6 @@ namespace FoxTube
|
|||||||
|
|
||||||
rootFrame.NavigationFailed += OnNavigationFailed;
|
rootFrame.NavigationFailed += OnNavigationFailed;
|
||||||
|
|
||||||
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
|
|
||||||
{
|
|
||||||
//TODO: Load state from previously suspended application
|
|
||||||
}
|
|
||||||
|
|
||||||
// Place the frame in the current Window
|
// Place the frame in the current Window
|
||||||
Window.Current.Content = rootFrame;
|
Window.Current.Content = rootFrame;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Name="progressPanel" Grid.Column="4" Margin="10">
|
<StackPanel Name="progressPanel" Grid.Column="4" Margin="10">
|
||||||
<TextBlock Name="status" Text="Initializing..." HorizontalAlignment="Left"/>
|
<TextBlock Name="status" Text="Downloading..." HorizontalAlignment="Left"/>
|
||||||
<ProgressBar Name="progressBar" Width="200" Maximum="1" IsIndeterminate="True" Foreground="Red"/>
|
<ProgressBar Name="progressBar" Width="200" Maximum="1" IsIndeterminate="True" Foreground="Red"/>
|
||||||
<TextBlock Name="perc" Text="--%"/>
|
<TextBlock Name="perc" Text="--%"/>
|
||||||
<Button Content="Cancel" Name="cancel" Click="CancelPrompt" HorizontalAlignment="Right"/>
|
<Button Content="Cancel" Name="cancel" Click="CancelPrompt" HorizontalAlignment="Right"/>
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ namespace FoxTube.Controls
|
|||||||
Progress<double> progress = new Progress<double>();
|
Progress<double> progress = new Progress<double>();
|
||||||
NotificationData data = new NotificationData();
|
NotificationData data = new NotificationData();
|
||||||
|
|
||||||
|
DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) };
|
||||||
|
double percentage;
|
||||||
|
|
||||||
public DownloadItem(MediaStreamInfo info, Video meta, string q)
|
public DownloadItem(MediaStreamInfo info, Video meta, string q)
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
@@ -71,13 +74,16 @@ namespace FoxTube.Controls
|
|||||||
donePanel.Visibility = Visibility.Visible;
|
donePanel.Visibility = Visibility.Visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task Download(MediaStreamInfo info, Video meta, string q)
|
async void Download(MediaStreamInfo info, Video meta, string q)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
InProgress = true;
|
InProgress = true;
|
||||||
Container = new DownloadItemContainer();
|
Container = new DownloadItemContainer();
|
||||||
|
|
||||||
token = cts.Token;
|
token = cts.Token;
|
||||||
progress.ProgressChanged += UpdateInfo;
|
progress.ProgressChanged += (s, e) => percentage = e;
|
||||||
|
timer.Tick += (s, e) => UpdateInfo(percentage);
|
||||||
|
|
||||||
file = await DownloadAgent.Downloads.CreateFileAsync($"{meta.Snippet.Title.ReplaceInvalidChars('_')}.{info.Container.GetFileExtension()}", CreationCollisionOption.GenerateUniqueName);
|
file = await DownloadAgent.Downloads.CreateFileAsync($"{meta.Snippet.Title.ReplaceInvalidChars('_')}.{info.Container.GetFileExtension()}", CreationCollisionOption.GenerateUniqueName);
|
||||||
Container.Name = file.Name;
|
Container.Name = file.Name;
|
||||||
@@ -137,6 +143,8 @@ namespace FoxTube.Controls
|
|||||||
progressPanel.Visibility = Visibility.Visible;
|
progressPanel.Visibility = Visibility.Visible;
|
||||||
donePanel.Visibility = Visibility.Collapsed;
|
donePanel.Visibility = Visibility.Collapsed;
|
||||||
|
|
||||||
|
timer.Start();
|
||||||
|
|
||||||
await client.DownloadMediaStreamAsync(info, await file.OpenStreamForWriteAsync(), progress, token);
|
await client.DownloadMediaStreamAsync(info, await file.OpenStreamForWriteAsync(), progress, token);
|
||||||
|
|
||||||
progressPanel.Visibility = Visibility.Collapsed;
|
progressPanel.Visibility = Visibility.Collapsed;
|
||||||
@@ -147,10 +155,11 @@ namespace FoxTube.Controls
|
|||||||
if (!cts.IsCancellationRequested)
|
if (!cts.IsCancellationRequested)
|
||||||
DownloadCompleted();
|
DownloadCompleted();
|
||||||
}
|
}
|
||||||
|
catch (TaskCanceledException) { }
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateInfo(object sender, double e)
|
private void UpdateInfo(double e)
|
||||||
{
|
{
|
||||||
status.Text = "Downloading";
|
|
||||||
progressBar.Value = e;
|
progressBar.Value = e;
|
||||||
perc.Text = $"{(int)e * 100}%";
|
perc.Text = $"{(int)e * 100}%";
|
||||||
|
|
||||||
|
|||||||
@@ -168,5 +168,13 @@
|
|||||||
<Button Name="signin" Click="signin_Click" Content="Sign in now" Foreground="White" Background="Gray" HorizontalAlignment="Right" Grid.Column="1" Margin="0,0,10,0"/>
|
<Button Name="signin" Click="signin_Click" Content="Sign in now" Foreground="White" Background="Gray" HorizontalAlignment="Right" Grid.Column="1" Margin="0,0,10,0"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid Background="#E5000000" Visibility="Collapsed">
|
||||||
|
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Name="errorPlate">
|
||||||
|
<TextBlock Text="Something went wrong..." HorizontalAlignment="Center" FontSize="20"/>
|
||||||
|
<TextBlock Text="Video ID: " HorizontalAlignment="Center" IsTextSelectionEnabled="True" FontSize="20"/>
|
||||||
|
<TextBlock Text="Error type: " HorizontalAlignment="Center" IsTextSelectionEnabled="True" FontSize="20"/>
|
||||||
|
<TextBlock Text="Message: " HorizontalAlignment="Center" IsTextSelectionEnabled="True" FontSize="20"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -112,6 +112,8 @@ namespace FoxTube
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async void Initialize(Video meta, string channelAvatar)
|
public async void Initialize(Video meta, string channelAvatar)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
item = meta;
|
item = meta;
|
||||||
avatar = channelAvatar;
|
avatar = channelAvatar;
|
||||||
@@ -209,6 +211,19 @@ namespace FoxTube
|
|||||||
|
|
||||||
Visibility = Visibility.Visible;
|
Visibility = Visibility.Visible;
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
RaiseError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RaiseError(Exception e)
|
||||||
|
{
|
||||||
|
((TextBlock)errorPlate.Children[1]).Text = $"Video ID: {videoId}";
|
||||||
|
((TextBlock)errorPlate.Children[2]).Text = $"Error type: {e.GetType()}";
|
||||||
|
((TextBlock)errorPlate.Children[3]).Text = $"Message: {e.Message}";
|
||||||
|
((Grid)errorPlate.Parent).Visibility = Visibility.Visible;
|
||||||
|
}
|
||||||
|
|
||||||
private async void SystemControls_Engaged(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args)
|
private async void SystemControls_Engaged(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -242,6 +242,8 @@ namespace FoxTube.Pages
|
|||||||
}
|
}
|
||||||
|
|
||||||
async void LoadDownloads()
|
async void LoadDownloads()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
MediaStreamInfoSet infoSet = await new YoutubeClient().GetVideoMediaStreamInfosAsync(videoId);
|
MediaStreamInfoSet infoSet = await new YoutubeClient().GetVideoMediaStreamInfosAsync(videoId);
|
||||||
foreach (MuxedStreamInfo i in infoSet.Muxed)
|
foreach (MuxedStreamInfo i in infoSet.Muxed)
|
||||||
@@ -263,6 +265,11 @@ namespace FoxTube.Pages
|
|||||||
audioItem.Click += downloadItemSelected;
|
audioItem.Click += downloadItemSelected;
|
||||||
downloadSelector.Items.Add(audioItem);
|
downloadSelector.Items.Add(audioItem);
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
loading.Error(e.GetType().ToString(), e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void downloadItemSelected(object sender, RoutedEventArgs e)
|
private void downloadItemSelected(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user