aboutsummaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Cache.hx13
-rw-r--r--src/server/Main.hx21
2 files changed, 23 insertions, 11 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 -> {
diff --git a/src/server/Main.hx b/src/server/Main.hx
index 7d78879..7c9041f 100644
--- a/src/server/Main.hx
+++ b/src/server/Main.hx
@@ -38,6 +38,7 @@ class Main {
final rootDir = '$__dirname/..';
+ public final userDir:String;
public final logsDir:String;
public final config:Config;
@@ -83,9 +84,10 @@ class Main {
isNoState = !opts.loadState;
final args = Utils.parseArgs(Sys.args(), false);
verbose = args.exists("verbose");
- statePath = '$rootDir/user/state.json';
- logsDir = '$rootDir/user/logs';
- cacheDir = '$rootDir/user/res/cache';
+ userDir = '$rootDir/user';
+ statePath = '$userDir/state.json';
+ logsDir = '$userDir/logs';
+ cacheDir = '$userDir/res/cache';
// process.on("exit", exit);
process.on("SIGINT", exit); // ctrl+c
@@ -160,7 +162,7 @@ class Main {
final dir = '$rootDir/res';
final httpServer = new HttpServer(this, {
dir: dir,
- customDir: '$rootDir/user/res',
+ customDir: '$userDir/res',
allowLocalRequests: config.localAdmins,
cache: cache,
});
@@ -222,7 +224,7 @@ class Main {
function getUserConfig():Config {
final config:Config = Json.parse(File.getContent('$rootDir/default-config.json'));
if (isNoState) return config;
- final customPath = '$rootDir/user/config.json';
+ final customPath = '$userDir/config.json';
if (!FileSystem.exists(customPath)) return config;
final customConfig:Config = Json.parse(File.getContent(customPath));
for (field in Reflect.fields(customConfig)) {
@@ -245,7 +247,7 @@ class Main {
}
function loadUsers():UserList {
- final customPath = '$rootDir/user/users.json';
+ final customPath = '$userDir/users.json';
if (isNoState || !FileSystem.exists(customPath)) return {
admins: [],
bans: []
@@ -260,8 +262,7 @@ class Main {
}
function writeUsers(users:UserList):Void {
- final folder = '$rootDir/user';
- Utils.ensureDir(folder);
+ Utils.ensureDir(userDir);
final data:UserList = {
admins: users.admins,
bans: [
@@ -272,7 +273,7 @@ class Main {
],
salt: users.salt
}
- File.saveContent('$folder/users.json', Json.stringify(data, "\t"));
+ File.saveContent('$userDir/users.json', Json.stringify(data, "\t"));
}
function saveState():Void {
@@ -325,7 +326,7 @@ class Main {
function logError(type:String, data:Dynamic):Void {
cache.removeOlderCache(1024 * 1024);
trace(type, data);
- final crashesFolder = '$rootDir/user/crashes';
+ final crashesFolder = '$userDir/crashes';
Utils.ensureDir(crashesFolder);
final name = DateTools.format(Date.now(), "%Y-%m-%d_%H_%M_%S") + "-" + type;
File.saveContent('$crashesFolder/$name.json', Json.stringify(data, "\t"));
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage