add search and video resume
This commit is contained in:
parent
f336b73b68
commit
6760089173
Binary file not shown.
|
@ -34,6 +34,13 @@ namespace youtube_downloader
|
||||||
{
|
{
|
||||||
rp.AsFile(rq, Path.Combine(webSitePath, "index.html"));
|
rp.AsFile(rq, Path.Combine(webSitePath, "index.html"));
|
||||||
});
|
});
|
||||||
|
Route.Add("/api/Search/{text}", (rq, rp, args) =>
|
||||||
|
{
|
||||||
|
string search=System.Web.HttpUtility.UrlDecode(args["text"]);
|
||||||
|
string json = JsonConvert.SerializeObject(Server.Functions.Downloader.Search(search));
|
||||||
|
rp.AsText(json, "application/json");
|
||||||
|
|
||||||
|
});
|
||||||
Route.Add("/api/Storage/GetDirectories/{Path}", (rq, rp, args) =>
|
Route.Add("/api/Storage/GetDirectories/{Path}", (rq, rp, args) =>
|
||||||
{
|
{
|
||||||
string path = Server.Functions.Downloader.DL.GetPath(true, args["Path"]);
|
string path = Server.Functions.Downloader.DL.GetPath(true, args["Path"]);
|
||||||
|
@ -62,6 +69,7 @@ namespace youtube_downloader
|
||||||
rp.AsText("[]", "application/json");
|
rp.AsText("[]", "application/json");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Route.Add("/api/Storage/FileExists/{Path}", (rq, rp, args) =>
|
Route.Add("/api/Storage/FileExists/{Path}", (rq, rp, args) =>
|
||||||
{
|
{
|
||||||
string path = Server.Functions.Downloader.DL.GetPath(true, args["Path"]);
|
string path = Server.Functions.Downloader.DL.GetPath(true, args["Path"]);
|
||||||
|
|
|
@ -282,6 +282,8 @@ namespace youtube_downloader.Server.Functions
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canDownload)
|
if (canDownload)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
switch (v.Resolution)
|
switch (v.Resolution)
|
||||||
{
|
{
|
||||||
|
@ -303,12 +305,74 @@ namespace youtube_downloader.Server.Functions
|
||||||
var best = s3.GetVideoOnlyStreams().GetWithHighestVideoQuality();
|
var best = s3.GetVideoOnlyStreams().GetWithHighestVideoQuality();
|
||||||
P.Length = best.Size.Bytes + best2.Size.Bytes;
|
P.Length = best.Size.Bytes + best2.Size.Bytes;
|
||||||
ProgressTwo p = new ProgressTwo(best.Size.Bytes, best2.Size.Bytes, DownloadP);
|
ProgressTwo p = new ProgressTwo(best.Size.Bytes, best2.Size.Bytes, DownloadP);
|
||||||
await ytc.Videos.Streams.DownloadAsync(best,mypath, p.Video);
|
|
||||||
|
using (var destStrm = System.IO.File.Open(mypath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
||||||
|
{
|
||||||
|
long pos = 0;
|
||||||
|
long len = 0;
|
||||||
|
using (var srcStrm = await ytc.Videos.Streams.GetAsync(best))
|
||||||
|
{
|
||||||
|
len = srcStrm.Length;
|
||||||
|
pos = destStrm.Length;
|
||||||
|
IProgress<double> myProgress = p.Video;
|
||||||
|
if (pos >= len)
|
||||||
|
{
|
||||||
|
|
||||||
|
myProgress.Report(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
srcStrm.Seek(destStrm.Length, SeekOrigin.Begin);
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int read = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
read = srcStrm.Read(buffer, 0, buffer.Length);
|
||||||
|
destStrm.Write(buffer, 0, read);
|
||||||
|
|
||||||
|
pos += read;
|
||||||
|
double myP = (double)pos / (double)len;
|
||||||
|
myProgress.Report(myP);
|
||||||
|
}
|
||||||
|
while (read > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
IProgress<double> pv = p.Video;
|
IProgress<double> pv = p.Video;
|
||||||
pv.Report(1);
|
pv.Report(1);
|
||||||
if (Continue(mypathCompleteAudio))
|
if (Continue(mypathCompleteAudio))
|
||||||
{
|
{
|
||||||
await ytc.Videos.Streams.DownloadAsync(best2, mypathaudio,p.Audio);
|
long pos = 0;
|
||||||
|
long len = 0;
|
||||||
|
using (var destStrm = System.IO.File.Open(mypathaudio, FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
||||||
|
{
|
||||||
|
using (var srcStrm = await ytc.Videos.Streams.GetAsync(best2))
|
||||||
|
{
|
||||||
|
len = srcStrm.Length;
|
||||||
|
pos = destStrm.Length;
|
||||||
|
IProgress<double> myProgress = p.Audio;
|
||||||
|
if (pos >= len)
|
||||||
|
{
|
||||||
|
|
||||||
|
myProgress.Report(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
srcStrm.Seek(destStrm.Length, SeekOrigin.Begin);
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int read = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
read = srcStrm.Read(buffer, 0, buffer.Length);
|
||||||
|
destStrm.Write(buffer, 0, read);
|
||||||
|
|
||||||
|
pos += read;
|
||||||
|
double myP = (double)pos / (double)len;
|
||||||
|
myProgress.Report(myP);
|
||||||
|
}
|
||||||
|
while (read > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
File.Move(mypathaudio, mypathCompleteAudio);
|
File.Move(mypathaudio, mypathCompleteAudio);
|
||||||
}
|
}
|
||||||
IProgress<double> pa = p.Video;
|
IProgress<double> pa = p.Video;
|
||||||
|
@ -328,8 +392,37 @@ namespace youtube_downloader.Server.Functions
|
||||||
var s = await ytc.Videos.Streams.GetManifestAsync(v.Video.Id);
|
var s = await ytc.Videos.Streams.GetManifestAsync(v.Video.Id);
|
||||||
var best = s.GetMuxedStreams().GetWithHighestVideoQuality();
|
var best = s.GetMuxedStreams().GetWithHighestVideoQuality();
|
||||||
P.Length = best.Size.Bytes;
|
P.Length = best.Size.Bytes;
|
||||||
|
long pos = 0;
|
||||||
|
long len = 0;
|
||||||
|
using (var destStrm = System.IO.File.Open(mypath2, FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
||||||
|
{
|
||||||
|
using (var srcStrm = await ytc.Videos.Streams.GetAsync(best))
|
||||||
|
{
|
||||||
|
len = srcStrm.Length;
|
||||||
|
pos = destStrm.Length;
|
||||||
|
IProgress<double> myProgress = DownloadP;
|
||||||
|
if (pos >= len)
|
||||||
|
{
|
||||||
|
|
||||||
await ytc.Videos.Streams.DownloadAsync(best, mypath2, DownloadP);
|
myProgress.Report(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
srcStrm.Seek(destStrm.Length, SeekOrigin.Begin);
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int read = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
read = srcStrm.Read(buffer, 0, buffer.Length);
|
||||||
|
destStrm.Write(buffer, 0, read);
|
||||||
|
|
||||||
|
pos += read;
|
||||||
|
double myP = (double)pos / (double)len;
|
||||||
|
myProgress.Report(myP);
|
||||||
|
}
|
||||||
|
while (read > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
File.Move(mypath2, mypath2Complete);
|
File.Move(mypath2, mypath2Complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,11 +436,45 @@ namespace youtube_downloader.Server.Functions
|
||||||
var s2 = await ytc.Videos.Streams.GetManifestAsync(v.Video.Id);
|
var s2 = await ytc.Videos.Streams.GetManifestAsync(v.Video.Id);
|
||||||
var best2 = s2.GetAudioOnlyStreams().GetWithHighestBitrate();
|
var best2 = s2.GetAudioOnlyStreams().GetWithHighestBitrate();
|
||||||
P.Length = best2.Size.Bytes;
|
P.Length = best2.Size.Bytes;
|
||||||
await ytc.Videos.Streams.DownloadAsync(best2, mypath3, DownloadP);
|
long pos = 0;
|
||||||
|
long len = 0;
|
||||||
|
using (var destStrm = System.IO.File.Open(mypath3, FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
||||||
|
{
|
||||||
|
using (var srcStrm = await ytc.Videos.Streams.GetAsync(best2))
|
||||||
|
{
|
||||||
|
len = srcStrm.Length;
|
||||||
|
pos = destStrm.Length;
|
||||||
|
IProgress<double> myProgress = DownloadP;
|
||||||
|
if (pos >= len)
|
||||||
|
{
|
||||||
|
|
||||||
|
myProgress.Report(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
srcStrm.Seek(destStrm.Length, SeekOrigin.Begin);
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int read = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
read = srcStrm.Read(buffer, 0, buffer.Length);
|
||||||
|
destStrm.Write(buffer, 0, read);
|
||||||
|
|
||||||
|
pos += read;
|
||||||
|
double myP = (double)pos / (double)len;
|
||||||
|
myProgress.Report(myP);
|
||||||
|
}
|
||||||
|
while (read > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
File.Move(mypath3, mypath3Complete);
|
File.Move(mypath3, mypath3Complete);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}catch(Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
System.Threading.Thread.Sleep(1);
|
System.Threading.Thread.Sleep(1);
|
||||||
}
|
}
|
||||||
|
@ -370,7 +497,20 @@ namespace youtube_downloader.Server.Functions
|
||||||
_ = ex;
|
_ = ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static async Task<List<SavedMedia>> Search(string text)
|
||||||
|
{
|
||||||
|
List<SavedMedia> media = new List<SavedMedia>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await DL.ytc.Search.GetVideosAsync(text).ForEachAsync((e) => { media.Add(new SavedMedia() { Title = e.Title, Id = e.Id, Kind = InfoType.Video }); });
|
||||||
|
await DL.ytc.Search.GetPlaylistsAsync(text).ForEachAsync((e) => { media.Add(new SavedMedia() { Title = e.Title, Id = e.Id, Kind = InfoType.Playlist }); });
|
||||||
|
await DL.ytc.Search.GetChannelsAsync(text).ForEachAsync((e) => { media.Add(new SavedMedia() { Title = e.Title, Id = e.Id, Kind = InfoType.Channel }); });
|
||||||
|
}catch (Exception ex)
|
||||||
|
{
|
||||||
|
_ = ex;
|
||||||
|
}
|
||||||
|
return media;
|
||||||
|
}
|
||||||
internal static List<SavedVideoObject> GetQueueItems()
|
internal static List<SavedVideoObject> GetQueueItems()
|
||||||
{
|
{
|
||||||
return DL.Queue;
|
return DL.Queue;
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
using TessesYoutubeDownloader.Server.Models;
|
||||||
|
using youtube_downloader.Server.Models;
|
||||||
|
|
||||||
|
namespace youtube_downloader.Server.Functions
|
||||||
|
{
|
||||||
|
|
||||||
|
public class SavedMedia
|
||||||
|
{
|
||||||
|
public InfoType Kind { get; set; }
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,11 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using youtube_downloader.Server.Functions;
|
||||||
|
|
||||||
namespace TessesYoutubeDownloader.Server.Models
|
namespace TessesYoutubeDownloader.Server.Models
|
||||||
{
|
{
|
||||||
class SavedChannel
|
public class SavedChannel
|
||||||
{
|
{
|
||||||
public static SavedChannel FromChannel(YoutubeExplode.Channels.Channel c, Action<int, int, string,string> downloadThumbnail)
|
public static SavedChannel FromChannel(YoutubeExplode.Channels.Channel c, Action<int, int, string,string> downloadThumbnail)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,10 +3,11 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using youtube_downloader.Server.Functions;
|
||||||
|
|
||||||
namespace TessesYoutubeDownloader.Server.Models
|
namespace TessesYoutubeDownloader.Server.Models
|
||||||
{
|
{
|
||||||
class SavedPlaylist
|
public class SavedPlaylist
|
||||||
{
|
{
|
||||||
public static async Task<SavedPlaylist> FromPlaylistId(Resolution res,YoutubeExplode.YoutubeClient ytc,YoutubeExplode.Playlists.PlaylistId id,Action<string,Resolution> addToQueue, Action<int, int, string,string> downloadThumbnail)
|
public static async Task<SavedPlaylist> FromPlaylistId(Resolution res,YoutubeExplode.YoutubeClient ytc,YoutubeExplode.Playlists.PlaylistId id,Action<string,Resolution> addToQueue, Action<int, int, string,string> downloadThumbnail)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using youtube_downloader.Server.Functions;
|
||||||
|
|
||||||
namespace TessesYoutubeDownloader.Server.Models
|
namespace TessesYoutubeDownloader.Server.Models
|
||||||
{
|
{
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
||||||
d24c4380a60b7d95eb6c0794042e9b1bb52b78fb
|
05a58042d13f08ad611e38c9c233d47d4e6ac009
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -133,6 +133,7 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Server\Functions\Downloader.cs" />
|
<Compile Include="Server\Functions\Downloader.cs" />
|
||||||
<Compile Include="Server\Functions\ffmpeg.cs" />
|
<Compile Include="Server\Functions\ffmpeg.cs" />
|
||||||
|
<Compile Include="Server\Functions\SavedMedia.cs" />
|
||||||
<Compile Include="Server\Models\InfomationQueueItem.cs" />
|
<Compile Include="Server\Models\InfomationQueueItem.cs" />
|
||||||
<Compile Include="Server\Models\InfoType.cs" />
|
<Compile Include="Server\Models\InfoType.cs" />
|
||||||
<Compile Include="Server\Models\SavedChannel.cs" />
|
<Compile Include="Server\Models\SavedChannel.cs" />
|
||||||
|
|
Loading…
Reference in New Issue