Region settings fixed
Channel page cover fixed Livestream toasts added
This commit is contained in:
@@ -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 { }
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ namespace FoxTube.Background
|
||||
{ "changelog", "Список изменений" },
|
||||
{ "changelogHeader", "Что нового в версии" },
|
||||
{ "videoContent", "загрузил новое видео" },
|
||||
{ "live", "ПРЯМОЙ ЭФИР" },
|
||||
{ "upcoming", "Запланирован" },
|
||||
{ "liveContent", "начал прямой эфир" },
|
||||
{ "upcomingContent", "запланировал прямой эфир" },
|
||||
{ "goChannel", "Открыть канал" }
|
||||
};
|
||||
else
|
||||
@@ -32,6 +36,10 @@ namespace FoxTube.Background
|
||||
{ "changelog", "Changelog" },
|
||||
{ "changelogHeader", "What's new in version" },
|
||||
{ "videoContent", "uploaded a new video" },
|
||||
{ "live", "LIVE" },
|
||||
{ "upcoming", "Upcoming" },
|
||||
{ "liveContent", "started live broadcast" },
|
||||
{ "upcomingContent", "planned live broadcast" },
|
||||
{ "goChannel", "Go to channel" }
|
||||
};
|
||||
}
|
||||
@@ -76,6 +84,48 @@ namespace FoxTube.Background
|
||||
|
||||
return new ToastNotification(template);
|
||||
}
|
||||
public static ToastNotification GetStreamToast(string id, string channelId, string title, string channel, string thumbnail, DateTimeOffset timeStamp, string avatar)
|
||||
{
|
||||
XmlDocument template = new XmlDocument();
|
||||
string ts = $"{timeStamp.Year}-{timeStamp.Month:00}-{timeStamp.Day:00}T{timeStamp.Hour:00}:{timeStamp.Minute:00}:{timeStamp.Second:00}Z";
|
||||
template.LoadXml($@"<toast activationType='foreground' launch='video|{id}' displayTimestamp='{ts}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='hero' src='{thumbnail.Replace("&", "%26")}'/>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{avatar.Replace("&", "%26") ?? "http://foxgame-studio.000webhostapp.com/FoxTubeAssets/LogoAvatar.png"}'/>
|
||||
<text>🔴 [{languagePack["live"]}] {System.Security.SecurityElement.Escape(title)}</text>
|
||||
<text>{System.Security.SecurityElement.Escape(channel)} {languagePack["liveContent"]}</text>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
<action content='{languagePack["goChannel"]}' activationType='foreground' arguments='channel|{channelId}'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
|
||||
return new ToastNotification(template);
|
||||
}
|
||||
public static ToastNotification GetUpcomingToast(string id, string channelId, string title, string channel, string thumbnail, DateTimeOffset timeStamp, string avatar)
|
||||
{
|
||||
XmlDocument template = new XmlDocument();
|
||||
string ts = $"{timeStamp.Year}-{timeStamp.Month:00}-{timeStamp.Day:00}T{timeStamp.Hour:00}:{timeStamp.Minute:00}:{timeStamp.Second:00}Z";
|
||||
template.LoadXml($@"<toast activationType='foreground' launch='video|{id}' displayTimestamp='{ts}'>
|
||||
<visual>
|
||||
<binding template='ToastGeneric'>
|
||||
<image placement='hero' src='{thumbnail.Replace("&", "%26")}'/>
|
||||
<image placement='appLogoOverride' hint-crop='circle' src='{avatar.Replace("&", "%26") ?? "http://foxgame-studio.000webhostapp.com/FoxTubeAssets/LogoAvatar.png"}'/>
|
||||
<text>🔴 [{languagePack["upcoming"]}] {System.Security.SecurityElement.Escape(title)}</text>
|
||||
<text>{System.Security.SecurityElement.Escape(channel)} {languagePack["upcomingContent"]}</text>
|
||||
</binding>
|
||||
</visual>
|
||||
|
||||
<actions>
|
||||
<action content='{languagePack["goChannel"]}' activationType='foreground' arguments='channel|{channelId}'/>
|
||||
</actions>
|
||||
</toast>");
|
||||
|
||||
return new ToastNotification(template);
|
||||
}
|
||||
|
||||
public static ToastNotification GetInternalToast(string id, string header, string content, string thumbnail, string avatar)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user