This commit is contained in:
Mike Nolan 2023-02-16 08:48:50 -06:00
parent 6a403b7d15
commit 4a03e3398e
12 changed files with 473 additions and 635 deletions

View File

@ -1,22 +0,0 @@
Copyright (c) 2008-2011, Kenneth Bell
Copyright (c) 2014, Quamotion
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
DiscUtils: https://github.com/DiscUtils/DiscUtils

View File

@ -1,26 +0,0 @@
The MIT License (MIT)
Copyright (c) Darko Jurić
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Licensing for JSON.NET dependency also applies: https://www.newtonsoft.com/json
Licensing for SimpleHttp also applies: https://github.com/dajuric/simple-http
I Used same license hince I used some of dajurics code in Tesses.WebServer

View File

@ -1,25 +0,0 @@
Copyright (c) 2017-2022, Alexandre Mutel
All rights reserved.
Redistribution and use in source and binary forms, with or without modification
, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Zio: https://github.com/xoofx/zio

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ namespace Tesses.YouTubeDownloader.Net6
server.RootServer.Server=new StaticServer("WebSite"); server.RootServer.Server=new StaticServer("WebSite");
currentDirectory.CanDownload=true; currentDirectory.CanDownload=true;
HttpServerListener listener=new HttpServerListener(new System.Net.IPEndPoint(System.Net.IPAddress.Any,3252),server.InnerServer); HttpServerListener listener=new HttpServerListener(new System.Net.IPEndPoint(System.Net.IPAddress.Any,3252),server.InnerServer);
currentDirectory.CanDownload=false;
currentDirectory.StartLoop(); currentDirectory.StartLoop();
TYTDStorage.FFmpeg ="/usr/bin/ffmpeg"; TYTDStorage.FFmpeg ="/usr/bin/ffmpeg";
Console.WriteLine("Almost Ready to Listen"); Console.WriteLine("Almost Ready to Listen");

View File

@ -131,10 +131,11 @@ namespace Tesses.YouTubeDownloader
{ {
begin_download: begin_download:
//await Task.Delay(this.GetLoggerProperties().DownloadMediaDelay);
try{ try{
if(video.DownloadFrom == "YouTube") if(video.DownloadFrom == "YouTube")
{ {
switch (resolution) switch (resolution)
{ {
case Resolution.Mux: case Resolution.Mux:

View File

@ -15,7 +15,10 @@ namespace Tesses.YouTubeDownloader
{ {
public interface ITYTDBase : IPersonalPlaylistGet public interface ITYTDBase : IPersonalPlaylistGet
{ {
Task<bool> BestStreamInfoExistsAsync(VideoId id);
Task<bool> VideoInfoExistsAsync(VideoId id);
Task<bool> PlaylistInfoExistsAsync(PlaylistId id);
Task<bool> ChannelInfoExistsAsync(ChannelId id);
Task<bool> ThumbnailExistsAsync(VideoId videoId,string res); Task<bool> ThumbnailExistsAsync(VideoId videoId,string res);
bool ThumbnailExists(VideoId videoId,string res); bool ThumbnailExists(VideoId videoId,string res);
Task<byte[]> ReadThumbnailAsync(VideoId videoId,string res,CancellationToken token=default); Task<byte[]> ReadThumbnailAsync(VideoId videoId,string res,CancellationToken token=default);

View File

@ -111,11 +111,16 @@ namespace Tesses.YouTubeDownloader
public bool AddDateInLog {get;set;} public bool AddDateInLog {get;set;}
public bool LogEntriesRightWhenAdded {get;set;}=true;
//public TimeSpan DownloadMediaDelay {get;set;}=new TimeSpan(0,0,5);
//public TimeSpan GetInfoDelay {get;set;}=new TimeSpan(0,0,5);
} }
public class Logger public class Logger
{ {
private string _video_log_file;
private string _filename; private string _filename;
private TYTDStorage _storage; private TYTDStorage _storage;
@ -126,8 +131,9 @@ namespace Tesses.YouTubeDownloader
_storage=storage; _storage=storage;
string dateTime = DateTime.Now.ToString("yyyyMMdd_hhmmss"); string dateTime = DateTime.Now.ToString("yyyyMMdd_HHmmss");
_filename = $"config/logs/{dateTime}.log"; _filename = $"config/logs/{dateTime}.log";
_video_log_file = $"config/addlog/{dateTime}.log";
} }
private void WriteStdErr(string message) private void WriteStdErr(string message)
{ {
@ -162,6 +168,30 @@ namespace Tesses.YouTubeDownloader
Write(message,writeToConsole,isError,log); Write(message,writeToConsole,isError,log);
}); });
} }
public void WriteVideoLog(string url)
{
if(!_storage.GetLoggerProperties().LogEntriesRightWhenAdded) return;
lock(TYTDStorage.o){
try{
using(var strm = _storage.OpenOrCreateAsync(_video_log_file).GetAwaiter().GetResult())
{
if(!strm.CanSeek) return;
strm.Seek(0,SeekOrigin.End);
using(var sw = new StreamWriter(strm))
{
DateTime dat=DateTime.Now;
sw.WriteLine($"[{dat.ToShortDateString()} at {dat.ToLongTimeString()}]: {url}");
}
} }
catch(Exception ex)
{
_=ex;
}
//mtx.ReleaseMutex();
}
}
public void Write(string message,bool writeToConsole=false, bool isError=false,bool log=true) public void Write(string message,bool writeToConsole=false, bool isError=false,bool log=true)
{ {

View File

@ -153,6 +153,7 @@ namespace Tesses.YouTubeDownloader
{ {
lock(Temporary) lock(Temporary)
{ {
GetLogger().WriteVideoLog($"https://www.youtube.com/playlist?list={id.Value}");
Temporary.Add( new PlaylistMediaContext(id,resolution)); Temporary.Add( new PlaylistMediaContext(id,resolution));
} }
@ -163,6 +164,7 @@ namespace Tesses.YouTubeDownloader
{ {
lock(Temporary) lock(Temporary)
{ {
GetLogger().WriteVideoLog($"https://www.youtube.com/channel/{id.Value}");
Temporary.Add(new ChannelMediaContext(id,resolution)); Temporary.Add(new ChannelMediaContext(id,resolution));
} }
await Task.FromResult(0); await Task.FromResult(0);
@ -171,6 +173,8 @@ namespace Tesses.YouTubeDownloader
{ {
lock(Temporary) lock(Temporary)
{ {
GetLogger().WriteVideoLog($"https://www.youtube.com/c/{slug.Value}");
Temporary.Add(new ChannelMediaContext(slug,resolution)); Temporary.Add(new ChannelMediaContext(slug,resolution));
} }
await Task.FromResult(0); await Task.FromResult(0);
@ -179,6 +183,7 @@ namespace Tesses.YouTubeDownloader
{ {
lock(Temporary) lock(Temporary)
{ {
GetLogger().WriteVideoLog($"https://www.youtube.com/@{handle.Value}");
Temporary.Add(new ChannelMediaContext(handle,resolution)); Temporary.Add(new ChannelMediaContext(handle,resolution));
} }
await Task.FromResult(0); await Task.FromResult(0);
@ -187,6 +192,7 @@ namespace Tesses.YouTubeDownloader
{ {
lock(Temporary) lock(Temporary)
{ {
GetLogger().WriteVideoLog($"https://www.youtube.com/user/{name.Value}");
Temporary.Add(new ChannelMediaContext(name,resolution)); Temporary.Add(new ChannelMediaContext(name,resolution));
} }
await Task.FromResult(0); await Task.FromResult(0);
@ -196,6 +202,7 @@ namespace Tesses.YouTubeDownloader
{ {
lock(Temporary) lock(Temporary)
{ {
GetLogger().WriteVideoLog($"https://www.youtube.com/watch?v={videoId.Value}");
Temporary.Add(new VideoMediaContext(videoId,res)); Temporary.Add(new VideoMediaContext(videoId,res));
} }
await Task.FromResult(0); await Task.FromResult(0);
@ -204,6 +211,7 @@ namespace Tesses.YouTubeDownloader
{ {
lock(Temporary) lock(Temporary)
{ {
GetLogger().WriteVideoLog(url);
Temporary.Add(new NormalDownloadMediaContext(url,download)); Temporary.Add(new NormalDownloadMediaContext(url,download));
} }
await Task.FromResult(0); await Task.FromResult(0);
@ -240,7 +248,7 @@ namespace Tesses.YouTubeDownloader
CreateDirectoryIfNotExist("Channel"); CreateDirectoryIfNotExist("Channel");
CreateDirectoryIfNotExist("Playlist"); CreateDirectoryIfNotExist("Playlist");
CreateDirectoryIfNotExist("Subscriptions"); CreateDirectoryIfNotExist("Subscriptions");
CreateDirectoryIfNotExist("VideoOnly"); CreateDirectoryIfNotExist("VideoOnly");
CreateDirectoryIfNotExist("AudioOnly"); CreateDirectoryIfNotExist("AudioOnly");
CreateDirectoryIfNotExist("Muxed"); CreateDirectoryIfNotExist("Muxed");
CreateDirectoryIfNotExist("PreMuxed"); CreateDirectoryIfNotExist("PreMuxed");
@ -248,13 +256,16 @@ namespace Tesses.YouTubeDownloader
CreateDirectoryIfNotExist("Thumbnails"); CreateDirectoryIfNotExist("Thumbnails");
CreateDirectoryIfNotExist("config"); CreateDirectoryIfNotExist("config");
CreateDirectoryIfNotExist("config/logs"); CreateDirectoryIfNotExist("config/logs");
CreateDirectoryIfNotExist("config/addlog");
CreateDirectoryIfNotExist("DownloadsInfo"); CreateDirectoryIfNotExist("DownloadsInfo");
CreateDirectoryIfNotExist("Downloads"); CreateDirectoryIfNotExist("Downloads");
CreateDirectoryIfNotExist("StreamInfo"); CreateDirectoryIfNotExist("StreamInfo");
CreateDirectoryIfNotExist("PersonalPlaylist"); CreateDirectoryIfNotExist("PersonalPlaylist");
} }
public void StartLoop(CancellationToken token = default(CancellationToken)) public void StartLoop(CancellationToken token = default(CancellationToken))
{ {
CreateDirectories(); CreateDirectories();
if(DirectoryExists("Download") && DirectoryExists("FileInfo")) if(DirectoryExists("Download") && DirectoryExists("FileInfo"))
Task.Run(MigrateDownloads).Wait(); Task.Run(MigrateDownloads).Wait();

View File

@ -40,9 +40,13 @@ namespace Tesses.YouTubeDownloader
{ {
return FileExists($"PersonalPlaylist/{name}.json"); return FileExists($"PersonalPlaylist/{name}.json");
} }
public virtual async Task<bool> PersonalPlaylistExistsAsync(string name)
{
return await FileExistsAsync($"PersonalPlaylist/{name}.json");
}
public virtual async IAsyncEnumerable<ListContentItem> GetPersonalPlaylistContentsAsync(string playlist) public virtual async IAsyncEnumerable<ListContentItem> GetPersonalPlaylistContentsAsync(string playlist)
{ {
if(!PersonalPlaylistExists(playlist)) yield break; if(!await PersonalPlaylistExistsAsync(playlist)) yield break;
var ls=JsonConvert.DeserializeObject<List<ListContentItem>>(await ReadAllTextAsync($"PersonalPlaylist/{playlist}.json")); var ls=JsonConvert.DeserializeObject<List<ListContentItem>>(await ReadAllTextAsync($"PersonalPlaylist/{playlist}.json"));
foreach(var item in ls) foreach(var item in ls)
{ {
@ -220,6 +224,10 @@ namespace Tesses.YouTubeDownloader
public virtual bool BestStreamInfoExists(VideoId id) public virtual bool BestStreamInfoExists(VideoId id)
{ {
return FileExists($"StreamInfo/{id.Value}.json"); return FileExists($"StreamInfo/{id.Value}.json");
}
public virtual async Task<bool> BestStreamInfoExistsAsync(VideoId id)
{
return await FileExistsAsync($"StreamInfo/{id.Value}.json");
} }
public virtual async Task<SavedVideo> GetDownloadInfoAsync(string url) public virtual async Task<SavedVideo> GetDownloadInfoAsync(string url)
{ {
@ -236,7 +244,12 @@ namespace Tesses.YouTubeDownloader
return B64.Base64UrlEncode(sha1.ComputeHash(Encoding.UTF8.GetBytes(url))); return B64.Base64UrlEncode(sha1.ComputeHash(Encoding.UTF8.GetBytes(url)));
} }
} }
public virtual async Task<bool> DownloadExistsAsync(string url)
{
string enc=$"DownloadsInfo/{HashDownloadUrl(url)}.json";
return await FileExistsAsync(enc);
}
public virtual bool DownloadExists(string url) public virtual bool DownloadExists(string url)
{ {
string enc=$"DownloadsInfo/{HashDownloadUrl(url)}.json"; string enc=$"DownloadsInfo/{HashDownloadUrl(url)}.json";
@ -247,14 +260,26 @@ namespace Tesses.YouTubeDownloader
{ {
return FileExists($"Playlist/{id}.json"); return FileExists($"Playlist/{id}.json");
} }
public virtual async Task<bool> PlaylistInfoExistsAsync(PlaylistId id)
{
return await FileExistsAsync($"Playlist/{id}.json");
}
public virtual bool VideoInfoExists(VideoId id) public virtual bool VideoInfoExists(VideoId id)
{ {
return FileExists($"Info/{id}.json"); return FileExists($"Info/{id}.json");
} }
public virtual async Task<bool> VideoInfoExistsAsync(VideoId id)
{
return await FileExistsAsync($"Info/{id}.json");
}
public virtual bool ChannelInfoExists(ChannelId id) public virtual bool ChannelInfoExists(ChannelId id)
{ {
return FileExists($"Channel/{id}.json"); return FileExists($"Channel/{id}.json");
} }
public virtual async Task<bool> ChannelInfoExistsAsync(ChannelId id)
{
return await FileExistsAsync($"Channel/{id}.json");
}
public virtual async Task<SavedPlaylist> GetPlaylistInfoAsync(PlaylistId id) public virtual async Task<SavedPlaylist> GetPlaylistInfoAsync(PlaylistId id)
{ {
return JsonConvert.DeserializeObject<SavedPlaylist>(await ReadAllTextAsync($"Playlist/{id}.json")); return JsonConvert.DeserializeObject<SavedPlaylist>(await ReadAllTextAsync($"Playlist/{id}.json"));
@ -920,6 +945,7 @@ namespace Tesses.YouTubeDownloader
ExtraData GetExtraData(); ExtraData GetExtraData();
IAsyncEnumerable<ListContentItem> GetPersonalPlaylistContentsAsync(string name); IAsyncEnumerable<ListContentItem> GetPersonalPlaylistContentsAsync(string name);
bool PersonalPlaylistExists(string name); bool PersonalPlaylistExists(string name);
Task<bool> PersonalPlaylistExistsAsync(string name);
} }
public interface IPersonalPlaylistSet : IPersonalPlaylistGet public interface IPersonalPlaylistSet : IPersonalPlaylistGet
{ {

View File

@ -947,7 +947,34 @@ namespace Tesses.YouTubeDownloader
return exists; return exists;
} }
public async Task<bool> VideoInfoExistsAsync(VideoId id)
{
if(Storage ==null) return await Task.FromResult(false);
return await Storage.VideoInfoExistsAsync(id);
}
public async Task<bool> PlaylistInfoExistsAsync(PlaylistId id)
{
if(Storage ==null) return await Task.FromResult(false);
return await Storage.PlaylistInfoExistsAsync(id);
}
public async Task<bool> ChannelInfoExistsAsync(ChannelId id)
{
if(Storage ==null) return await Task.FromResult(false);
return await Storage.ChannelInfoExistsAsync(id);
}
public async Task<bool> PersonalPlaylistExistsAsync(string name)
{
if(Storage ==null) return await Task.FromResult(false);
return await Storage.PersonalPlaylistExistsAsync(name);
}
public async Task<bool> BestStreamInfoExistsAsync(VideoId id)
{
if(Storage ==null) return await Task.FromResult(false);
return await Storage.BestStreamInfoExistsAsync(id);
}
} }
public class DownloaderMigration public class DownloaderMigration

View File

@ -7,11 +7,11 @@
<PackageId>Tesses.YouTubeDownloader</PackageId> <PackageId>Tesses.YouTubeDownloader</PackageId>
<Author>Mike Nolan</Author> <Author>Mike Nolan</Author>
<Company>Tesses</Company> <Company>Tesses</Company>
<Version>2.0.1</Version> <Version>2.0.2</Version>
<AssemblyVersion>2.0.1</AssemblyVersion> <AssemblyVersion>2.0.2</AssemblyVersion>
<FileVersion>2.0.1</FileVersion> <FileVersion>2.0.2</FileVersion>
<Description>A YouTube Downloader</Description> <Description>A YouTube Downloader</Description>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression> <PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>YoutubeExplode, YouTube, YouTubeDownloader</PackageTags> <PackageTags>YoutubeExplode, YouTube, YouTubeDownloader</PackageTags>
<RepositoryUrl>https://gitlab.tesses.cf/tesses50/tytd</RepositoryUrl> <RepositoryUrl>https://gitlab.tesses.cf/tesses50/tytd</RepositoryUrl>