From 597acb4be507d111ff3115eaad5bd74ea07289de Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Sat, 6 Jul 2024 20:24:58 -0500 Subject: [PATCH] Fixed offline --- .gitlab-ci.yml | 15 +++++++++ TYTDLite/Assets/template.html | 2 +- TYTDLite/Assets/video_download.html | 7 ++++- TYTDLite/Class1.cs | 47 ++++++++++++++++++----------- 4 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..120d8f7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,15 @@ + +stages: + - build + +build: + image: mcr.microsoft.com/dotnet/sdk:8.0 + stage: build + only: + - master + artifacts: + paths: + - publish + script: + - apt install -y make zip tar + - make all \ No newline at end of file diff --git a/TYTDLite/Assets/template.html b/TYTDLite/Assets/template.html index 72db890..cb76bab 100644 --- a/TYTDLite/Assets/template.html +++ b/TYTDLite/Assets/template.html @@ -6,7 +6,7 @@ TYTD Lite - +
diff --git a/TYTDLite/Assets/video_download.html b/TYTDLite/Assets/video_download.html index ff94e55..32e9862 100644 --- a/TYTDLite/Assets/video_download.html +++ b/TYTDLite/Assets/video_download.html @@ -1,6 +1,11 @@ {{if notavailable}}
-

This video is unavailable on YouTube

+

This video is unavailable on YouTube.

+
+{{end}} +{{if offline}} +
+

We can't access YouTube right now.

{{end}} {{if invalidurl}} diff --git a/TYTDLite/Class1.cs b/TYTDLite/Class1.cs index fe65202..0b44a42 100644 --- a/TYTDLite/Class1.cs +++ b/TYTDLite/Class1.cs @@ -142,8 +142,8 @@ server.Server.StartServer(port); var video=VideoId.TryParse(v); if(video.HasValue) { - var (_v,rfy)=await GetSavedVideoAsync(video.Value); - await ctx.SendJsonAsync(new{Video=_v,RemovedFromYouTube=rfy}); + var (_v,rfy,off)=await GetSavedVideoAsync(video.Value); + await ctx.SendJsonAsync(new{Video=_v,RemovedFromYouTube=rfy,Offline=off}); } else await ctx.SendNotFoundAsync(); @@ -220,7 +220,7 @@ server.Server.StartServer(port); await PreformTask(video.Value,res,new Progress(e=>{ })); - var (svideo,_) = await GetSavedVideoAsync(video.Value); + var (svideo,_,_) = await GetSavedVideoAsync(video.Value); switch(res) { @@ -263,10 +263,11 @@ server.Server.StartServer(port); } } - private async Task<(SavedVideo video,bool removedByYt)> GetSavedVideoAsync(VideoId id) + private async Task<(SavedVideo video,bool removedByYt,bool offline)> GetSavedVideoAsync(VideoId id) { string _id = id.Value; bool removedByYt=false; + bool offline=false; SavedVideo video=new SavedVideo(); await LockAsync(async()=>{ var _video=Videos.FindOne(e=>e.VideoId == _id); @@ -299,6 +300,11 @@ server.Server.StartServer(port); _=ex; removedByYt=true; } + catch(Exception ex) + { + _=ex; + offline=true; + } } } else @@ -330,7 +336,7 @@ server.Server.StartServer(port); } } }); - return (video,removedByYt); + return (video,removedByYt,offline); } private async Task DownloadThumbnailsAsync(VideoId id) @@ -647,8 +653,10 @@ server.Server.StartServer(port); { case "PreMuxed": { - var (video,removedByYT) = await GetSavedVideoAsync(id); - + var (video,removedByYT,off) = await GetSavedVideoAsync(id); + if(off && !Directory.Exists(Path.Combine(ServerPath,"PreMuxed")) && !File.Exists(Path.Combine(ServerPath,"PreMuxed",$"{video.VideoId}.{(video.PreMuxed != null ? video.PreMuxed.Container : "mp4")}"))) + throw new VideoUnavailableException("We don't have access to YouTube"); + if(removedByYT && !Directory.Exists(Path.Combine(ServerPath,"PreMuxed")) && !File.Exists(Path.Combine(ServerPath,"PreMuxed",$"{video.VideoId}.{(video.PreMuxed != null ? video.PreMuxed.Container : "mp4")}"))) throw new VideoUnavailableException("We dont have the video either"); @@ -657,8 +665,9 @@ server.Server.StartServer(port); break; case "AudioOnly": { - var (video,removedByYT) = await GetSavedVideoAsync(id); - + var (video,removedByYT,off) = await GetSavedVideoAsync(id); + if(off && !Directory.Exists(Path.Combine(ServerPath,"AudioOnly")) && !File.Exists(Path.Combine(ServerPath,"AudioOnly",$"{video.VideoId}.{(video.AudioOnly != null ? video.AudioOnly.Container : "mp4")}"))) + throw new VideoUnavailableException("We don't have access to YouTube"); if(removedByYT && !Directory.Exists(Path.Combine(ServerPath,"AudioOnly")) && !File.Exists(Path.Combine(ServerPath,"AudioOnly",$"{video.VideoId}.{(video.AudioOnly != null ? video.AudioOnly.Container : "mp4")}"))) throw new VideoUnavailableException("We dont have the video either"); @@ -667,8 +676,9 @@ server.Server.StartServer(port); break; case "VideoOnly": { - var (video,removedByYT) = await GetSavedVideoAsync(id); - + var (video,removedByYT,off) = await GetSavedVideoAsync(id); + if(off && !Directory.Exists(Path.Combine(ServerPath,"VideoOnly")) && !File.Exists(Path.Combine(ServerPath,"VideoOnly",$"{video.VideoId}.{(video.VideoOnly != null ? video.VideoOnly.Container : "mp4")}"))) + throw new VideoUnavailableException("We don't have access to YouTube"); if(removedByYT && !Directory.Exists(Path.Combine(ServerPath,"VideoOnly")) && !File.Exists(Path.Combine(ServerPath,"VideoOnly",$"{video.VideoId}.{(video.VideoOnly != null ? video.VideoOnly.Container : "mp4")}"))) throw new VideoUnavailableException("We dont have the video either"); @@ -677,7 +687,7 @@ server.Server.StartServer(port); break; case "MP3": { - var (video,removedByYT) = await GetSavedVideoAsync(id); + var (video,removedByYT,off) = await GetSavedVideoAsync(id); if(!HasConverter && !Directory.Exists(Path.Combine(ServerPath,"MP3")) && !File.Exists(Path.Combine(ServerPath,"MP3",$"{id}.mp3"))) throw new OperationCanceledException("We don't have the converter."); @@ -687,7 +697,7 @@ server.Server.StartServer(port); break; case "MP4": { - var (video,removedByYT) = await GetSavedVideoAsync(id); + var (video,removedByYT,off) = await GetSavedVideoAsync(id); if(!HasConverter && !Directory.Exists(Path.Combine(ServerPath,"MP4")) && !File.Exists(Path.Combine(ServerPath,"MP4",$"{id}.mp4"))) throw new OperationCanceledException("We don't have the converter."); @@ -697,7 +707,7 @@ server.Server.StartServer(port); break; case "MKV": { - var (video,removedByYT) = await GetSavedVideoAsync(id); + var (video,removedByYT,off) = await GetSavedVideoAsync(id); if(!HasConverter && !Directory.Exists(Path.Combine(ServerPath,"MKV")) && !File.Exists(Path.Combine(ServerPath,"MKV",$"{id}.mkv"))) throw new OperationCanceledException("We don't have the converter."); @@ -736,12 +746,13 @@ server.Server.StartServer(port); if(id.HasValue) { - (SavedVideo video,bool notavailable)=await GetSavedVideoAsync(id.Value); - bool premuxed = notavailable ? await StreamExistsAsync(video,"PreMuxed") : true; - bool audioonly = notavailable ? await StreamExistsAsync(video,"AudioOnly") : true; - bool videoonly = notavailable ? await StreamExistsAsync(video,"VideoOnly") : true; + (SavedVideo video,bool notavailable,bool offline)=await GetSavedVideoAsync(id.Value); + bool premuxed = (notavailable || offline) ? await StreamExistsAsync(video,"PreMuxed") : true; + bool audioonly = (notavailable || offline) ? await StreamExistsAsync(video,"AudioOnly") : true; + bool videoonly = (notavailable || offline) ? await StreamExistsAsync(video,"VideoOnly") : true; bool converter=HasConverter; //change me result = new { + offline, notavailable, premuxed, audioonly,