Archived
1
0
This commit is contained in:
Michael Gordeev
2018-12-16 00:04:08 +03:00
parent 0dd6513257
commit da99cca0c4
6 changed files with 198 additions and 168 deletions
+1 -10
View File
@@ -1,6 +1,4 @@
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Newtonsoft.Json;
using Google.Apis.YouTube.v3.Data;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -9,13 +7,11 @@ using System.Linq;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Background;
using Windows.ApplicationModel.Core;
using Windows.Globalization;
using Windows.Storage;
using Windows.System;
using Windows.System.Power;
using Windows.UI.Notifications;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
@@ -81,11 +77,6 @@ namespace FoxTube
rootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
+1 -1
View File
@@ -44,7 +44,7 @@
</Button>
</StackPanel>
<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"/>
<TextBlock Name="perc" Text="--%"/>
<Button Content="Cancel" Name="cancel" Click="CancelPrompt" HorizontalAlignment="Right"/>
+14 -5
View File
@@ -33,6 +33,9 @@ namespace FoxTube.Controls
Progress<double> progress = new Progress<double>();
NotificationData data = new NotificationData();
DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) };
double percentage;
public DownloadItem(MediaStreamInfo info, Video meta, string q)
{
this.InitializeComponent();
@@ -71,13 +74,16 @@ namespace FoxTube.Controls
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;
Container = new DownloadItemContainer();
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);
Container.Name = file.Name;
@@ -137,6 +143,8 @@ namespace FoxTube.Controls
progressPanel.Visibility = Visibility.Visible;
donePanel.Visibility = Visibility.Collapsed;
timer.Start();
await client.DownloadMediaStreamAsync(info, await file.OpenStreamForWriteAsync(), progress, token);
progressPanel.Visibility = Visibility.Collapsed;
@@ -144,13 +152,14 @@ namespace FoxTube.Controls
InProgress = false;
if(!cts.IsCancellationRequested)
if (!cts.IsCancellationRequested)
DownloadCompleted();
}
catch (TaskCanceledException) { }
}
private void UpdateInfo(object sender, double e)
private void UpdateInfo(double e)
{
status.Text = "Downloading";
progressBar.Value = e;
perc.Text = $"{(int)e * 100}%";
+8
View File
@@ -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"/>
</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>
</UserControl>
+18 -3
View File
@@ -112,6 +112,8 @@ namespace FoxTube
}
public async void Initialize(Video meta, string channelAvatar)
{
try
{
item = meta;
avatar = channelAvatar;
@@ -149,7 +151,7 @@ namespace FoxTube
Tag = cc
});
}
if(ccInfo.Count > 0)
if (ccInfo.Count > 0)
subsLang.SelectedIndex = 0;
else
captionsBtn.Visibility = Visibility.Collapsed;
@@ -157,14 +159,14 @@ namespace FoxTube
if (item.ContentDetails.ContentRating != null)
{
if(SecretsVault.IsAuthorized && settings.Values["showMature"] != null)
if (SecretsVault.IsAuthorized && settings.Values["showMature"] != null)
{
Visibility = Visibility.Visible;
proceedMature.Visibility = Visibility.Visible;
matureBlock.Visibility = Visibility.Visible;
return;
}
else if(!SecretsVault.IsAuthorized)
else if (!SecretsVault.IsAuthorized)
{
Visibility = Visibility.Visible;
signReq.Visibility = Visibility.Visible;
@@ -209,6 +211,19 @@ namespace FoxTube
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)
{
+8 -1
View File
@@ -242,9 +242,11 @@ namespace FoxTube.Pages
}
async void LoadDownloads()
{
try
{
MediaStreamInfoSet infoSet = await new YoutubeClient().GetVideoMediaStreamInfosAsync(videoId);
foreach(MuxedStreamInfo i in infoSet.Muxed)
foreach (MuxedStreamInfo i in infoSet.Muxed)
{
MenuFlyoutItem menuItem = new MenuFlyoutItem()
{
@@ -263,6 +265,11 @@ namespace FoxTube.Pages
audioItem.Click += downloadItemSelected;
downloadSelector.Items.Add(audioItem);
}
catch (Exception e)
{
loading.Error(e.GetType().ToString(), e.Message);
}
}
private void downloadItemSelected(object sender, RoutedEventArgs e)
{