Improved background process
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
using Google.Apis.Services;
|
using Google.Apis.Auth.OAuth2;
|
||||||
|
using Google.Apis.Oauth2.v2;
|
||||||
|
using Google.Apis.Services;
|
||||||
using Google.Apis.YouTube.v3;
|
using Google.Apis.YouTube.v3;
|
||||||
using Google.Apis.YouTube.v3.Data;
|
using Google.Apis.YouTube.v3.Data;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -6,6 +8,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Windows.ApplicationModel.Background;
|
using Windows.ApplicationModel.Background;
|
||||||
@@ -19,11 +22,6 @@ namespace FoxTube.Background
|
|||||||
private DateTime lastCheck;
|
private DateTime lastCheck;
|
||||||
private readonly ApplicationDataContainer settings = ApplicationData.Current.RoamingSettings;
|
private readonly ApplicationDataContainer settings = ApplicationData.Current.RoamingSettings;
|
||||||
dynamic prefs;
|
dynamic prefs;
|
||||||
private readonly YouTubeService Service = new YouTubeService(new BaseClientService.Initializer()
|
|
||||||
{
|
|
||||||
ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0",
|
|
||||||
ApplicationName = "FoxTube"
|
|
||||||
});
|
|
||||||
BackgroundTaskDeferral def;
|
BackgroundTaskDeferral def;
|
||||||
|
|
||||||
public async void Run(IBackgroundTaskInstance taskInstance)
|
public async void Run(IBackgroundTaskInstance taskInstance)
|
||||||
@@ -44,7 +42,7 @@ namespace FoxTube.Background
|
|||||||
prefs = JsonConvert.DeserializeObject<dynamic>(settings.Values["settings"] as string);
|
prefs = JsonConvert.DeserializeObject<dynamic>(settings.Values["settings"] as string);
|
||||||
if ((bool)prefs.devNotifications)
|
if ((bool)prefs.devNotifications)
|
||||||
CheckAnnouncements();
|
CheckAnnouncements();
|
||||||
if ((bool)prefs.videoNotifications)
|
if ((bool)prefs.videoNotifications && (bool)prefs.hasAccount)
|
||||||
await CheckAccount();
|
await CheckAccount();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -58,15 +56,59 @@ namespace FoxTube.Background
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Dictionary<string, string> subscriptions = JsonConvert.DeserializeObject<Dictionary<string, string>>(settings.Values["subscriptions"] as string);
|
UserCredential Credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
|
||||||
|
new ClientSecrets
|
||||||
|
{
|
||||||
|
ClientId = "349735264870-2ekqlm0a4mkg3mmrfcv90s3qp3o15dq0.apps.googleusercontent.com",
|
||||||
|
ClientSecret = "BkVZOAaCU2Zclf0Zlicg6y2_"
|
||||||
|
},
|
||||||
|
new[]
|
||||||
|
{
|
||||||
|
Oauth2Service.Scope.UserinfoProfile,
|
||||||
|
Oauth2Service.Scope.UserinfoEmail,
|
||||||
|
YouTubeService.Scope.YoutubeForceSsl,
|
||||||
|
YouTubeService.Scope.Youtube,
|
||||||
|
YouTubeService.Scope.YoutubeUpload,
|
||||||
|
YouTubeService.Scope.YoutubeReadonly,
|
||||||
|
YouTubeService.Scope.Youtubepartner
|
||||||
|
},
|
||||||
|
"user",
|
||||||
|
CancellationToken.None);
|
||||||
|
|
||||||
|
if (Credential == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
YouTubeService service = new YouTubeService(new BaseClientService.Initializer
|
||||||
|
{
|
||||||
|
HttpClientInitializer = Credential,
|
||||||
|
ApplicationName = "FoxTube"
|
||||||
|
});
|
||||||
|
|
||||||
|
List<Subscription> subscriptions = new List<Subscription>();
|
||||||
List<SearchResult> results = new List<SearchResult>();
|
List<SearchResult> results = new List<SearchResult>();
|
||||||
|
|
||||||
foreach (var s in subscriptions)
|
SubscriptionsResource.ListRequest subRequest = service.Subscriptions.List("snippet");
|
||||||
|
subRequest.Mine = true;
|
||||||
|
subRequest.MaxResults = 50;
|
||||||
|
subRequest.Order = SubscriptionsResource.ListRequest.OrderEnum.Relevance;
|
||||||
|
SubscriptionListResponse subResponse;
|
||||||
|
string nextToken = null;
|
||||||
|
|
||||||
|
do
|
||||||
{
|
{
|
||||||
SearchResource.ListRequest request = Service.Search.List("snippet");
|
subRequest.PageToken = nextToken;
|
||||||
request.PublishedAfter = lastCheck;
|
subResponse = await subRequest.ExecuteAsync();
|
||||||
request.ChannelId = s.Key;
|
foreach (Subscription s in subResponse.Items)
|
||||||
|
subscriptions.Add(s);
|
||||||
|
nextToken = subResponse.NextPageToken;
|
||||||
|
|
||||||
|
} while (!string.IsNullOrWhiteSpace(nextToken));
|
||||||
|
|
||||||
|
foreach (Subscription item in subscriptions)
|
||||||
|
{
|
||||||
|
SearchResource.ListRequest request = service.Search.List("snippet");
|
||||||
|
request.PublishedAfter = lastCheck.Subtract(TimeSpan.FromDays(1));
|
||||||
|
request.ChannelId = item.Snippet.ResourceId.ChannelId;
|
||||||
request.Type = "video";
|
request.Type = "video";
|
||||||
request.MaxResults = 5;
|
request.MaxResults = 5;
|
||||||
SearchListResponse response = await request.ExecuteAsync();
|
SearchListResponse response = await request.ExecuteAsync();
|
||||||
@@ -77,13 +119,13 @@ namespace FoxTube.Background
|
|||||||
|
|
||||||
if (i.Snippet.LiveBroadcastContent == "live")
|
if (i.Snippet.LiveBroadcastContent == "live")
|
||||||
ToastNotificationManager.CreateToastNotifier().Show(
|
ToastNotificationManager.CreateToastNotifier().Show(
|
||||||
Notification.GetStreamToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title.ConvertEscapeSymbols(), i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, i.Snippet.PublishedAt.Value, s.Value));
|
Notification.GetStreamToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title.ConvertEscapeSymbols(), i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, i.Snippet.PublishedAt.Value, item.Snippet.Thumbnails.Default__.Url));
|
||||||
else if (i.Snippet.LiveBroadcastContent == "upcoming")
|
else if (i.Snippet.LiveBroadcastContent == "upcoming")
|
||||||
ToastNotificationManager.CreateToastNotifier().Show(
|
ToastNotificationManager.CreateToastNotifier().Show(
|
||||||
Notification.GetUpcomingToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title.ConvertEscapeSymbols(), i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, i.Snippet.PublishedAt.Value, s.Value));
|
Notification.GetUpcomingToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title.ConvertEscapeSymbols(), i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, i.Snippet.PublishedAt.Value, item.Snippet.Thumbnails.Default__.Url));
|
||||||
else
|
else
|
||||||
ToastNotificationManager.CreateToastNotifier().Show(
|
ToastNotificationManager.CreateToastNotifier().Show(
|
||||||
Notification.GetVideoToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title.ConvertEscapeSymbols(), i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, i.Snippet.PublishedAt.Value, s.Value));
|
Notification.GetVideoToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title.ConvertEscapeSymbols(), i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, i.Snippet.PublishedAt.Value, item.Snippet.Thumbnails.Default__.Url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +135,7 @@ namespace FoxTube.Background
|
|||||||
updater.EnableNotificationQueue(true);
|
updater.EnableNotificationQueue(true);
|
||||||
updater.Clear();
|
updater.Clear();
|
||||||
for (int i = 0; i < 5 && i < results.Count; i++)
|
for (int i = 0; i < 5 && i < results.Count; i++)
|
||||||
updater.Update(Tiles.GetTileLayout(System.Security.SecurityElement.Escape(results[i].Snippet.Title.ConvertEscapeSymbols()), System.Security.SecurityElement.Escape(results[i].Snippet.ChannelTitle), results[i].Snippet.Thumbnails.Medium.Url.Replace("&", "%26"), subscriptions[results[i].Snippet.ChannelId]));
|
updater.Update(Tiles.GetTileLayout(System.Security.SecurityElement.Escape(results[i].Snippet.Title.ConvertEscapeSymbols()), System.Security.SecurityElement.Escape(results[i].Snippet.ChannelTitle), results[i].Snippet.Thumbnails.Medium.Url.Replace("&", "%26"), subscriptions.Find(x => x.Snippet.ResourceId.ChannelId == results[i].Snippet.ChannelId).Snippet.Thumbnails.Medium.Url));
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ namespace FoxTube.Background
|
|||||||
private static Dictionary<string, string> LoadPack()
|
private static Dictionary<string, string> LoadPack()
|
||||||
{
|
{
|
||||||
dynamic saved = JsonConvert.DeserializeObject<dynamic>(ApplicationData.Current.RoamingSettings.Values["settings"] as string);
|
dynamic saved = JsonConvert.DeserializeObject<dynamic>(ApplicationData.Current.RoamingSettings.Values["settings"] as string);
|
||||||
if (saved.language as string == "ru-RU")
|
string hl = saved.language;
|
||||||
|
if (hl == "ru-RU")
|
||||||
return new Dictionary<string, string>()
|
return new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
{ "addLater", "Посмотреть позже" },
|
{ "addLater", "Посмотреть позже" },
|
||||||
|
|||||||
Reference in New Issue
Block a user