Archived
1
0

Video playback fixes

Merged to YouTubeExplode instead of MyToolkit
This commit is contained in:
Michael Gordeev
2018-10-21 00:49:34 +03:00
parent 067e1456b4
commit 3bca3a30be
14 changed files with 185 additions and 257 deletions
+49 -50
View File
@@ -1,73 +1,72 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.IO; using System.IO;
using MyToolkit.Multimedia;
using Windows.Storage; using Windows.Storage;
using FoxTube.Classes;
using Newtonsoft.Json;
using Windows.UI.Popups;
namespace FoxTube.Controls namespace FoxTube.Controls
{ {
public class DownloadAgent public class DownloadAgent
{ {
public List<DownloadItem> Items = new List<DownloadItem>(); public List<DownloadItem> items = new List<DownloadItem>();
public event ObjectEventHandler ListChanged; StorageFolder roaming = ApplicationData.Current.RoamingFolder;
private ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
XmlDocument doc = new XmlDocument();
public DownloadAgent() public DownloadAgent()
{ {
if (settings.Values["downloadHistory"] != null) Initialize();
doc.LoadXml(settings.Values["downloadHistory"] as string); Windows.UI.Core.Preview.SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += (s, a) => QuitPrompt();
else }
public async void Initialize()
{
try
{ {
doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); List<DownloadItemContainer> containers = JsonConvert.DeserializeObject<List<DownloadItemContainer>>(await FileIO.ReadTextAsync(await roaming.GetFileAsync("data.json")));
doc.AppendChild(doc.CreateElement("downloads"));
settings.Values.Add("downloadHistory", doc.InnerXml); foreach (DownloadItemContainer i in containers)
try { items.Add(new DownloadItem(i)); }
catch (FileNotFoundException) { }
} }
catch { }
foreach(XmlElement e in doc["downloads"].ChildNodes)
try
{
Items.Add(new DownloadItem(
e["details"]["id"].InnerText,
e["title"].InnerText,
e["snippet"]["author"].InnerText,
e["snippet"]["image"].InnerText,
e["snippet"]["duration"].InnerText,
e["snippet"]["quality"].InnerText,
e["details"]["path"].InnerText));
}
catch { }
} }
public void Add(string id, YouTubeQuality quality) public void Add(string url)
{ {
DownloadItem item = new DownloadItem(id, quality); items.Add(new DownloadItem(url));
item.DownloadCanceled += Item_DownloadCanceled;
item.DownloadComplete += Item_DownloadComplete;
Items.Add(item);
ListChanged.Invoke(item, "add");
}
public void Add(string id, string url)
{
}
private void Item_DownloadComplete(object sender, params object[] e)
{
doc["downloads"].InnerXml += e[0];
settings.Values["downloadHistory"] = doc.InnerXml;
} }
private void Item_DownloadCanceled(object sender, params object[] e) private void Item_DownloadCanceled(object sender, params object[] e)
{ {
Items.Remove(sender as DownloadItem); items.Remove(sender as DownloadItem);
ListChanged.Invoke(sender, "remove"); }
public async void QuitPrompt()
{
if(items.Find(x => x.InProgress) != null)
{
MessageDialog dialog = new MessageDialog("You have some unfinished downloads. Quitting now will erase all downloaded data. Are you sure to continue?", "Some downloads are still pending");
dialog.Commands.Add(new UICommand("Yes", async (command) =>
{
foreach (DownloadItem i in items.FindAll(x => x.InProgress))
i.Cancel();
items.RemoveAll(x => x.InProgress);
List<DownloadItemContainer> containers = new List<DownloadItemContainer>();
foreach (DownloadItem i in items)
containers.Add(i.Container);
await FileIO.WriteTextAsync(
await roaming.CreateFileAsync("data.json", CreationCollisionOption.ReplaceExisting),
JsonConvert.SerializeObject(containers));
}));
dialog.Commands.Add(new UICommand("No"));
dialog.DefaultCommandIndex = 1;
await dialog.ShowAsync();
}
} }
} }
} }
+16
View File
@@ -0,0 +1,16 @@
using System;
using YoutubeExplode.Models.MediaStreams;
namespace FoxTube.Classes
{
public class DownloadItemContainer
{
public string Title { get; set; }
public string Channel { get; set; }
public string Id { get; set; }
public Uri Path { get; set; }
public Uri Thumbnail { get; set; }
public VideoQuality Quality { get; set; }
public TimeSpan Duration { get; set; }
}
}
+7 -6
View File
@@ -1,11 +1,7 @@
using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using MyToolkit.Multimedia;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web; using System.Web;
using Windows.ApplicationModel.Core; using Windows.ApplicationModel.Core;
using Windows.System; using Windows.System;
@@ -30,6 +26,11 @@ namespace FoxTube
CoreApplication.Exit(); CoreApplication.Exit();
} }
public static Uri ToUri(this string url)
{
return new Uri(url);
}
public static string GetAgo(DateTime dateTime) public static string GetAgo(DateTime dateTime)
{ {
TimeSpan span = DateTime.Now - dateTime; TimeSpan span = DateTime.Now - dateTime;
@@ -105,7 +106,7 @@ namespace FoxTube
} }
} }
public static string QualityToString(YouTubeQuality quality) /*public static string QualityToString(YouTubeQuality quality)
{ {
switch(quality) switch(quality)
{ {
@@ -138,7 +139,7 @@ namespace FoxTube
default: default:
return "Unknown"; return "Unknown";
} }
} }*/
public async static void ProcessLink(string url) public async static void ProcessLink(string url)
{ {
+1 -1
View File
@@ -28,7 +28,7 @@
<TextBlock Text="Author:" Foreground="Gray" Name="channel"/> <TextBlock Text="Author:" Foreground="Gray" Name="channel"/>
</StackPanel> </StackPanel>
<StackPanel Name="donePanel" Grid.Column="3" Orientation="Horizontal" Visibility="Collapsed"> <StackPanel Name="donePanel" Grid.Column="3" Orientation="Horizontal" Visibility="Visible">
<Button Name="open" Click="open_Click" Width="80" Height="80" Padding="0" Background="Transparent"> <Button Name="open" Click="open_Click" Width="80" Height="80" Padding="0" Background="Transparent">
<StackPanel> <StackPanel>
<TextBlock Text="&#xED25;" FontFamily="Segoe MDL2 Assets" FontSize="30" HorizontalAlignment="Center"/> <TextBlock Text="&#xED25;" FontFamily="Segoe MDL2 Assets" FontSize="30" HorizontalAlignment="Center"/>
+37 -84
View File
@@ -1,26 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Net; using System.Net;
using Windows.UI.Xaml.Media.Imaging; using Windows.UI.Xaml.Media.Imaging;
using Windows.System; using Windows.System;
using MyToolkit.Multimedia; using FoxTube.Classes;
using Windows.Storage; using YoutubeExplode.Models.MediaStreams;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Windows.UI.Popups;
using System.Xml;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
@@ -28,55 +14,36 @@ namespace FoxTube.Controls
{ {
public sealed partial class DownloadItem : UserControl public sealed partial class DownloadItem : UserControl
{ {
string uri; public DownloadItemContainer Container { get; private set; }
string Id; public bool InProgress { get; set; } = false;
public DownloadItem(string url)
{
this.InitializeComponent();
Download(url);
}
public event ObjectEventHandler DownloadCanceled; public DownloadItem(DownloadItemContainer container)
public event ObjectEventHandler DownloadComplete;
WebClient client = new WebClient();
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
public DownloadItem(string id, YouTubeQuality q)
{ {
this.InitializeComponent(); this.InitializeComponent();
client.DownloadFileCompleted += DownloadCompleted; Container = container;
client.DownloadProgressChanged += UpdateInfo; if (!File.Exists(container.Path.AbsolutePath))
throw new FileNotFoundException();
title.Text = Container.Title;
thumbnail.Source = new BitmapImage(Container.Thumbnail);
quality.Text = $"Quality: {Container.Quality.GetVideoQualityLabel()}";
duration.Text = $"Duration: {Container.Duration}";
channel.Text = $"Author: {Container.Channel}";
progressPanel.Visibility = Visibility.Collapsed;
donePanel.Visibility = Visibility.Visible;
} }
async void Download(string id, YouTubeQuality q) void Download(string url)
{ {
try
{
Id = id;
VideosResource.ListRequest request = SecretsVault.NoAuthService.Videos.List("snippet");
request.Id = id;
var response = (await request.ExecuteAsync()).Items[0];
Uri url = (await YouTube.GetVideoUriAsync(id, q)).Uri;
client.DownloadFileAsync(url, settings.Values["defaultDownload"] as string + $@"\{response.Snippet.Title} - {response.Snippet.ChannelTitle}.mp4");
thumbnail.Source = new BitmapImage(new Uri(response.Snippet.Thumbnails.Standard.Url));
title.Text = response.Snippet.Title;
channel.Text = $"Author: {response.Snippet.ChannelTitle}";
quality.Text = $"Quality: {Methods.QualityToString(q)}"; TimeSpan ts = XmlConvert.ToTimeSpan(response.ContentDetails.Duration);
duration.Text = string.Format("Duration: {0}{1:00}:{2:00} | ", ts.Hours == 0 ? "" : ts.Hours + ":", ts.Minutes, ts.Seconds);
uri = settings.Values["defaultDownload"] as string + $@"\{response.Snippet.Title} - {response.Snippet.ChannelTitle}.mp4";
status.Text = "Downloading...";
perc.Text = "0%";
}
catch
{
if (client.IsBusy)
client.CancelAsync();
await new MessageDialog("We were unable to download video due to connection problems or internal YouTube server error. Please, try again later.", "Failed to download").ShowAsync();
throw new FileNotFoundException();
}
} }
private void UpdateInfo(object sender, DownloadProgressChangedEventArgs e) private void UpdateInfo(object sender, DownloadProgressChangedEventArgs e)
@@ -87,7 +54,7 @@ namespace FoxTube.Controls
private void DownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) private void DownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{ {
progressPanel.Visibility = Visibility.Collapsed; /*progressPanel.Visibility = Visibility.Collapsed;
donePanel.Visibility = Visibility.Visible; donePanel.Visibility = Visibility.Visible;
string node = $@"<item> string node = $@"<item>
@@ -103,41 +70,27 @@ namespace FoxTube.Controls
</details> </details>
</item>"; </item>";
DownloadComplete.Invoke(this, node); DownloadComplete.Invoke(this, node);*/
}
public DownloadItem(string videoId, string videoName, string channelName, string thumbUrl, string length, string videoQuality, string path)
{
if (!File.Exists(path))
throw new FileNotFoundException();
title.Text = videoName;
thumbnail.Source = new BitmapImage(new Uri(thumbUrl));
quality.Text = $"Quality: {videoQuality}";
duration.Text = $"Duration: {length}";
channel.Text = $"Author: {channelName}";
progressPanel.Visibility = Visibility.Collapsed;
donePanel.Visibility = Visibility.Visible;
uri = path;
Id = videoId;
} }
private async void open_Click(object sender, RoutedEventArgs e) private async void open_Click(object sender, RoutedEventArgs e)
{ {
if (!string.IsNullOrWhiteSpace(uri)) await Launcher.LaunchUriAsync(Container.Path);
await Launcher.LaunchUriAsync(new Uri(uri));
} }
private void gotoOriginal_Click(object sender, RoutedEventArgs e) private void gotoOriginal_Click(object sender, RoutedEventArgs e)
{ {
Methods.MainPage.GoToVideo(Id); Methods.MainPage.GoToVideo(Container.Id);
} }
private async void cancel_Click(object sender, RoutedEventArgs e) public void Cancel()
{ {
if(client.IsBusy)
}
private void cancel_Click(object sender, RoutedEventArgs e)
{
/*if(client.IsBusy)
{ {
MessageDialog dialog = new MessageDialog("Are you sure?", "Cancelling download"); MessageDialog dialog = new MessageDialog("Are you sure?", "Cancelling download");
@@ -153,7 +106,7 @@ namespace FoxTube.Controls
dialog.DefaultCommandIndex = 1; dialog.DefaultCommandIndex = 1;
await dialog.ShowAsync(); await dialog.ShowAsync();
} }*/
} }
} }
} }
+1 -10
View File
@@ -123,16 +123,7 @@
<Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE713;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Video quality"> <Button Background="Transparent" FontFamily="Segoe MDL2 Assets" Content="&#xE713;" Foreground="White" Width="50" Height="50" FontSize="25" ToolTipService.ToolTip="Video quality">
<Button.Flyout> <Button.Flyout>
<Flyout> <Flyout>
<ComboBox Width="225" Header="Quality" Name="quality" SelectionChanged="quality_SelectionChanged"> <ComboBox Width="225" Header="Quality" Name="quality" SelectionChanged="quality_SelectionChanged"/>
<!--<ComboBoxItem Content="Auto"/>-->
<ComboBoxItem Content="2160P" Visibility="Collapsed"/>
<ComboBoxItem Content="1080p" Visibility="Collapsed"/>
<ComboBoxItem Content="720p" Visibility="Collapsed"/>
<ComboBoxItem Content="480p" Visibility="Collapsed"/>
<ComboBoxItem Content="360p" Visibility="Collapsed"/>
<ComboBoxItem Content="240p" Visibility="Collapsed"/>
<ComboBoxItem Content="144p" Visibility="Collapsed"/>
</ComboBox>
</Flyout> </Flyout>
</Button.Flyout> </Button.Flyout>
</Button> </Button>
+37 -43
View File
@@ -1,26 +1,17 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Timers; using System.Timers;
using Windows.Foundation; using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage; using Windows.Storage;
using Windows.UI.Core; using Windows.UI.Core;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Microsoft.Toolkit.Uwp.UI.Animations;
using Google.Apis.YouTube.v3.Data; using Google.Apis.YouTube.v3.Data;
using Google.Apis.YouTube.v3;
using Windows.UI.Xaml.Media.Imaging; using Windows.UI.Xaml.Media.Imaging;
using Windows.Networking.Connectivity;
using System.Diagnostics; using System.Diagnostics;
using Windows.Media; using Windows.Media;
using Windows.Storage.Streams; using Windows.Storage.Streams;
@@ -28,17 +19,13 @@ using Windows.UI.ViewManagement;
using System.Xml; using System.Xml;
using Windows.ApplicationModel.Core; using Windows.ApplicationModel.Core;
using Windows.UI; using Windows.UI;
using Windows.Graphics.Display;
using Windows.Media.Casting; using Windows.Media.Casting;
using MyToolkit.Multimedia;
using YoutubeExplode.Models.MediaStreams; using YoutubeExplode.Models.MediaStreams;
using YoutubeExplode; using YoutubeExplode;
using YoutubeExplode.Models.ClosedCaptions; using YoutubeExplode.Models.ClosedCaptions;
using System.Globalization; using System.Globalization;
using FoxTube.Controls; using FoxTube.Controls;
using Windows.System; using Windows.System;
using Windows.Devices.Sensors;
using Windows.System.Profile;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
@@ -87,7 +74,7 @@ namespace FoxTube
LiveCaptions captions; LiveCaptions captions;
IReadOnlyList<ClosedCaptionTrackInfo> ccInfo; IReadOnlyList<ClosedCaptionTrackInfo> ccInfo;
List<YouTubeUri> streamInfo; MediaStreamInfoSet streamInfo;
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
Timer t = new Timer() Timer t = new Timer()
@@ -132,35 +119,25 @@ namespace FoxTube
#region Retrieving info for CC and Media streams #region Retrieving info for CC and Media streams
//Loading streams //Loading streams
streamInfo = (await YouTube.GetUrisAsync(item.Id)).ToList(); streamInfo = await new YoutubeClient().GetVideoMediaStreamInfosAsync(videoId);
foreach (YouTubeQuality q in Enum.GetValues(typeof(YouTubeQuality))) streamInfo.Audio.ToList().ForEach(x => Debug.WriteLine($"{x.AudioEncoding} {x.Bitrate}"));
if (streamInfo.FindAll(x => x.VideoQuality == q).Count > 1)
streamInfo.RemoveAll(x => x.VideoQuality == q && !x.HasAudio);
streamInfo.ForEach(x => Debug.WriteLine($"{x.HasAudio}; {x.HasVideo}; {x.VideoQuality}; {x.AudioQuality}")); List<VideoQuality> q = streamInfo.GetAllVideoQualities().ToList();
foreach (YouTubeUri i in streamInfo) q.Sort();
{ q.Reverse();
if (i.VideoQuality == YouTubeQuality.Quality2160P) foreach (VideoQuality i in q)
(quality.Items[0] as ComboBoxItem).Visibility = Visibility.Visible; quality.Items.Add(new ComboBoxItem() { Content = i.GetVideoQualityLabel() });
if (i.VideoQuality == YouTubeQuality.Quality1080P)
(quality.Items[1] as ComboBoxItem).Visibility = Visibility.Visible;
if (i.VideoQuality == YouTubeQuality.Quality720P)
(quality.Items[2] as ComboBoxItem).Visibility = Visibility.Visible;
if (i.VideoQuality == YouTubeQuality.Quality480P)
(quality.Items[3] as ComboBoxItem).Visibility = Visibility.Visible;
if (i.VideoQuality == YouTubeQuality.Quality360P)
(quality.Items[4] as ComboBoxItem).Visibility = Visibility.Visible;
if (i.VideoQuality == YouTubeQuality.Quality240P)
(quality.Items[5] as ComboBoxItem).Visibility = Visibility.Visible;
if (i.VideoQuality == YouTubeQuality.Quality144P)
(quality.Items[6] as ComboBoxItem).Visibility = Visibility.Visible;
}
int k = (int)settings.Values["quality"]; string s;
if ((quality.Items[k] as ComboBoxItem).Visibility == Visibility.Visible) if ((string)settings.Values["quality"] == "remember")
quality.SelectedIndex = k; s = (string)settings.Values["rememberedQuality"];
else else
quality.SelectedItem = quality.Items.First(x => (x as ComboBoxItem).Visibility == Visibility.Visible); s = (string)settings.Values["quality"];
if (quality.Items.ToList().Find(x => (x as ComboBoxItem).Content as string == s) != null)
quality.SelectedItem = quality.Items.First(x => (x as ComboBoxItem).Content as string == s);
else
quality.SelectedItem = quality.Items.First();
//Loading captions //Loading captions
ccInfo = await new YoutubeClient().GetVideoClosedCaptionTrackInfosAsync(item.Id); ccInfo = await new YoutubeClient().GetVideoClosedCaptionTrackInfosAsync(item.Id);
@@ -369,11 +346,28 @@ namespace FoxTube
audioReady = false; audioReady = false;
videoReady = false; videoReady = false;
switch((quality.SelectedItem as ComboBoxItem).Content) settings.Values["rememberedQuality"] = (quality.SelectedItem as ComboBoxItem).Content as string;
if(streamInfo.Muxed.ToList().Find(x => x.VideoQualityLabel == (quality.SelectedItem as ComboBoxItem).Content as string) != null)
{
isMuxed = true;
videoSource.Source = streamInfo.Muxed.First(x => x.VideoQualityLabel == (quality.SelectedItem as ComboBoxItem).Content as string).Url.ToUri();
}
else
{
isMuxed = false;
videoSource.Source = streamInfo.Video.First(x => x.VideoQualityLabel == (quality.SelectedItem as ComboBoxItem).Content as string).Url.ToUri();
audioSource.Source = streamInfo.Audio.First().Url.ToUri();
}
/*switch((quality.SelectedItem as ComboBoxItem).Content)
{ {
case "2160p": case "2160p":
if(streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality2160P).HasAudio) if(streamInfo.Muxed.First(x => x.VideoQuality.))
{
isMuxed = true; isMuxed = true;
}
else else
{ {
isMuxed = false; isMuxed = false;
@@ -456,7 +450,7 @@ namespace FoxTube
} }
videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality144P).Uri; videoSource.Source = streamInfo.First(x => x.VideoQuality == YouTubeQuality.Quality144P).Uri;
break; break;
} }*/
needUpdateTimecode = true; needUpdateTimecode = true;
videoSource.Play(); videoSource.Play();
+13 -12
View File
@@ -97,6 +97,7 @@
<DependentUpon>App.xaml</DependentUpon> <DependentUpon>App.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Classes\Caption.cs" /> <Compile Include="Classes\Caption.cs" />
<Compile Include="Classes\DownloadItemContainer.cs" />
<Compile Include="Classes\InboxItem.cs" /> <Compile Include="Classes\InboxItem.cs" />
<Compile Include="Classes\Methods.cs" /> <Compile Include="Classes\Methods.cs" />
<Compile Include="Classes\ObjectEventArgs.cs" /> <Compile Include="Classes\ObjectEventArgs.cs" />
@@ -398,7 +399,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AdaptiveCards.Rendering.Uwp"> <PackageReference Include="AdaptiveCards.Rendering.Uwp">
<Version>1.0.1</Version> <Version>1.1.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Google.Apis"> <PackageReference Include="Google.Apis">
<Version>1.30.0-beta02</Version> <Version>1.30.0-beta02</Version>
@@ -419,25 +420,25 @@
<Version>10.1805.7001</Version> <Version>10.1805.7001</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform"> <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.1.5</Version> <Version>6.1.9</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications"> <PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
<Version>3.0.0</Version> <Version>4.0.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls"> <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
<Version>3.0.0</Version> <Version>4.0.0</Version>
</PackageReference>
<PackageReference Include="MyToolkit">
<Version>2.5.16</Version>
</PackageReference>
<PackageReference Include="MyToolkit.Extended">
<Version>2.5.16</Version>
</PackageReference> </PackageReference>
<PackageReference Include="runtime.win10-arm64.runtime.native.System.IO.Compression"> <PackageReference Include="runtime.win10-arm64.runtime.native.System.IO.Compression">
<Version>4.3.1</Version> <Version>4.3.2</Version>
</PackageReference>
<PackageReference Include="Syroot.Windows.IO.KnownFolders">
<Version>1.2.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="YoutubeExplode"> <PackageReference Include="YoutubeExplode">
<Version>4.3.1</Version> <Version>4.4.0</Version>
</PackageReference>
<PackageReference Include="YoutubeExtractor">
<Version>0.10.11</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+4 -1
View File
@@ -5,6 +5,7 @@
xmlns:local="using:FoxTube.Pages" xmlns:local="using:FoxTube.Pages"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:FoxTube.Controls"
mc:Ignorable="d" mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
@@ -27,7 +28,9 @@
</Grid> </Grid>
</StackPanel> </StackPanel>
<ScrollViewer Grid.Row="1"> <ScrollViewer Grid.Row="1">
<StackPanel Margin="5" Name="stack"/> <StackPanel Margin="5" Name="stack">
<ListView ItemsSource="{Binding Path=Methods.MainPage.agent.items}" SelectionMode="None"/>
</StackPanel>
</ScrollViewer> </ScrollViewer>
</Grid> </Grid>
</Page> </Page>
+3 -21
View File
@@ -11,11 +11,6 @@ using Windows.Storage.Pickers;
using Windows.System; using Windows.System;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
#pragma warning disable CS0252 // Possible unintended reference comparison; left hand side needs cast #pragma warning disable CS0252 // Possible unintended reference comparison; left hand side needs cast
@@ -28,33 +23,20 @@ namespace FoxTube.Pages
public sealed partial class Downloads : Page public sealed partial class Downloads : Page
{ {
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
DownloadAgent agent = Methods.MainPage.Agent;
public Downloads() public Downloads()
{ {
this.InitializeComponent(); this.InitializeComponent();
path.Text = settings.Values["defaultDownload"] as string; path.Text = settings.Values["defaultDownload"] as string;
agent.ListChanged += UpdateList;
foreach (DownloadItem item in agent.Items)
stack.Children.Add(item);
}
private void UpdateList(object sender, params object[] e)
{
if (e[0] == "remove")
stack.Children.Remove(sender as DownloadItem);
else if (e[0] == "add")
stack.Children.Add(sender as DownloadItem);
} }
private async void changePath_Click(object sender, RoutedEventArgs e) private async void changePath_Click(object sender, RoutedEventArgs e)
{ {
FolderPicker picker = new FolderPicker() FolderPicker picker = new FolderPicker()
{ {
SuggestedStartLocation = PickerLocationId.Desktop, SuggestedStartLocation = PickerLocationId.Downloads,
ViewMode = PickerViewMode.Thumbnail ViewMode = PickerViewMode.Thumbnail
}; };
picker.FileTypeFilter.Add(".shit"); //Because overwise it trhows an exception
StorageFolder p = await picker.PickSingleFolderAsync(); StorageFolder p = await picker.PickSingleFolderAsync();
if (p != null) if (p != null)
@@ -64,7 +46,7 @@ namespace FoxTube.Pages
private async void openFolder_Click(object sender, RoutedEventArgs e) private async void openFolder_Click(object sender, RoutedEventArgs e)
{ {
await Launcher.LaunchUriAsync(new Uri(settings.Values["defaultDownload"] as string)); await Launcher.LaunchFolderAsync( await StorageFolder.GetFolderFromPathAsync(settings.Values["defaultDownload"] as string));
} }
} }
} }
+5 -2
View File
@@ -24,6 +24,7 @@ using System.Net;
using Windows.UI.Popups; using Windows.UI.Popups;
using Windows.Networking.Connectivity; using Windows.Networking.Connectivity;
using Windows.UI.Core; using Windows.UI.Core;
using Syroot.Windows.IO;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
@@ -48,7 +49,9 @@ namespace FoxTube
this.InitializeComponent(); this.InitializeComponent();
if (settings.Values["quality"] == null) if (settings.Values["quality"] == null)
settings.Values.Add("quality", 1); settings.Values.Add("quality", "remember");
if (settings.Values["rememberedQuality"] == null)
settings.Values.Add("rememberedQuality", "1080p");
if (settings.Values["newVideoNotification"] == null) if (settings.Values["newVideoNotification"] == null)
settings.Values.Add("newVideoNotification", true); settings.Values.Add("newVideoNotification", true);
@@ -70,7 +73,7 @@ namespace FoxTube
settings.Values.Add("safeSearch", 0); settings.Values.Add("safeSearch", 0);
if (settings.Values["defaultDownload"] == null) if (settings.Values["defaultDownload"] == null)
settings.Values.Add("defaultDownload", Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\DownloadedVideos"); settings.Values.Add("defaultDownload", Syroot.Windows.IO.KnownFolders.Downloads.Path + "\\DownloadedVideos");
if (settings.Values["notificationsHistory"] == null) if (settings.Values["notificationsHistory"] == null)
{ {
+8 -8
View File
@@ -28,14 +28,14 @@
<TextBlock x:Uid="/General/playback" Text="Playback" FontSize="22"/> <TextBlock x:Uid="/General/playback" Text="Playback" FontSize="22"/>
<ComboBox x:Uid="/General/quality" Width="250" Header="Default video playback quality" Name="quality" SelectionChanged="quality_SelectionChanged"> <ComboBox x:Uid="/General/quality" Width="250" Header="Default video playback quality" Name="quality" SelectionChanged="quality_SelectionChanged">
<ComboBoxItem x:Uid="/General/remember" Content="Remember my choice"/> <ComboBoxItem Tag="remember" x:Uid="/General/remember" Content="Remember my choice"/>
<ComboBoxItem Content="2160p"/> <ComboBoxItem Tag="2160p" Content="2160p"/>
<ComboBoxItem Content="1080p"/> <ComboBoxItem Tag="1080p" Content="1080p"/>
<ComboBoxItem Content="720p"/> <ComboBoxItem Tag="720p" Content="720p"/>
<ComboBoxItem Content="480p"/> <ComboBoxItem Tag="480p" Content="480p"/>
<ComboBoxItem Content="360p"/> <ComboBoxItem Tag="360p" Content="360p"/>
<ComboBoxItem Content="240p"/> <ComboBoxItem Tag="240p" Content="240p"/>
<ComboBoxItem Content="144p"/> <ComboBoxItem Tag="144p" Content="144p"/>
</ComboBox> </ComboBox>
<ToggleSwitch x:Uid="/General/metered" OnContent="Notify when playing on metered connection" OffContent="Notify when playing on metered connection" Name="mobileWarning" Toggled="mobileWarning_Toggled"/> <ToggleSwitch x:Uid="/General/metered" OnContent="Notify when playing on metered connection" OffContent="Notify when playing on metered connection" Name="mobileWarning" Toggled="mobileWarning_Toggled"/>
<ToggleSwitch x:Uid="/General/autoplay" OnContent="Play videos automatically" OffContent="Play videos automatically" Name="autoplay" Toggled="autoplay_Toggled"/> <ToggleSwitch x:Uid="/General/autoplay" OnContent="Play videos automatically" OffContent="Play videos automatically" Name="autoplay" Toggled="autoplay_Toggled"/>
+1 -1
View File
@@ -76,7 +76,7 @@ namespace FoxTube.Pages.SettingsPages
private void quality_SelectionChanged(object sender, SelectionChangedEventArgs e) private void quality_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
settings.Values["quality"] = quality.SelectedIndex; settings.Values["quality"] = (quality.SelectedItem as ComboBoxItem).Tag as string;
} }
private void mobileWarning_Toggled(object sender, RoutedEventArgs e) private void mobileWarning_Toggled(object sender, RoutedEventArgs e)
+3 -18
View File
@@ -1,36 +1,21 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation; using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation; using Windows.UI.Xaml.Navigation;
using Windows.System; using Windows.System;
using Google.Apis.YouTube.v3.Data; using Google.Apis.YouTube.v3.Data;
using Google.Apis.YouTube.v3; using Google.Apis.YouTube.v3;
using Windows.UI.Xaml.Media.Imaging; using Windows.UI.Xaml.Media.Imaging;
using System.Diagnostics; using System.Diagnostics;
using System.Timers;
using Windows.UI.Core;
using System.Threading;
using Windows.ApplicationModel.DataTransfer; using Windows.ApplicationModel.DataTransfer;
using Windows.Storage; using Windows.Storage;
using Windows.ApplicationModel; using Windows.ApplicationModel;
using Windows.Storage.Streams; using Windows.Storage.Streams;
using Windows.UI.Popups;
using Windows.UI.Text;
using Windows.UI; using Windows.UI;
using FoxTube.Pages;
using MyToolkit.Multimedia;
using FoxTube.Controls; using FoxTube.Controls;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
@@ -250,7 +235,7 @@ namespace FoxTube.Pages
async void LoadDownloads() async void LoadDownloads()
{ {
List<YouTubeUri> uris = (await YouTube.GetUrisAsync(item.Id)).ToList(); /*List<YouTubeUri> uris = (await YouTube.GetUrisAsync(item.Id)).ToList();
if (uris.Count > 0) if (uris.Count > 0)
foreach (YouTubeUri u in uris) foreach (YouTubeUri u in uris)
{ {
@@ -276,12 +261,12 @@ namespace FoxTube.Pages
} }
} }
else else
download.Visibility = Visibility.Collapsed; download.Visibility = Visibility.Collapsed;*/
} }
private void downloadItemSelected(object sender, RoutedEventArgs e) private void downloadItemSelected(object sender, RoutedEventArgs e)
{ {
Methods.MainPage.Agent.Add(videoId, (sender as MenuFlyoutItem).Tag.ToString()); Methods.MainPage.Agent.Add((sender as MenuFlyoutItem).Tag.ToString());
} }
async void LoadRelatedVideos() async void LoadRelatedVideos()