Archived
1
0

Region settings fixed

Channel page cover fixed
Livestream toasts added
This commit is contained in:
Michael Gordeev
2019-04-04 22:10:47 +03:00
parent d745611ca5
commit b875124c1a
12 changed files with 175 additions and 40 deletions
+29 -16
View File
@@ -1,4 +1,7 @@
using Newtonsoft.Json;
using Google.Apis.Services;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -17,6 +20,11 @@ namespace FoxTube.Background
private DateTime lastCheck;
private readonly ApplicationDataContainer settings = ApplicationData.Current.RoamingSettings;
dynamic prefs;
private readonly YouTubeService Service = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "AIzaSyBgHrCnrlzlVmk0cJKL8RqP9Y8x6XSuk_0",
ApplicationName = "FoxTube"
});
BackgroundTaskDeferral def;
public async void Run(IBackgroundTaskInstance taskInstance)
@@ -53,35 +61,40 @@ namespace FoxTube.Background
{
Dictionary<string, string> subscriptions = JsonConvert.DeserializeObject<Dictionary<string, string>>(settings.Values["subscriptions"] as string);
List<XmlElement> results = new List<XmlElement>();
List<SearchResult> results = new List<SearchResult>();
foreach (var s in subscriptions)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(await new HttpClient().GetStringAsync($"https://www.youtube.com/feeds/videos.xml?channel_id={s.Key}"));
SearchResource.ListRequest request = Service.Search.List("snippet");
request.PublishedAfter = lastCheck;
request.ChannelId = s.Key;
request.Type = "video";
request.MaxResults = 5;
SearchListResponse response = await request.ExecuteAsync();
List<XmlElement> items = new List<XmlElement>();
foreach (XmlElement i in doc["feed"].ChildNodes)
if (i.Name == "entry" && DateTime.Parse(i["published"].InnerText) > lastCheck)
items.Add(i);
items.OrderByDescending(i => DateTime.Parse(i["published"].InnerText));
foreach(XmlElement i in items)
foreach (SearchResult i in response.Items)
{
results.Add(i);
ToastNotificationManager.CreateToastNotifier().Show(
Notification.GetVideoToast(i["yt:videoId"].InnerText, s.Key, i["title"].InnerText, i["author"]["name"].InnerText, (await new YoutubeExplode.YoutubeClient().GetVideoAsync(i["yt:videoId"].InnerText)).Thumbnails.MediumResUrl, DateTime.Parse(i["published"].InnerText), s.Value));
if(i.Snippet.LiveBroadcastContent == "live")
ToastNotificationManager.CreateToastNotifier().Show(
Notification.GetStreamToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title, i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, i.Snippet.PublishedAt.Value, s.Value));
else if(i.Snippet.LiveBroadcastContent == "upcoming")
ToastNotificationManager.CreateToastNotifier().Show(
Notification.GetUpcomingToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title, i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, i.Snippet.PublishedAt.Value, s.Value));
else
ToastNotificationManager.CreateToastNotifier().Show(
Notification.GetVideoToast(i.Id.VideoId, i.Snippet.ChannelId, i.Snippet.Title, i.Snippet.ChannelTitle, i.Snippet.Thumbnails.Medium.Url, i.Snippet.PublishedAt.Value, s.Value));
}
}
results.OrderBy(i => i.Snippet.PublishedAt);
TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();
updater.EnableNotificationQueue(true);
updater.Clear();
for (int i = 0; i < 5 && i < results.Count; i++)
updater.Update(Tiles.GetTileLayout(System.Security.SecurityElement.Escape(results[i]["title"].InnerText), System.Security.SecurityElement.Escape(results[i]["author"]["name"].InnerText), (await new YoutubeExplode.YoutubeClient().GetVideoAsync(results[i]["yt:videoId"].InnerText)).Thumbnails.MediumResUrl.Replace("&", "%26"), subscriptions[results[i]["author"]["url"].InnerText.Split('/').Last()]));
updater.Update(Tiles.GetTileLayout(System.Security.SecurityElement.Escape(results[i].Snippet.Title), System.Security.SecurityElement.Escape(results[i].Snippet.ChannelTitle), results[i].Snippet.Thumbnails.Medium.Url.Replace("&", "%26"), subscriptions[results[i].Snippet.ChannelId]));
}
catch { }
}