aboutsummaryrefslogtreecommitdiffstats
path: root/src/server/Cache.hx
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2025-02-15 06:16:13 +0300
committerRblSb <msrblsb@gmail.com>2025-02-15 06:16:13 +0300
commitf085006f1da0ac431caf391e721f0ee140d1bfb8 (patch)
treef63d9cd10c9eb272228e66e7492122bed4712554 /src/server/Cache.hx
parent74244ebef3e3e4cbd9af50ca19af2affb39ba0f1 (diff)
Youtube cache cookies support
closes #59
Diffstat (limited to 'src/server/Cache.hx')
-rw-r--r--src/server/Cache.hx13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/server/Cache.hx b/src/server/Cache.hx
index cfd5d88..88899a6 100644
--- a/src/server/Cache.hx
+++ b/src/server/Cache.hx
@@ -1,5 +1,6 @@
package server;
+import haxe.Json;
import haxe.io.Path;
import js.lib.Promise;
import js.node.Buffer;
@@ -7,6 +8,7 @@ import js.node.ChildProcess;
import js.node.Fs.Fs;
import js.node.stream.Readable;
import sys.FileSystem;
+import sys.io.File;
import utils.YoutubeUtils;
class Cache {
@@ -119,7 +121,14 @@ class Cache {
data: outName
}
});
- final promise:Promise<YouTubeVideoInfo> = ytdl.getInfo(url);
+ var agent:Any = null;
+ final cookiesPath = '${main.userDir}/cookies.json';
+ if (FileSystem.exists(cookiesPath)) {
+ agent = ytdl.createAgent(Json.parse(File.getContent(cookiesPath)));
+ }
+ final promise:Promise<YouTubeVideoInfo> = ytdl.getInfo(url, {
+ agent: agent,
+ });
promise.then(info -> {
trace('Get info with ${info.formats.length} formats');
final audioFormat:YoutubeVideoFormat = try {
@@ -140,6 +149,7 @@ class Cache {
final dlVideo:Readable<Dynamic> = ytdl(url, {
format: videoFormat,
+ agent: agent,
});
dlVideo.pipe(Fs.createWriteStream('$cacheDir/$inVideoName'));
dlVideo.on("error", err -> {
@@ -150,6 +160,7 @@ class Cache {
final dlAudio:Readable<Dynamic> = ytdl(url, {
format: audioFormat,
+ agent: agent,
});
dlAudio.pipe(Fs.createWriteStream('$cacheDir/$inAudioName'));
dlAudio.on("error", err -> {
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage