diff --git a/Program.cs b/Program.cs
index 026061a..99cd211 100644
--- a/Program.cs
+++ b/Program.cs
@@ -22,6 +22,8 @@ using PlaylistsNET.Content;
using PlaylistsNET.Models;
using PlaylistsNET.Utils;
using YoutubeExplode.Playlists;
+using Dasync.Collections;
+using YoutubeExplode.Search;
namespace TYTD
{
@@ -67,7 +69,7 @@ namespace TYTD
Route.Add("/api/AddCaptions/{Id}", (HttpAction)AddCaptions);
/* Videos */
- Route.Add("/api/AddVideoInfo/{Id}", (HttpAction)AddVideoInfo);
+ Route.Add("/api/AddVideoInfo/{Id}", AddVideoInfo);
Route.Add("/api/AddVideo/{Id}", (HttpAction)AddVideo);
Route.Add("/api/AddVideoRes/{R}/{Id}", (HttpAction)AddVideoRes);
Route.Add("/api/Redownload", (HttpAction)Redownload);
@@ -75,28 +77,31 @@ namespace TYTD
Route.Add("/api/Watch/{VideoId}", (HttpAction)Watch);
Route.Add("/api/VideoInfo/{Id}",(HttpAction)VideoInfo);
/* Playlist */
- Route.Add("/api/AddPlaylistOnly/{Id}", (HttpAction)AddPlaylistOnly);
+ Route.Add("/api/AddPlaylistOnly/{Id}", AddPlaylistOnly);
Route.Add("/api/AddPlaylist/{Id}", (HttpAction)AddPlaylist);
Route.Add("/api/AddPlaylistRes/{R}/{Id}", (HttpAction)AddPlaylistRes);
Route.Add("/api/PersonalPlaylist/{PlaylistName}",(HttpAction)PersonalPlaylist);
Route.Add("/api/CreatePlaylist/{Ids}/playlist.{extension}", (HttpAction)CreatePlaylist);
Route.Add("/api/CreatePlaylistRes/{Ids}/playlist.{extension}", (HttpAction)CreatePlaylistRes);
Route.Add("/api/PlaylistInfo/{Id}", (HttpAction)PlaylistInfo);
- Route.Add("/api/ListPlaylists.html", (HttpAction)ListPlaylists);
+ Route.Add("/api/ListPlaylists/", (HttpAction)ListPlaylists);
/* Search */
Route.Add("/api/SearchOnly/{text}", (HttpAction)SearchOnly);
Route.Add("/api/Search/{text}", (HttpAction)Search);
+ Route.Add("/api/SearchPage/", SearchPage);
+ Route.Add("/api/SearchPage/{query}",SearchPage);
+ Route.Add("/api/SearchPage/",SearchPage,"POST");
Route.Add("/api/SearchVideos/", (HttpAction)SearchVideos,"POST");
Route.Add("/api/SearchVideos/{query}", (HttpAction)SearchVideos, "GET");
Route.Add("/api/SearchVideos/", (HttpAction)SearchVideos, "GET");
/* Channel */
- Route.Add("/api/AddChannelOnly/{Id}", (HttpAction)AddChannelOnly);
+ Route.Add("/api/AddChannelOnly/{Id}", AddChannelOnly);
Route.Add("/api/AddChannel/{Id}", (HttpAction)AddChannel);
Route.Add("/api/AddChannelRes/{R}/{Id}", (HttpAction)AddChannelRes);
/* User */
- Route.Add("/api/AddUserOnly/{Id}", (HttpAction)AddUserOnly);
+ Route.Add("/api/AddUserOnly/{Id}", AddUserOnly);
Route.Add("/api/AddUser/{Id}", (HttpAction)AddUser);
Route.Add("/api/AddUserRes/{R}/{Id}", (HttpAction)AddUserRes);
@@ -224,7 +229,7 @@ namespace TYTD
videos.AddEscapedHtml("Description", item.Description);
videos.AddEscapedHtml("UploadDate", DateTime.Parse(item.UploadDate).ToShortDateString());
- string res=ApiLoader.RenderFileOrDefault("WebSite/err/video_list/VideoInfo.html", "
Information about {Title}Video Info for {Title}
Playback: SD HD Audio
Download: SD HD Audio
Video Id: {Id}
Video Channel: {AuthorTitle}
Video Channel Id: {AuthorChannelId}
Likes: {Likes}, Dislikes: {Dislikes}, Views: {Views}
Upload Date: {UploadDate}
Duration: {DurationStringLong}
Description:
{Description}
", videos);
+ string res=ApiLoader.RenderFileOrDefault("WebSite/err/video_list/VideoInfo.html", "Information about {Title}Video Info for {Title}
Playback: SD HD Audio
Download: SD HD Audio
Add To Server: SD HD Audio
Video Id: {Id}
Video Channel: {AuthorTitle}
Video Channel Id: {AuthorChannelId}
Likes: {Likes}, Dislikes: {Dislikes}, Views: {Views}
Upload Date: {UploadDate}
Duration: {DurationStringLong}
Description:
{Description}
", videos);
response.AsText(res);
}
else
@@ -234,9 +239,9 @@ namespace TYTD
}
- public static void AddVideoInfo(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
+ public static async Task AddVideoInfo(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
{
- Downloader.DownloadVideoInfo(System.Web.HttpUtility.UrlDecode(args["Id"]), Resolution.NoConvert);
+ await Downloader.DownloadVideoInfo(System.Web.HttpUtility.UrlDecode(args["Id"]), Resolution.NoConvert);
rq.RedirectIt(rp);
}
@@ -282,9 +287,9 @@ namespace TYTD
}
#endregion
#region Playlist
- public static void AddPlaylistOnly(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
+ public static async Task AddPlaylistOnly(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
{
- Downloader.DownloadPlaylistOnly(System.Web.HttpUtility.UrlDecode(args["Id"]), Resolution.NoConvert);
+ await Downloader.DownloadPlaylistOnly(System.Web.HttpUtility.UrlDecode(args["Id"]), Resolution.NoConvert);
rq.RedirectIt(rp);
}
@@ -429,7 +434,7 @@ namespace TYTD
}
public static void ListPlaylists(HttpListenerRequest request,HttpListenerResponse resp,Dictionary args)
{
- string htmlBeforeProcessed = ApiLoader.ReadAllTextOrDefault("WebSite/err/playlist_list/element.html", " | {Title}{AuthorTitle} |
");
+ string htmlBeforeProcessed = ApiLoader.ReadAllTextOrDefault("WebSite/err/playlist_list/element.html", " | {Title}{AuthorTitle} |
");
StringBuilder builder = new StringBuilder();
foreach (var f in Directory.EnumerateFiles("Playlist","*.json"))
{
@@ -472,9 +477,14 @@ namespace TYTD
StringBuilder builder = new StringBuilder();
foreach (var v in plitem.Videos)
{
+ string path = Path.Combine("Info", $"{v}.json");
+ if (!File.Exists(path))
+ {
+ continue;
+ }
try
{
- var item = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine("Info", $"{v}.json")));
+ var item = JsonConvert.DeserializeObject(File.ReadAllText(path));
Dictionary videos = new Dictionary();
videos.AddEscapedHtml("Title", item.Title);
videos.AddEscapedHtml("Id", item.Id);
@@ -528,6 +538,86 @@ namespace TYTD
rp.AsText(json, "application/json");
}
+ public static async Task SearchPage(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
+ {
+ if (rq.HttpMethod == "POST")
+ {
+ rq.ParseBody(args);
+ }
+ string search = "";
+ if (args.ContainsKey("query"))
+ {
+ search = System.Web.HttpUtility.UrlDecode(args["query"]);
+
+ }
+ try
+ {
+ string htmlBeforeProcessedPlaylist = ApiLoader.ReadAllTextOrDefault("WebSite/err/playlist_list/element.html", " | {Title}{AuthorTitle} |
");
+ string htmlBeforeProcessedVideo = ApiLoader.ReadAllTextOrDefault("WebSite/err/video_list/element.html", " | {Title}{AuthorTitle} |
");
+
+ StringBuilder builder = new StringBuilder();
+ await Downloader.GetClient().Search.GetResultsAsync(search).ForEachAsync(async (e) =>
+ {
+
+ var video = e as VideoSearchResult;
+ var playlist = e as PlaylistSearchResult;
+ var channel = e as ChannelSearchResult;
+ if (video != null)
+ {
+ await Downloader.DownloadVideoInfo(video.Id, Resolution.NoConvert);
+ string path = Path.Combine("Info", $"{video.Id.Value}.json");
+ var item = JsonConvert.DeserializeObject(File.ReadAllText(path));
+ Dictionary videos = new Dictionary();
+ videos.AddEscapedHtml("Title", item.Title);
+ videos.AddEscapedHtml("Id", item.Id);
+ videos.AddEscapedHtml("AuthorTitle", item.AuthorTitle);
+ videos.AddEscapedHtml("AuthorChannelId", item.AuthorChannelId);
+ videos.AddEscapedHtml("DurationStringLong", TimeSpan.FromSeconds(item.Duration).ToString());
+ videos.AddEscapedHtml("DurationNumber", item.Duration.ToString());
+ videos.AddEscapedHtml("Likes", item.Likes.ToString());
+ videos.AddEscapedHtml("Dislikes", item.Dislikes.ToString());
+ videos.AddEscapedHtml("Views", item.Views.ToString());
+
+ videos.AddEscapedHtml("Description", item.Description);
+ videos.AddEscapedHtml("UploadDate", DateTime.Parse(item.UploadDate).ToShortDateString());
+ builder.Append(Templating.RenderString(htmlBeforeProcessedVideo, videos));
+
+ }
+ if (playlist != null)
+ {
+ await Downloader.DownloadPlaylistOnly(playlist.Id, Resolution.NoConvert);
+
+ Dictionary playlist0 = new Dictionary();
+ var plitem = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine("Playlist", $"{playlist.Id.Value}.json")));
+
+ playlist0.AddEscapedHtml("Title", plitem.Title);
+ playlist0.AddEscapedHtml("Id", plitem.Id);
+ playlist0.AddEscapedHtml("AuthorTitle", plitem.AuthorTitle);
+ playlist0.AddEscapedHtml("AuthorChannelId", plitem.AuthorChannelId);
+ playlist0.AddEscapedHtml("Description", plitem.Description);
+ playlist0.AddEscapedHtml("FirstVideoId", plitem.Videos[0]);
+ string res0 = Templating.RenderString(htmlBeforeProcessedPlaylist, playlist0);
+ builder.Append(res0);
+ }
+ if(channel !=null)
+ {
+ await Downloader.DownloadChannelOnly(channel.Id);
+
+ }
+
+ });
+ //string res = ApiLoader.RenderFileOrDefault(, "All PlaylistsAll Playlists
", main);
+ Dictionary data = new Dictionary();
+ data.Add("Elements", builder.ToString());
+
+ string html = ApiLoader.RenderFileOrDefault("WebSite/err/search_main.html", "Search Online\n", data);
+ rp.AsText(html, "text/html");
+ }
+ catch (Exception ex)
+ {
+ _ = ex;
+ }
+ }
public static void SearchVideos(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
{
if(rq.HttpMethod == "POST")
@@ -537,11 +627,11 @@ namespace TYTD
string search = "*";
if (args.ContainsKey("query"))
{
- System.Web.HttpUtility.UrlDecode(args["query"]);
+ search= System.Web.HttpUtility.UrlDecode(args["query"]);
}
StringBuilder innerHtml = new StringBuilder();
- string htmlBeforeProcessed = ApiLoader.ReadAllTextOrDefault("WebSite/err/video_list/element.html", " | {Title}{AuthorTitle} |
");
+ string htmlBeforeProcessed = ApiLoader.ReadAllTextOrDefault("WebSite/err/video_list/element.html", " | {Title}{AuthorTitle} |
");
long i=0;
foreach (var item in Downloader.SearchFor(search))
{
@@ -573,9 +663,9 @@ namespace TYTD
}
#endregion
#region Channel
- public static void AddChannelOnly(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
+ public static async Task AddChannelOnly(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
{
- Downloader.DownloadChannelOnly(System.Web.HttpUtility.UrlDecode(args["Id"]));
+ await Downloader.DownloadChannelOnly(System.Web.HttpUtility.UrlDecode(args["Id"]));
rq.RedirectIt(rp);
@@ -595,9 +685,9 @@ namespace TYTD
}
#endregion
#region User
- public static void AddUserOnly(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
+ public static async Task AddUserOnly(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
{
- Downloader.DownloadUserOnly(System.Web.HttpUtility.UrlDecode(args["Id"]));
+ await Downloader.DownloadUserOnly(System.Web.HttpUtility.UrlDecode(args["Id"]));
rq.RedirectIt(rp);
}
@@ -910,7 +1000,7 @@ namespace TYTD
#region Other
public static void Index(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args)
{
- string r = ApiLoader.ReadAllTextOrDefault(Path.Combine(webSitePath, "index.html"), "TYTDTYTD
Existing Videos:
Get Progress
List Queue
List Playlists
");
+ string r = ApiLoader.ReadAllTextOrDefault(Path.Combine(webSitePath, "index.html"), "TYTDTYTD
Existing Videos:
Get Progress
List Queue
List Playlists
");
rp.AsText( r);
}
diff --git a/TYTD.Api/Server/Functions/Downloader.cs b/TYTD.Api/Server/Functions/Downloader.cs
index d1da04c..64e9b7b 100644
--- a/TYTD.Api/Server/Functions/Downloader.cs
+++ b/TYTD.Api/Server/Functions/Downloader.cs
@@ -149,6 +149,11 @@ namespace TYTD.Server.Functions
static HttpClient Http;
internal YoutubeClient ytc = CreateYoutubeClient();
+
+ public static YoutubeClient GetClient()
+ {
+ return DL.ytc;
+ }
static VideoDownloadProgress P = new VideoDownloadProgress();
const int NUM_WAITS = 5;
static int WAITS = 0;
@@ -391,16 +396,13 @@ namespace TYTD.Server.Functions
}
}
- public static void DownloadChannelOnly(string id)
+ public static async Task DownloadChannelOnly(string id)
{
ChannelId? v = ChannelId.TryParse(id);
if (v.HasValue)
{
InfomationQueueItem item = new InfomationQueueItem(v.Value, Resolution.NoConvert, false);
- lock (DL.infoQueue)
- {
- DL.infoQueue.Insert(0, item);
- }
+ await item.DownloadData();
}
}
public static void DownloadItems(List id)
@@ -423,16 +425,13 @@ namespace TYTD.Server.Functions
}
}
}
- public static void DownloadUserOnly(string id)
+ public static async Task DownloadUserOnly(string id)
{
UserName? v = UserName.TryParse(id);
if (v.HasValue)
{
InfomationQueueItem item = new InfomationQueueItem(v.Value, Resolution.NoConvert, false);
- lock (DL.infoQueue)
- {
- DL.infoQueue.Insert(0, item);
- }
+ await item.DownloadData();
}
}
@@ -1221,16 +1220,13 @@ namespace TYTD.Server.Functions
}
}
}
- public static void DownloadVideoInfo(string id, Resolution res)
+ public static async Task DownloadVideoInfo(string id, Resolution res)
{
VideoId? v = VideoId.TryParse(id);
if (v.HasValue)
{
InfomationQueueItem item = new InfomationQueueItem(v.Value, res, false);
- lock (DL.infoQueue)
- {
- DL.infoQueue.Insert(0, item);
- }
+ await item.DownloadData();
}
}
@@ -1262,16 +1258,14 @@ namespace TYTD.Server.Functions
}
}
}
- public static void DownloadPlaylistOnly(string id, Resolution res)
+ public static async Task DownloadPlaylistOnly(string id, Resolution res)
{
PlaylistId? v = PlaylistId.TryParse(id);
if (v.HasValue)
{
InfomationQueueItem item = new InfomationQueueItem(v.Value, res, false);
- lock (DL.infoQueue)
- {
- DL.infoQueue.Insert(0, item);
- }
+
+ await item.DownloadData();
}
}
public static void DownloadPlaylist(string id)
diff --git a/TYTD.Api/bin/Release/TYTD.Api.dll b/TYTD.Api/bin/Release/TYTD.Api.dll
index a74b7f2..c42bd75 100644
Binary files a/TYTD.Api/bin/Release/TYTD.Api.dll and b/TYTD.Api/bin/Release/TYTD.Api.dll differ
diff --git a/TYTD.Api/obj/Release/TYTD.Api.dll b/TYTD.Api/obj/Release/TYTD.Api.dll
index a74b7f2..c42bd75 100644
Binary files a/TYTD.Api/obj/Release/TYTD.Api.dll and b/TYTD.Api/obj/Release/TYTD.Api.dll differ
diff --git a/bin/Release/TYTD.Api.dll b/bin/Release/TYTD.Api.dll
index a74b7f2..c42bd75 100644
Binary files a/bin/Release/TYTD.Api.dll and b/bin/Release/TYTD.Api.dll differ
diff --git a/bin/Release/youtube-downloader.exe b/bin/Release/youtube-downloader.exe
index 2f877c7..ff7b008 100644
Binary files a/bin/Release/youtube-downloader.exe and b/bin/Release/youtube-downloader.exe differ
diff --git a/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache b/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache
index 1cba76e..2871d8b 100644
Binary files a/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache and b/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache differ
diff --git a/obj/x86/Release/youtube-downloader.exe b/obj/x86/Release/youtube-downloader.exe
index 2f877c7..ff7b008 100644
Binary files a/obj/x86/Release/youtube-downloader.exe and b/obj/x86/Release/youtube-downloader.exe differ