filmout_manager/dist/files/index.js

82 lines
2.2 KiB
JavaScript
Raw Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Files = void 0;
const promises_1 = __importDefault(require("fs/promises"));
const hash_1 = require("../hash");
const path_1 = require("path");
const fileExtensions = [
'.mp4',
'.mkv',
'.mov'
];
class Files {
static async exists(path) {
try {
await promises_1.default.access(path);
return true;
}
catch {
return false;
}
}
static async enumerateSequences(path) {
const dirs = [];
let all;
let stats;
try {
all = await promises_1.default.readdir(path);
}
catch (err) {
throw err;
}
for (let elem of all) {
try {
stats = await promises_1.default.lstat(elem);
if (stats.isDirectory()) {
dirs.push({
path: elem,
hash: hash_1.Hashes.stringHash(elem),
name: (0, path_1.basename)(elem)
});
}
}
catch (err) {
//
}
}
return dirs;
}
static async enumerateVideos(path) {
const videos = [];
let all;
let stats;
try {
all = await promises_1.default.readdir(path);
}
catch (err) {
throw err;
}
for (let elem of all) {
try {
stats = await promises_1.default.lstat(elem);
if (stats.isFile() && fileExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem))) !== -1) {
videos.push({
path: elem,
hash: hash_1.Hashes.stringHash(elem),
name: (0, path_1.basename)(elem)
});
}
}
catch (err) {
//
}
}
return videos;
}
}
exports.Files = Files;
module.exports = { Files };
//# sourceMappingURL=index.js.map