Skip to content

Commit

Permalink
Rename VIDEOS_FOLDER to VIDEOS_DIR and PREVIEW_CACHE to `PREVIE…
Browse files Browse the repository at this point in the history
…W_CACHE_DIR`
  • Loading branch information
ysdragon committed Oct 22, 2024
1 parent 701a913 commit abec935
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ COMMAND_CHANNEL_ID = "" # The ID of the Discord channel where your self-bot will
VIDEO_CHANNEL_ID = "" # The ID of the Discord voice/video channel where your self-bot will stream videos

# General options
VIDEOS_FOLDER = "./videos" # The local path where you store video files
PREVIEW_CACHE = "./tmp/preview-cache" # The local path where your self-bot will cache video preview thumbnails
VIDEOS_DIR = "./videos" # The local path where you store video files
PREVIEW_CACHE_DIR = "./tmp/preview-cache" # The local path where your self-bot will cache video preview thumbnails
YT_VIDEO_CACHE: "false" # Whether to enable youtube video caching, set to "true" to enable, "false" to disable
YT_VIDEO_CACHE_DIR = "./tmp/video-cache" # The local path where your self-bot will cache youtube videos

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ COMMAND_CHANNEL_ID = "" # The ID of the Discord channel where your self-bot will
VIDEO_CHANNEL_ID = "" # The ID of the Discord voice/video channel where your self-bot will stream videos

# General options
VIDEOS_FOLDER = "./videos" # The local path where you store video files
PREVIEW_CACHE = "./tmp/preview-cache" # The local path where your self-bot will cache video preview thumbnails
VIDEOS_DIR = "./videos" # The local path where you store video files
PREVIEW_CACHE_DIR = "./tmp/preview-cache" # The local path where your self-bot will cache video preview thumbnails
YT_VIDEO_CACHE: "false" # Whether to enable youtube video caching, set to "true" to enable, "false" to disable
YT_VIDEO_CACHE_DIR = "./tmp/video-cache" # The local path where your self-bot will cache youtube videos

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ services:
VIDEO_CHANNEL_ID: "" # The ID of the Discord voice/video channel where your self-bot will stream videos

# General options
VIDEOS_FOLDER: "./videos" # The local path where you store video files
PREVIEW_CACHE: "./tmp/preview-cache" # The local path where your self-bot will cache video preview thumbnails
VIDEOS_DIR: "./videos" # The local path where you store video files
PREVIEW_CACHE_DIR: "./tmp/preview-cache" # The local path where your self-bot will cache video preview thumbnails
YT_VIDEO_CACHE: "false" # Whether to enable youtube video caching, set to "true" to enable, "false" to disable
YT_VIDEO_CACHE_DIR: "./tmp/video-cache" # The local path where your self-bot will cache youtube videos

Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default {
videoChannelId: process.env.VIDEO_CHANNEL_ID ? process.env.VIDEO_CHANNEL_ID : '',

// General options
previewCache: process.env.PREVIEW_CACHE ? process.env.PREVIEW_CACHE : './tmp/preview-cache',
videosDir: process.env.VIDEOS_DIR ? process.env.VIDEOS_DIR : './videos',
previewCacheDir: process.env.PREVIEW_CACHE_DIR ? process.env.PREVIEW_CACHE_DIR : './tmp/preview-cache',
ytVideoCache: process.env.YT_VIDEO_CACHE ? parseBoolean(process.env.YT_VIDEO_CACHE) : false,
ytVideoCacheDir: process.env.YT_VIDEO_CACHE_DIR ? process.env.YT_VIDEO_CACHE_DIR : './tmp/video-cache',

Expand All @@ -31,7 +32,6 @@ export default {
server_username: process.env.SERVER_USERNAME ? process.env.SERVER_USERNAME : 'admin',
server_password: bcrypt.hashSync(process.env.SERVER_PASSWORD ? process.env.SERVER_PASSWORD : 'admin', 10),
server_port: parseInt(process.env.SERVER_PORT ? process.env.SERVER_PORT : '8080'),
videosFolder: process.env.VIDEOS_FOLDER ? process.env.VIDEOS_FOLDER : './videos'
}

function parseBoolean(value: string | undefined): boolean {
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const streamOpts: StreamOptions = {
};

// Create the videosFolder dir if it doesn't exist
if (!fs.existsSync(config.videosFolder)) {
fs.mkdirSync(config.videosFolder);
if (!fs.existsSync(config.videosDir)) {
fs.mkdirSync(config.videosDir);
}

// Create previewCache/ytVideoCacheDir parent dir if it doesn't exist
Expand All @@ -50,8 +50,8 @@ if (!fs.existsSync(path.dirname(config.ytVideoCacheDir))) {
}

// Create the previewCache dir if it doesn't exist
if (!fs.existsSync(config.previewCache)) {
fs.mkdirSync(config.previewCache);
if (!fs.existsSync(config.previewCacheDir)) {
fs.mkdirSync(config.previewCacheDir);
}

// Create the ytVideoCacheDir dir if it doesn't exist
Expand All @@ -61,11 +61,11 @@ if (!fs.existsSync(config.ytVideoCacheDir)) {

const tmpVideo = `${config.ytVideoCacheDir}/temp_vid.mp4`;

const videoFiles = fs.readdirSync(config.videosFolder);
const videoFiles = fs.readdirSync(config.videosDir);
let videos = videoFiles.map(file => {
const fileName = path.parse(file).name;
// replace space with _
return { name: fileName.replace(/ /g, '_'), path: path.join(config.videosFolder, file) };
return { name: fileName.replace(/ /g, '_'), path: path.join(config.videosDir, file) };
});

// print out all videos
Expand Down Expand Up @@ -332,11 +332,11 @@ streamer.client.on('messageCreate', async (message) => {
break;
case 'refresh':
// refresh video list
const videoFiles = fs.readdirSync(config.videosFolder);
const videoFiles = fs.readdirSync(config.videosDir);
videos = videoFiles.map(file => {
const fileName = path.parse(file).name;
// replace space with _
return { name: fileName.replace(/ /g, '_'), path: path.join(config.videosFolder, file) };
return { name: fileName.replace(/ /g, '_'), path: path.join(config.videosDir, file) };
});
message.reply('video list refreshed ' + videos.length + ' videos found.\n' + videos.map(m => m.name).join('\n'));
break;
Expand Down
28 changes: 14 additions & 14 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ app.use(session({
}));

// Create the videosFolder dir if it doesn't exist
if (!fs.existsSync(config.videosFolder)) {
fs.mkdirSync(config.videosFolder);
if (!fs.existsSync(config.videosDir)) {
fs.mkdirSync(config.videosDir);
}

// Create previewCache parent dir if it doesn't exist
if (!fs.existsSync(path.dirname(config.previewCache))) {
fs.mkdirSync(path.dirname(config.previewCache), { recursive: true });
if (!fs.existsSync(path.dirname(config.previewCacheDir))) {
fs.mkdirSync(path.dirname(config.previewCacheDir), { recursive: true });
}

// Create the previewCache dir if it doesn't exist
if (!fs.existsSync(config.previewCache)) {
fs.mkdirSync(config.previewCache);
if (!fs.existsSync(config.previewCacheDir)) {
fs.mkdirSync(config.previewCacheDir);
}

const storage = multer.diskStorage({
destination: (req: any, file: any, cb: (arg0: null, arg1: string) => void) => {
cb(null, config.videosFolder);
cb(null, config.videosDir);
},
filename: (req: any, file: { originalname: any; }, cb: (arg0: null, arg1: any) => void) => {
cb(null, file.originalname);
Expand Down Expand Up @@ -363,15 +363,15 @@ app.get("/logout", (req, res) => {

// Main route
app.get("/", (req, res) => {
fs.readdir(config.videosFolder, (err, files) => {
fs.readdir(config.videosDir, (err, files) => {
if (err) {
console.error(err);
res.status(500).send("Internal Server Error");
return;
}

const fileList = files.map((file) => {
const stats = fs.statSync(path.join(config.videosFolder, file));
const stats = fs.statSync(path.join(config.videosDir, file));
return { name: file, size: prettySize(stats.size) };
});

Expand Down Expand Up @@ -502,7 +502,7 @@ app.post("/api/upload", upload.single("file"), (req, res) => {
app.post("/api/remote_upload", upload.single("link"), async (req, res) => {
const link = req.body.link;
const filename = link.substring(link.lastIndexOf('/') + 1);
const filepath = path.join(config.videosFolder, filename);
const filepath = path.join(config.videosDir, filename);

try {
const response = await axios.get(link, { responseType: "stream", httpsAgent: agent });
Expand All @@ -526,12 +526,12 @@ app.post("/api/remote_upload", upload.single("link"), async (req, res) => {

app.get("/preview/:file", (req, res) => {
const file = req.params.file;
if (!fs.existsSync(path.join(config.videosFolder, file))) {
if (!fs.existsSync(path.join(config.videosDir, file))) {
res.status(404).send("Not Found");
return;
}

ffmpeg.ffprobe(`${config.videosFolder}/${file}`, (err, metadata) => {
ffmpeg.ffprobe(`${config.videosDir}/${file}`, (err, metadata) => {
if (err) {
console.log(err);
res.status(500).send("Internal Server Error");
Expand Down Expand Up @@ -618,7 +618,7 @@ app.get("/api/preview/:file/:id", async (req, res) => {
}

// check if preview exists
const previewFile = path.resolve(config.previewCache, `${file}-${id}.jpg`);
const previewFile = path.resolve(config.previewCacheDir, `${file}-${id}.jpg`);
if (fs.existsSync(previewFile)) {
res.sendFile(previewFile);
} else {
Expand All @@ -635,7 +635,7 @@ app.get("/api/preview/:file/:id", async (req, res) => {

app.get("/delete/:file", (req, res) => {
const file = req.params.file;
const filePath = path.join(config.videosFolder, file);
const filePath = path.join(config.videosDir, file);

if (fs.existsSync(filePath)) {
fs.unlink(filePath, (err) => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export async function ffmpegScreenshot(video: string): Promise<string[]> {
return;
}
console.log(`Taking screenshot ${i + 1} of ${video} at ${ts[i]}`);
ffmpeg(`${config.videosFolder}/${video}`)
ffmpeg(`${config.videosDir}/${video}`)
.on("end", () => {
const screenshotPath = `${config.previewCache}/${video}-${i + 1}.jpg`;
const screenshotPath = `${config.previewCacheDir}/${video}-${i + 1}.jpg`;
images.push(screenshotPath);
takeScreenshots(i + 1);
})
Expand All @@ -41,7 +41,7 @@ export async function ffmpegScreenshot(video: string): Promise<string[]> {
count: 1,
filename: `${video}-${i + 1}.jpg`,
timestamps: [ts[i]],
folder: config.previewCache,
folder: config.previewCacheDir,
size: "640x480"
});
};
Expand Down

0 comments on commit abec935

Please sign in to comment.