diff --git a/FoxTube.Background/BackgroundProcessor.cs b/FoxTube.Background/BackgroundProcessor.cs new file mode 100644 index 0000000..152477a --- /dev/null +++ b/FoxTube.Background/BackgroundProcessor.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using Windows.ApplicationModel.Background; +using Windows.Storage; +using Windows.UI.Notifications; + +namespace FoxTube.Background +{ + public sealed class BackgroundProcessor : IBackgroundTask + { + public List Notifications = new List(); + + private DateTime lastCheck; + private ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; + + BackgroundTaskDeferral def; + public async void Run(IBackgroundTaskInstance taskInstance) + { + XmlDocument doc = new XmlDocument(); + def = taskInstance.GetDeferral(); + + if (settings.Values["notificationsHistory"] != null) + doc.LoadXml(settings.Values["notificationsHistory"] as string); + else + { + doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); + doc.AppendChild(doc.CreateElement("notifications")); + settings.Values.Add("notificationsHistory", doc.InnerXml); + } + + CheckAccount(); + + CheckAnnouncements(); + + def.Complete(); + } + + void CheckAccount() + { + + } + + void CheckAnnouncements() + { + XmlDocument doc = new XmlDocument(); + doc.Load(XmlReader.Create("http://foxgame.hol.es/ftp.xml")); + if ((XmlConvert.ToDateTime((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), XmlDateTimeSerializationMode.Utc) - DateTime.UtcNow).TotalSeconds > 0) + Notifications.Add(new Notification(NotificationType.Internal, + doc["posts"].FirstChild["notificationHeader"].InnerText, + doc["posts"].FirstChild["content"].InnerText, + XmlConvert.ToDateTime((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), + XmlDateTimeSerializationMode.Local), (doc["posts"].FirstChild as XmlElement).GetAttribute("image"))); + if ((bool)settings.Values["newmessagesNotification"] == true) + SendNotification(Notifications.Last()); + } + + void SendNotification(Notification notification) + { + ToastNotificationManager.CreateToastNotifier().Show(notification.GetToast(0)); + } + } +} diff --git a/FoxTube.Background/FoxTube.Background.csproj b/FoxTube.Background/FoxTube.Background.csproj new file mode 100644 index 0000000..1793119 --- /dev/null +++ b/FoxTube.Background/FoxTube.Background.csproj @@ -0,0 +1,136 @@ + + + + + Debug + AnyCPU + {FC9128D7-E3AA-48ED-8641-629794B88B28} + winmdobj + Properties + FoxTube.Background + FoxTube.Background + en-US + UAP + 10.0.17134.0 + 10.0.15063.0 + 14 + 512 + {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + false + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + prompt + 4 + + + x86 + true + bin\x86\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x86 + false + prompt + + + x86 + bin\x86\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x86 + false + prompt + + + ARM + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + ARM + false + prompt + + + ARM + bin\ARM\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + ARM + false + prompt + + + x64 + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x64 + false + prompt + + + x64 + bin\x64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x64 + false + prompt + + + PackageReference + + + + + + + + + + 6.1.5 + + + + + ..\..\..\..\..\..\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.netcore.universalwindowsplatform\6.1.5\ref\uap10.0.15138\System.Net.WebClient.dll + + + + 14.0 + + + + \ No newline at end of file diff --git a/FoxTube.Background/Notification.cs b/FoxTube.Background/Notification.cs new file mode 100644 index 0000000..eccc230 --- /dev/null +++ b/FoxTube.Background/Notification.cs @@ -0,0 +1,175 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.Data.Xml.Dom; +using Windows.UI; +using Windows.UI.Notifications; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Media.Imaging; + +namespace FoxTube.Background +{ + public enum NotificationType + { + Video, Comment, Post, Internal + } + + public class Notification + { + public string Channel { get; set; } + public string Content { get; set; } + public DateTime TimeStamp { get; set; } + public NotificationType Type { get; set; } + public string Avatar { get; set; } + public string Thumbnail { get; set; } + + public Notification(NotificationType type, + string channelName, string content, DateTime date, + string thumbnailUrl, string avatarUrl = "ms-appx:///Assets/Icons/Profile.png") + { + Channel = channelName; + Content = content; + TimeStamp = date; + Type = type; + Avatar = avatarUrl; + Thumbnail = thumbnailUrl; + } + + public UIElement GetNotification() + { + StackPanel stackPanel = new StackPanel() { Margin = new Thickness(10, 0, 0, 0) }; + + //Channel + switch (Type) + { + case NotificationType.Comment: + stackPanel.Children.Add(new TextBlock() + { + FontSize = 14, + FontStyle = Windows.UI.Text.FontStyle.Italic, + Foreground = new SolidColorBrush(Colors.Gray), + Text = string.Format("{0} replied to your comment", Channel) + }); + break; + + case NotificationType.Internal: + stackPanel.Children.Add(new TextBlock() + { + FontSize = 14, + FontStyle = Windows.UI.Text.FontStyle.Italic, + Foreground = new SolidColorBrush(Colors.Gray), + Text = Channel + }); + break; + + case NotificationType.Post: + stackPanel.Children.Add(new TextBlock() + { + FontSize = 14, + FontStyle = Windows.UI.Text.FontStyle.Italic, + Foreground = new SolidColorBrush(Colors.Gray), + Text = string.Format("{0} published new post", Channel) + }); + break; + + case NotificationType.Video: + stackPanel.Children.Add(new TextBlock() + { + FontSize = 14, + FontStyle = Windows.UI.Text.FontStyle.Italic, + Foreground = new SolidColorBrush(Colors.Gray), + Text = string.Format("{0} uploaded new video", Channel) + }); + break; + } + + //Content + stackPanel.Children.Add(new TextBlock() + { + TextWrapping = TextWrapping.WrapWholeWords, + Text = Content, + }); + //Time + stackPanel.Children.Add(new TextBlock() + { + FontSize = 13, + Foreground = new SolidColorBrush(Colors.Gray), + Text = TimeStamp.ToString() + }); + PersonPicture avatar = new PersonPicture() + { + Height = 50, + VerticalAlignment = VerticalAlignment.Top, + ProfilePicture = string.IsNullOrWhiteSpace(Avatar) ? null : new BitmapImage(new Uri(Avatar)) + }; + + Grid grid = new Grid(); + grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(50) }); + grid.ColumnDefinitions.Add(new ColumnDefinition()); + + grid.Children.Add(avatar); + Grid.SetColumn(stackPanel, 1); + grid.Children.Add(stackPanel); + + Button item = new Button() + { + HorizontalAlignment = HorizontalAlignment.Stretch, + HorizontalContentAlignment = HorizontalAlignment.Left, + Background = new SolidColorBrush(Colors.Transparent), + Content = grid + }; + + return item; + } + + public ToastNotification GetToast(int assignedId) + { + XmlDocument template = new XmlDocument(); + switch (Type) + { + case NotificationType.Comment: + template.LoadXml($@" + + + + {Channel} posted a new comment + {Content} + + + + + + + + + + + "); + break; + + case NotificationType.Video: + template.LoadXml($@" {Channel} uploaded a new video {Content} "); + break; + + case NotificationType.Internal: + string thumb1 = string.IsNullOrWhiteSpace(Thumbnail) ? "Assets/AnnouncementThumb.png" : Thumbnail; + template.LoadXml($@" {Channel} {Content} "); + break; + + case NotificationType.Post: + string thumb2 = string.IsNullOrWhiteSpace(Thumbnail) ? "" : $""; + template.LoadXml($@" {thumb2} {Channel} {Content} "); + break; + } + + return new ToastNotification(template); + } + } +} diff --git a/FoxTube.Background/Properties/AssemblyInfo.cs b/FoxTube.Background/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b4bdea3 --- /dev/null +++ b/FoxTube.Background/Properties/AssemblyInfo.cs @@ -0,0 +1,29 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FoxTube.Background")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FoxTube.Background")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/FoxTube.Background/ToastTemplates.cs b/FoxTube.Background/ToastTemplates.cs new file mode 100644 index 0000000..cf6483a --- /dev/null +++ b/FoxTube.Background/ToastTemplates.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FoxTube.Background +{ + public static class ToastTemplates + { + public static string Comment = + @" + + + + [ChannelName] posted a new comment + [VideoName] + + + + + + + + + + + + "; + public static string Video = + @" [ChannelName] uploaded a new video [VideoName] "; + public static string Post = + @" [ChannelName] [PostContent] "; + public static string Internal = + @" [Header] "; + public static string Download = + @" Downloading a video... [VideoName] "; + public static string DownloadComplete = + @" Download complete Subnautica - SAY GOODBYE TO SUBNAUTICA! We're Back Home! - Subnautica Ending (Full Release Gameplay) "; + } +} diff --git a/FoxTube.sln b/FoxTube.sln index a73f0db..7357c1c 100644 --- a/FoxTube.sln +++ b/FoxTube.sln @@ -5,16 +5,21 @@ VisualStudioVersion = 15.0.27428.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoxTube", "FoxTube\FoxTube.csproj", "{2597B816-7316-4D20-BA6C-D78001E89C1A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoxTube.Background", "FoxTube.Background\FoxTube.Background.csproj", "{FC9128D7-E3AA-48ED-8641-629794B88B28}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU Debug|ARM = Debug|ARM Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU Release|ARM = Release|ARM Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2597B816-7316-4D20-BA6C-D78001E89C1A}.Debug|Any CPU.ActiveCfg = Debug|x86 {2597B816-7316-4D20-BA6C-D78001E89C1A}.Debug|ARM.ActiveCfg = Debug|ARM {2597B816-7316-4D20-BA6C-D78001E89C1A}.Debug|ARM.Build.0 = Debug|ARM {2597B816-7316-4D20-BA6C-D78001E89C1A}.Debug|ARM.Deploy.0 = Debug|ARM @@ -24,6 +29,7 @@ Global {2597B816-7316-4D20-BA6C-D78001E89C1A}.Debug|x86.ActiveCfg = Debug|x86 {2597B816-7316-4D20-BA6C-D78001E89C1A}.Debug|x86.Build.0 = Debug|x86 {2597B816-7316-4D20-BA6C-D78001E89C1A}.Debug|x86.Deploy.0 = Debug|x86 + {2597B816-7316-4D20-BA6C-D78001E89C1A}.Release|Any CPU.ActiveCfg = Release|x86 {2597B816-7316-4D20-BA6C-D78001E89C1A}.Release|ARM.ActiveCfg = Release|ARM {2597B816-7316-4D20-BA6C-D78001E89C1A}.Release|ARM.Build.0 = Release|ARM {2597B816-7316-4D20-BA6C-D78001E89C1A}.Release|ARM.Deploy.0 = Release|ARM @@ -33,6 +39,22 @@ Global {2597B816-7316-4D20-BA6C-D78001E89C1A}.Release|x86.ActiveCfg = Release|x86 {2597B816-7316-4D20-BA6C-D78001E89C1A}.Release|x86.Build.0 = Release|x86 {2597B816-7316-4D20-BA6C-D78001E89C1A}.Release|x86.Deploy.0 = Release|x86 + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Debug|ARM.ActiveCfg = Debug|ARM + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Debug|ARM.Build.0 = Debug|ARM + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Debug|x64.ActiveCfg = Debug|x64 + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Debug|x64.Build.0 = Debug|x64 + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Debug|x86.ActiveCfg = Debug|x86 + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Debug|x86.Build.0 = Debug|x86 + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Release|Any CPU.Build.0 = Release|Any CPU + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Release|ARM.ActiveCfg = Release|ARM + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Release|ARM.Build.0 = Release|ARM + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Release|x64.ActiveCfg = Release|x64 + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Release|x64.Build.0 = Release|x64 + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Release|x86.ActiveCfg = Release|x86 + {FC9128D7-E3AA-48ED-8641-629794B88B28}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FoxTube/Assets/Icons/Profile.png b/FoxTube/Assets/Icons/Profile.png new file mode 100644 index 0000000..71ac04e Binary files /dev/null and b/FoxTube/Assets/Icons/Profile.png differ diff --git a/FoxTube/Assets/Icons/Send.png b/FoxTube/Assets/Icons/Send.png new file mode 100644 index 0000000..2c73623 Binary files /dev/null and b/FoxTube/Assets/Icons/Send.png differ diff --git a/FoxTube/Classes/Methods.cs b/FoxTube/Classes/Methods.cs index 35759d7..182fbb7 100644 --- a/FoxTube/Classes/Methods.cs +++ b/FoxTube/Classes/Methods.cs @@ -1,5 +1,7 @@ -using System; +using MyToolkit.Multimedia; +using System; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Windows.UI; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -70,5 +72,40 @@ namespace FoxTube else block.Inlines.Add(new Run { Text = item }); } } + + public static string QualityToString(YouTubeQuality quality) + { + switch(quality) + { + case YouTubeQuality.NotAvailable: + return "N/A"; + case YouTubeQuality.Quality1080P: + return "1080p"; + case YouTubeQuality.Quality144P: + return "144p"; + case YouTubeQuality.Quality2160P: + return "2160p"; + case YouTubeQuality.Quality240P: + return "240p"; + case YouTubeQuality.Quality270P: + return "270p"; + case YouTubeQuality.Quality360P: + return "360p"; + case YouTubeQuality.Quality480P: + return "480p"; + case YouTubeQuality.Quality520P: + return "520p"; + case YouTubeQuality.Quality720P: + return "720p"; + case YouTubeQuality.QualityHigh: + return "[Audio only] High quality"; + case YouTubeQuality.QualityLow: + return "[Audio only] Low quality"; + case YouTubeQuality.QualityMedium: + return "[Audio only] Medium quality"; + default: + return "Unknown"; + } + } } } diff --git a/FoxTube/Classes/Notification.cs b/FoxTube/Classes/Notification.cs index 52204d3..cdb02bb 100644 --- a/FoxTube/Classes/Notification.cs +++ b/FoxTube/Classes/Notification.cs @@ -3,6 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Windows.Data.Xml.Dom; +using Windows.UI; +using Windows.UI.Notifications; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Imaging; @@ -10,35 +15,157 @@ namespace FoxTube { public enum NotificationType { - NewVideo, NewComment, NewPost, Update + Video, Comment, Post, Internal } public class Notification { - public string Header { get; set; } - public string message { get; set; } - public DateTime time { get; set; } + public string Channel { get; set; } + public string Content { get; set; } + public DateTime TimeStamp { get; set; } public NotificationType Type { get; set; } public string Avatar { get; set; } public string Thumbnail { get; set; } - public Notification(string header, string content, DateTime date, NotificationType type, string avatar = "ms-appx:///Assets/NewsAvatar.png", string thumbnail = "ms-appx:///Assets/AnnouncementThumb.png") + public Notification(NotificationType type, + string channelName, string content, DateTime date, + string thumbnailUrl, string avatarUrl = "ms-appx:///Assets/Icons/Profile.png") { - Header = header; - message = content; - time = date; + Channel = channelName; + Content = content; + TimeStamp = date; Type = type; - Avatar = avatar; - Thumbnail = thumbnail; + Avatar = avatarUrl; + Thumbnail = thumbnailUrl; } - public string returnTimecode(bool twelveFormat = true) + public UIElement GetNotification() { - TimeSpan diff = DateTime.Now - time; - if (diff.TotalDays == 0) - return string.Format("{0}:{1}", time.Hour, time.Minute); - else - return string.Format("{0}/{1} {2}:{3}", time.Month, time.Day, time.Hour, time.Minute); + StackPanel stackPanel = new StackPanel() { Margin = new Thickness(10, 0, 0, 0) }; + + //Channel + switch (Type) + { + case NotificationType.Comment: + stackPanel.Children.Add(new TextBlock() + { + FontSize = 14, + FontStyle = Windows.UI.Text.FontStyle.Italic, + Foreground = new SolidColorBrush(Colors.Gray), + Text = string.Format("{0} replied to your comment", Channel) + }); + break; + + case NotificationType.Internal: + stackPanel.Children.Add(new TextBlock() + { + FontSize = 14, + FontStyle = Windows.UI.Text.FontStyle.Italic, + Foreground = new SolidColorBrush(Colors.Gray), + Text = Channel + }); + break; + + case NotificationType.Post: + stackPanel.Children.Add(new TextBlock() + { + FontSize = 14, + FontStyle = Windows.UI.Text.FontStyle.Italic, + Foreground = new SolidColorBrush(Colors.Gray), + Text = string.Format("{0} published new post", Channel) + }); + break; + + case NotificationType.Video: + stackPanel.Children.Add(new TextBlock() + { + FontSize = 14, + FontStyle = Windows.UI.Text.FontStyle.Italic, + Foreground = new SolidColorBrush(Colors.Gray), + Text = string.Format("{0} uploaded new video", Channel) + }); + break; + } + + //Content + stackPanel.Children.Add(new TextBlock() + { + TextWrapping = TextWrapping.WrapWholeWords, + Text = Content, + }); + //Time + stackPanel.Children.Add(new TextBlock() + { + FontSize = 13, + Foreground = new SolidColorBrush(Colors.Gray), + Text = TimeStamp.ToString() + }); + PersonPicture avatar = new PersonPicture() + { + Height = 50, + VerticalAlignment = VerticalAlignment.Top, + ProfilePicture = string.IsNullOrWhiteSpace(Avatar) ? null : new BitmapImage(new Uri(Avatar)) + }; + + Grid grid = new Grid(); + grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(50) }); + grid.ColumnDefinitions.Add(new ColumnDefinition()); + + grid.Children.Add(avatar); + Grid.SetColumn(stackPanel, 1); + grid.Children.Add(stackPanel); + + Button item = new Button() + { + HorizontalAlignment = HorizontalAlignment.Stretch, + HorizontalContentAlignment = HorizontalAlignment.Left, + Background = new SolidColorBrush(Colors.Transparent), + Content = grid + }; + + return item; + } + + public ToastNotification GetToast(int assignedId) + { + System.Xml.XmlDocument template = new System.Xml.XmlDocument(); + switch(Type) + { + case NotificationType.Comment: + template.Load("ms-appx:///Assets/Notifications/Comment.xml"); + template["toast"]["visual"]["binding"]["image"].SetAttribute("src", Avatar); + template["toast"]["visual"]["binding"].ChildNodes[1].InnerText = string.Format("{0} posted a new comment", Channel); + template["toast"]["visual"]["binding"].LastChild.InnerText = Content; + break; + + case NotificationType.Video: + template.Load("ms-appx:///Assets/Notifications/Video.xml"); + (template["toast"]["visual"]["binding"].FirstChild as System.Xml.XmlElement).SetAttribute("src", Avatar); + template["toast"]["visual"]["binding"].ChildNodes[1].InnerText = string.Format("{0} uploaded a new video", Channel); + template["toast"]["visual"]["binding"].ChildNodes[2].InnerText = Content; + (template["toast"]["visual"]["binding"].LastChild as System.Xml.XmlElement).SetAttribute("src", Thumbnail); + break; + + case NotificationType.Internal: + template.Load("ms-appx:///Assets/Notifications/Internal.xml"); + if(!string.IsNullOrWhiteSpace(Thumbnail)) + (template["toast"]["visual"]["binding"].FirstChild as System.Xml.XmlElement).SetAttribute("src", Avatar); + template["toast"]["visual"]["binding"].LastChild.InnerText = Channel; + break; + + case NotificationType.Post: + template.Load("ms-appx:///Assets/Notifications/Video.xml"); + (template["toast"]["visual"]["binding"].FirstChild as System.Xml.XmlElement).SetAttribute("src", Thumbnail); + (template["toast"]["visual"]["binding"].ChildNodes[1] as System.Xml.XmlElement).SetAttribute("src", Avatar); + template["toast"]["visual"]["binding"].ChildNodes[2].InnerText = string.Format("{0} published a new post", Channel); + template["toast"]["visual"]["binding"].ChildNodes[3].InnerText = Content; + break; + } + + XmlDocument toastXml = new XmlDocument(); + toastXml.LoadXml(template.InnerXml); + + return new ToastNotification(toastXml); } } } diff --git a/FoxTube/Classes/ObjectEventArgs.cs b/FoxTube/Classes/ObjectEventArgs.cs new file mode 100644 index 0000000..d5716c0 --- /dev/null +++ b/FoxTube/Classes/ObjectEventArgs.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FoxTube +{ + public class ObjectEventArgs : EventArgs + { + public List Parameters = new List(); + public ObjectEventArgs(params object[] args) + { + foreach (object a in args) + Parameters.Add(a); + } + } +} diff --git a/FoxTube/Classes/SecretsVault.cs b/FoxTube/Classes/SecretsVault.cs index 588957d..332c55f 100644 --- a/FoxTube/Classes/SecretsVault.cs +++ b/FoxTube/Classes/SecretsVault.cs @@ -24,47 +24,50 @@ using Google.Apis.Util.Store; using Google.Apis.YouTube.v3; using Google.Apis.Auth.OAuth2.Responses; using Windows.Storage; +using Google.Apis.YouTube.v3.Data; namespace FoxTube { public class SecretsVault { #region Static Information - public static NetworkCredential EmailCredential { get => new NetworkCredential("youwillneverknowthisadress@gmail.com", "thisisthepassword12345"); } - public static SecretsVault Vault { get => Methods.MainPage.Vault; } + public static NetworkCredential EmailCredential => new NetworkCredential("youwillneverknowthisadress@gmail.com", "thisisthepassword12345"); + private static ClientSecrets Secrets => new ClientSecrets() + { + ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com", + ClientSecret = "BkVZOAaCU2Zclf0Zlicg6y2_" + }; + + public static SecretsVault Vault => Methods.MainPage.Vault; + public static string AccountId => Methods.MainPage.Vault.userId; - private static ClientSecrets Secrets - { - get => new ClientSecrets() - { - ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com", - ClientSecret = "BkVZOAaCU2Zclf0Zlicg6y2_" - }; - } - public static bool IsAuthorized { get => Vault.IsLoged; } + public static bool IsAuthorized => Vault.IsLoged; - public static YouTubeService NoAuthService + public static Google.Apis.YouTube.v3.Data.Channel UserChannel => Methods.MainPage.Vault.channel; + public static List> WatchLater => Methods.MainPage.Vault.later; + public static List UserHistory => Methods.MainPage.Vault.history; + public static List Subscriptions => Methods.MainPage.Vault.subs; + + public static YouTubeService NoAuthService => new YouTubeService(new BaseClientService.Initializer() { - get => new YouTubeService(new BaseClientService.Initializer() - { - ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0", - ApplicationName = "FoxTube" - }); - } + ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0", + ApplicationName = "FoxTube" + }); - public static YouTubeService Service + public static YouTubeService Service => new YouTubeService(new BaseClientService.Initializer() { - get => new YouTubeService(new BaseClientService.Initializer() - { - HttpClientInitializer = Vault.Credential, - ApplicationName = "FoxTube" - }); - } + HttpClientInitializer = Vault.Credential, + ApplicationName = "FoxTube" + }); #endregion #region Object containers public bool IsLoged = false; public string userId; + public List history = new List(); + public List subs = new List(); + public List> later = new List>(); + public Google.Apis.YouTube.v3.Data.Channel channel; public UserCredential Credential; public event EventHandler AuthorizationStateChanged; @@ -78,9 +81,56 @@ namespace FoxTube AuthorizationStateChanged.Invoke(this, null); } - var request = Service.Channels.List("snippet"); + var request = Service.Channels.List("snippet,contentDetails"); request.Mine = true; - userId = (await request.ExecuteAsync()).Items[0].Id; + channel = (await request.ExecuteAsync()).Items[0]; + userId = channel.Id; + + var historyRequest = Service.PlaylistItems.List("snippet"); + historyRequest.PlaylistId = channel.ContentDetails.RelatedPlaylists.WatchHistory; + historyRequest.MaxResults = 50; + var response = await historyRequest.ExecuteAsync(); + history.Clear(); + foreach (PlaylistItem i in response.Items) + history.Add(i.Snippet.ResourceId.VideoId); + + var laterRequest = Service.PlaylistItems.List("snippet"); + laterRequest.PlaylistId = channel.ContentDetails.RelatedPlaylists.WatchLater; + laterRequest.MaxResults = 50; + var laterResponse = await laterRequest.ExecuteAsync(); + later.Clear(); + + foreach (PlaylistItem i in laterResponse.Items) + later.Add(new KeyValuePair(i.Id, i.Snippet.ResourceId.VideoId)); + + string nextToken = laterResponse.NextPageToken; + while (nextToken != null) + { + laterRequest.PageToken = nextToken; + laterResponse = await laterRequest.ExecuteAsync(); + foreach (PlaylistItem i in laterResponse.Items) + later.Add(new KeyValuePair(i.Id, i.Snippet.ResourceId.VideoId)); + + nextToken = laterResponse.NextPageToken; + } + + SubscriptionsResource.ListRequest subRequest = SecretsVault.Service.Subscriptions.List("snippet"); + subRequest.Mine = true; + subRequest.MaxResults = 50; + SubscriptionListResponse subResponse = await subRequest.ExecuteAsync(); + subs.Clear(); + + foreach (Subscription s in subResponse.Items) + subs.Add(s.Snippet.ResourceId.ChannelId); + + nextToken = subResponse.NextPageToken; + while(nextToken != null) + { + subRequest.PageToken = nextToken; + subResponse = await subRequest.ExecuteAsync(); + foreach (Subscription s in subResponse.Items) + subs.Add(s.Snippet.ResourceId.ChannelId); + } } public async void Deauthenticate() diff --git a/FoxTube/Controls/DownloadAgent.cs b/FoxTube/Controls/DownloadAgent.cs new file mode 100644 index 0000000..511fdb3 --- /dev/null +++ b/FoxTube/Controls/DownloadAgent.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using System.IO; +using MyToolkit.Multimedia; + +namespace FoxTube.Controls +{ + public class DownloadAgent + { + public List Items = new List(); + + XmlDocument doc = new XmlDocument(); + string path = $@"{Directory.GetCurrentDirectory()}\DownloadHistory.xml"; + public DownloadAgent() + { + if (File.Exists(path)) + doc.Load(path); + else + { + doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); + doc.AppendChild(doc.CreateElement("downloads")); + doc.Save(path); + } + + 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) + { + DownloadItem item = new DownloadItem(id, quality); + item.DownloadCanceled += Item_DownloadCanceled; + item.DownloadComplete += Item_DownloadComplete; + + Items.Add(item); + } + + private void Item_DownloadComplete(object sender, EventArgs e) + { + doc["downloads"].AppendChild((e as ObjectEventArgs).Parameters[0] as XmlElement); + } + + private void Item_DownloadCanceled(object sender, EventArgs e) + { + Items.Remove(sender as DownloadItem); + } + } +} diff --git a/FoxTube/Controls/DownloadItem.xaml b/FoxTube/Controls/DownloadItem.xaml new file mode 100644 index 0000000..8c5e2fe --- /dev/null +++ b/FoxTube/Controls/DownloadItem.xaml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +