2024-05-08 21:08:47 +00:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.Files = void 0;
|
2024-07-31 18:39:21 +00:00
|
|
|
const promises_1 = require("fs/promises");
|
2024-05-08 21:08:47 +00:00
|
|
|
const hash_1 = require("../hash");
|
|
|
|
const path_1 = require("path");
|
2024-10-26 23:43:01 +00:00
|
|
|
const env_1 = require("../env");
|
|
|
|
const os_1 = require("os");
|
2024-07-31 18:39:21 +00:00
|
|
|
const videoExtensions = [
|
2024-05-15 18:34:24 +00:00
|
|
|
'.mp4',
|
|
|
|
'.mkv',
|
|
|
|
'.mov'
|
|
|
|
];
|
2024-07-31 18:39:21 +00:00
|
|
|
const imageExtensions = [
|
|
|
|
'.jpg',
|
|
|
|
'.jpeg',
|
|
|
|
'.png',
|
|
|
|
'.tif',
|
|
|
|
'.tiff',
|
2024-10-27 01:47:13 +00:00
|
|
|
'.bmp',
|
|
|
|
'.dpx'
|
2024-07-31 18:39:21 +00:00
|
|
|
];
|
2024-05-08 21:08:47 +00:00
|
|
|
class Files {
|
2024-10-26 21:11:25 +00:00
|
|
|
static async init(sequencesDir) {
|
|
|
|
this.sequencesDir = sequencesDir;
|
|
|
|
return this.exists(sequencesDir);
|
|
|
|
}
|
2024-05-08 21:08:47 +00:00
|
|
|
static async exists(path) {
|
|
|
|
try {
|
2024-07-31 18:39:21 +00:00
|
|
|
await (0, promises_1.access)(path);
|
2024-05-08 21:08:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-10-26 23:43:01 +00:00
|
|
|
static async enumerateSequenceDirs() {
|
|
|
|
const sequencesDirs = [
|
|
|
|
await (0, promises_1.realpath)(this.sequencesDir)
|
|
|
|
];
|
|
|
|
let drivesDir = null;
|
|
|
|
let drives = [];
|
|
|
|
let drive;
|
|
|
|
let user;
|
|
|
|
let stats;
|
|
|
|
if ((0, os_1.platform)() === 'darwin') {
|
|
|
|
drivesDir = `/Volumes/`;
|
|
|
|
}
|
|
|
|
else if ((0, os_1.platform)() === 'linux') {
|
|
|
|
user = (0, env_1.envString)('USER', null);
|
|
|
|
if (user !== null) {
|
|
|
|
drivesDir = (0, path_1.join)('/media', user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (drivesDir !== null) {
|
|
|
|
try {
|
|
|
|
drives = await (0, promises_1.readdir)(drivesDir);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let drive of drives) {
|
|
|
|
if (drive.substring(0, 1) === '.') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
drive = await (0, promises_1.realpath)((0, path_1.join)(drivesDir, drive));
|
|
|
|
stats = await (0, promises_1.lstat)(drive);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (stats.isDirectory()) {
|
|
|
|
sequencesDirs.push(drive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sequencesDirs;
|
|
|
|
}
|
2024-10-26 21:11:25 +00:00
|
|
|
static async enumerateSequences() {
|
2024-05-08 21:08:47 +00:00
|
|
|
const dirs = [];
|
|
|
|
let all;
|
|
|
|
let stats;
|
2024-07-31 18:39:21 +00:00
|
|
|
let dirPath;
|
2024-10-26 23:43:01 +00:00
|
|
|
const paths = await this.enumerateSequenceDirs();
|
2024-10-26 21:11:25 +00:00
|
|
|
for (let path of paths) {
|
|
|
|
try {
|
|
|
|
all = await (0, promises_1.readdir)(path);
|
|
|
|
}
|
|
|
|
catch (err) {
|
2024-10-26 23:43:01 +00:00
|
|
|
//
|
2024-10-26 21:11:25 +00:00
|
|
|
}
|
|
|
|
for (let elem of all) {
|
|
|
|
if (elem.substring(0, 1) === '.') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dirPath = (0, path_1.join)(path, elem);
|
|
|
|
try {
|
|
|
|
stats = await (0, promises_1.lstat)(dirPath);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!stats.isDirectory()) {
|
|
|
|
continue;
|
|
|
|
}
|
2024-10-26 23:43:01 +00:00
|
|
|
if (!await this.isSequence(dirPath)) {
|
2024-10-26 21:11:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dirs.push({
|
2024-10-26 23:43:01 +00:00
|
|
|
created: +stats.birthtime,
|
2024-10-26 21:11:25 +00:00
|
|
|
path: dirPath,
|
|
|
|
hash: hash_1.Hashes.stringHash(dirPath),
|
|
|
|
name: (0, path_1.basename)(dirPath)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2024-10-26 23:43:01 +00:00
|
|
|
dirs.sort((a, b) => {
|
|
|
|
return b.created - a.created;
|
|
|
|
});
|
2024-10-26 21:11:25 +00:00
|
|
|
return dirs;
|
|
|
|
}
|
|
|
|
static async isSequence(dirPath) {
|
|
|
|
let sequence = false;
|
|
|
|
let all;
|
|
|
|
let stats;
|
|
|
|
let filePath;
|
2024-05-08 21:08:47 +00:00
|
|
|
try {
|
2024-10-26 21:11:25 +00:00
|
|
|
all = await (0, promises_1.readdir)(dirPath);
|
2024-05-08 21:08:47 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
2024-10-26 21:11:25 +00:00
|
|
|
//
|
2024-05-08 21:08:47 +00:00
|
|
|
}
|
|
|
|
for (let elem of all) {
|
2024-10-26 21:11:25 +00:00
|
|
|
filePath = (0, path_1.join)(dirPath, elem);
|
2024-05-08 21:08:47 +00:00
|
|
|
try {
|
2024-10-26 21:11:25 +00:00
|
|
|
stats = await (0, promises_1.lstat)(filePath);
|
2024-05-08 21:08:47 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//
|
|
|
|
}
|
2024-10-26 23:43:01 +00:00
|
|
|
if (stats.isFile() && elem.substring(0, 1) !== '.' && imageExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem).toLowerCase())) !== -1) {
|
2024-10-26 21:11:25 +00:00
|
|
|
sequence = true;
|
|
|
|
break;
|
|
|
|
}
|
2024-05-08 21:08:47 +00:00
|
|
|
}
|
2024-10-26 21:11:25 +00:00
|
|
|
return sequence;
|
2024-05-08 21:08:47 +00:00
|
|
|
}
|
2024-05-15 18:34:24 +00:00
|
|
|
static async enumerateVideos(path) {
|
|
|
|
const videos = [];
|
|
|
|
let all;
|
|
|
|
let stats;
|
2024-07-31 18:39:21 +00:00
|
|
|
let filePath;
|
|
|
|
path = await (0, promises_1.realpath)(path);
|
2024-05-15 21:29:59 +00:00
|
|
|
try {
|
2024-07-31 18:39:21 +00:00
|
|
|
all = await (0, promises_1.readdir)(path);
|
2024-05-15 21:29:59 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
for (let elem of all) {
|
2024-07-31 18:39:21 +00:00
|
|
|
filePath = (0, path_1.join)(path, elem);
|
2024-05-15 21:29:59 +00:00
|
|
|
try {
|
2024-07-31 18:39:21 +00:00
|
|
|
stats = await (0, promises_1.lstat)(filePath);
|
|
|
|
if (stats.isFile() && videoExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem).toLowerCase())) !== -1) {
|
2024-05-15 21:29:59 +00:00
|
|
|
videos.push({
|
2024-10-26 23:43:01 +00:00
|
|
|
created: +stats.birthtime,
|
2024-07-31 18:39:21 +00:00
|
|
|
path: filePath,
|
|
|
|
hash: hash_1.Hashes.stringHash(filePath),
|
|
|
|
name: (0, path_1.basename)(filePath)
|
2024-05-15 21:29:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
2024-05-15 18:34:24 +00:00
|
|
|
return videos;
|
|
|
|
}
|
2024-07-31 18:39:21 +00:00
|
|
|
static async enumerateSequence(path) {
|
2024-08-09 20:20:07 +00:00
|
|
|
const imgs = [];
|
2024-07-31 18:39:21 +00:00
|
|
|
let all;
|
|
|
|
let stats;
|
|
|
|
let filePath;
|
|
|
|
path = await (0, promises_1.realpath)(path);
|
|
|
|
try {
|
|
|
|
all = await (0, promises_1.readdir)(path);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
for (let elem of all) {
|
2024-10-26 21:11:25 +00:00
|
|
|
if (elem.substring(0, 1) === '.') {
|
|
|
|
continue;
|
|
|
|
}
|
2024-07-31 18:39:21 +00:00
|
|
|
filePath = (0, path_1.join)(path, elem);
|
|
|
|
try {
|
|
|
|
stats = await (0, promises_1.lstat)(filePath);
|
|
|
|
if (stats.isFile() && imageExtensions.indexOf((0, path_1.extname)((0, path_1.basename)(elem).toLowerCase())) !== -1) {
|
2024-08-09 20:20:07 +00:00
|
|
|
imgs.push({
|
2024-07-31 18:39:21 +00:00
|
|
|
path: filePath,
|
|
|
|
hash: hash_1.Hashes.stringHash(filePath),
|
|
|
|
name: (0, path_1.basename)(filePath)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
2024-08-09 20:20:07 +00:00
|
|
|
return imgs;
|
2024-07-31 18:39:21 +00:00
|
|
|
}
|
2024-05-08 21:08:47 +00:00
|
|
|
}
|
|
|
|
exports.Files = Files;
|
|
|
|
module.exports = { Files };
|
|
|
|
//# sourceMappingURL=index.js.map
|