DownloadAgent fixes and improvements
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
using System;
|
||||
using Google.Apis.Auth.OAuth2;
|
||||
using Google.Apis.Services;
|
||||
using Google.Apis.YouTube.v3;
|
||||
using Google.Apis.YouTube.v3.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using Windows.ApplicationModel.Background;
|
||||
@@ -15,14 +20,23 @@ namespace FoxTube.Background
|
||||
{
|
||||
public List<Notification> Notifications = new List<Notification>();
|
||||
|
||||
private DateTime lastCheck;
|
||||
private DateTime lastCheck = DateTime.Now;
|
||||
private ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
|
||||
|
||||
private ClientSecrets Secrets => new ClientSecrets()
|
||||
{
|
||||
ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com",
|
||||
ClientSecret = "BkVZOAaCU2Zclf0Zlicg6y2_"
|
||||
};
|
||||
|
||||
BackgroundTaskDeferral def;
|
||||
public async void Run(IBackgroundTaskInstance taskInstance)
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
def = taskInstance.GetDeferral();
|
||||
XmlDocument doc = new XmlDocument();
|
||||
if (settings.Values["lastCheck"] == null)
|
||||
settings.Values.Add("lastCheck", XmlConvert.ToString(DateTime.Now));
|
||||
else lastCheck = XmlConvert.ToDateTime(settings.Values["lastCheck"] as string, XmlDateTimeSerializationMode.Unspecified);
|
||||
|
||||
if (settings.Values["notificationsHistory"] != null)
|
||||
doc.LoadXml(settings.Values["notificationsHistory"] as string);
|
||||
@@ -40,16 +54,49 @@ namespace FoxTube.Background
|
||||
def.Complete();
|
||||
}
|
||||
|
||||
void CheckAccount()
|
||||
async void CheckAccount()
|
||||
{
|
||||
UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, new[] { Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoProfile, YouTubeService.Scope.YoutubeForceSsl }, "user", CancellationToken.None);
|
||||
if (credential == null)
|
||||
return;
|
||||
|
||||
SubscriptionsResource.ListRequest subRequest = new YouTubeService(new BaseClientService.Initializer()
|
||||
{
|
||||
HttpClientInitializer = credential,
|
||||
ApplicationName = "FoxTube"
|
||||
}).Subscriptions.List("snippet");
|
||||
subRequest.Mine = true;
|
||||
subRequest.MaxResults = 50;
|
||||
SubscriptionListResponse subResponse = await subRequest.ExecuteAsync();
|
||||
List<string> subs = new List<string>();
|
||||
|
||||
foreach (Subscription s in subResponse.Items)
|
||||
subs.Add(s.Snippet.ResourceId.ChannelId);
|
||||
|
||||
string 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);
|
||||
}
|
||||
|
||||
foreach(string s in subs)
|
||||
{
|
||||
var request = new YouTubeService(new BaseClientService.Initializer()
|
||||
{
|
||||
ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0",
|
||||
ApplicationName = "FoxTube"
|
||||
}).Activities.List("snippet");
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
if ((XmlConvert.ToDateTime((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), XmlDateTimeSerializationMode.Utc) - lastCheck).TotalSeconds > 0)
|
||||
Notifications.Add(new Notification(NotificationType.Internal,
|
||||
doc["posts"].FirstChild["notificationHeader"].InnerText,
|
||||
doc["posts"].FirstChild["content"].InnerText,
|
||||
|
||||
@@ -110,9 +110,23 @@
|
||||
<Compile Include="BackgroundProcessor.cs" />
|
||||
<Compile Include="Notification.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ToastTemplates.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Apis">
|
||||
<Version>1.30.0-beta02</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Google.Apis.Auth">
|
||||
<Version>1.30.0-beta02</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Google.Apis.Core">
|
||||
<Version>1.30.0-beta02</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Google.Apis.Oauth2.v2">
|
||||
<Version>1.29.2.994</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Google.Apis.YouTube.v3">
|
||||
<Version>1.29.2.1006</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||
<Version>6.1.5</Version>
|
||||
</PackageReference>
|
||||
|
||||
@@ -39,6 +39,12 @@ namespace FoxTube.Background
|
||||
Thumbnail = thumbnailUrl;
|
||||
}
|
||||
|
||||
public string GetXml()
|
||||
{
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public UIElement GetNotification()
|
||||
{
|
||||
StackPanel stackPanel = new StackPanel() { Margin = new Thickness(10, 0, 0, 0) };
|
||||
@@ -155,17 +161,71 @@ namespace FoxTube.Background
|
||||
break;
|
||||
|
||||
case NotificationType.Video:
|
||||
template.LoadXml($@"<toast launch='action=viewPhoto&photoId=92187'>
|
||||
template.LoadXml($@"<toast launch='action=viewPhoto&photoId=92187'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{Avatar}'/>
|
||||
<text>{Channel} uploaded a new video</text>
|
||||
<text>{Content}</text>
|
||||
<image src='{Thumbnail}'/>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
<action content='Watch later'
|
||||
activationType='background'
|
||||
arguments='likePhoto&photoId=92187'/>
|
||||
<action content='Go to channel'
|
||||
arguments='action=commentPhoto&photoId=92187'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
break;
|
||||
|
||||
case NotificationType.Internal:
|
||||
string thumb1 = string.IsNullOrWhiteSpace(Thumbnail) ? "Assets/AnnouncementThumb.png" : Thumbnail;
|
||||
<text>{Content}</text>
|
||||
template.LoadXml($@"<toast launch='action=openThread&threadId=92187'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='hero' src='{thumb1}'/>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='Assets/LogoAvatar.png'/>
|
||||
<text>{Channel}</text>
|
||||
<text hint-maxLines='5'>{Content}</text>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
<action content='Watch full post'
|
||||
arguments='action=commentPhoto&photoId=92187'/>
|
||||
<action content='Manage notifications'
|
||||
arguments='action=commentPhoto&photoId=92187'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
break;
|
||||
|
||||
case NotificationType.Post:
|
||||
string thumb2 = string.IsNullOrWhiteSpace(Thumbnail) ? "" : $"<image placement='hero' src ='{Thumbnail}'/>";
|
||||
<actions>
|
||||
template.LoadXml($@"<toast launch='action=openThread&threadId=92187'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
{thumb2}
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{Avatar}'/>
|
||||
<text>{Channel}</text>
|
||||
<text hint-maxLines='5'>{Content}</text>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
<input id='textBox' type='text' placeHolderContent='Leave a comment'/>
|
||||
<action content='Send'
|
||||
imageUri='Assets/Icons/send.png'
|
||||
hint-inputId='textBox'
|
||||
activationType='background'
|
||||
arguments='action=reply&threadId=92187'/>
|
||||
|
||||
<action content='Like'
|
||||
arguments='action=commentPhoto&photoId=92187'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
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 =
|
||||
@"<toast launch='action=openThread&threadId=92187'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='Assets/Icons/Profile.png'/>
|
||||
<text>[ChannelName] posted a new comment</text>
|
||||
<text>[VideoName]</text>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
<input id='textBox' type='text' placeHolderContent='Send a reply'/>
|
||||
|
||||
<action content='Send' imageUri='Assets/Icons/Send.png'
|
||||
hint-inputId='textBox' activationType='background'
|
||||
arguments='action=reply&threadId=92187'/>
|
||||
|
||||
<action content='Like'
|
||||
arguments='action=commentPhoto&photoId=92187'/>
|
||||
<action content='Go to comment'
|
||||
arguments='action=commentPhoto&photoId=92187'/>
|
||||
</actions>
|
||||
</toast>";
|
||||
public static string Video =
|
||||
@"<toast launch='action=viewPhoto&photoId=92187'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='Assets/Icons/Profile.png'/>
|
||||
<text>[ChannelName] uploaded a new video</text>
|
||||
<text>[VideoName]</text>
|
||||
<image src='Assets/videoThumbSample.png'/>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
Reference in New Issue
Block a user