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,
|
||||
|
||||
Reference in New Issue
Block a user