"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHlsResolutionPlaylistFilename = exports.generateHlsSha256SegmentsFilename = exports.generateHLSMasterPlaylistFilename = exports.getHLSRedundancyDirectory = exports.getLiveReplayBaseDirectory = exports.getLiveDirectory = exports.getHLSDirectory = exports.getFSTorrentFilePath = exports.generateTorrentFileName = exports.generateWebTorrentVideoFilename = exports.generateHLSVideoFilename = void 0;
const path_1 = require("path");
const config_1 = require("../initializers/config");
const constants_1 = require("../initializers/constants");
const models_1 = require("../types/models");
const core_utils_1 = require("../../shared/core-utils");
const extra_utils_1 = require("../../shared/extra-utils");
const video_privacy_1 = require("./video-privacy");
function generateWebTorrentVideoFilename(resolution, extname) {
    return (0, extra_utils_1.buildUUID)() + '-' + resolution + extname;
}
exports.generateWebTorrentVideoFilename = generateWebTorrentVideoFilename;
function generateHLSVideoFilename(resolution) {
    return `${(0, extra_utils_1.buildUUID)()}-${resolution}-fragmented.mp4`;
}
exports.generateHLSVideoFilename = generateHLSVideoFilename;
function getLiveDirectory(video) {
    return getHLSDirectory(video);
}
exports.getLiveDirectory = getLiveDirectory;
function getLiveReplayBaseDirectory(video) {
    return (0, path_1.join)(getLiveDirectory(video), constants_1.VIDEO_LIVE.REPLAY_DIRECTORY);
}
exports.getLiveReplayBaseDirectory = getLiveReplayBaseDirectory;
function getHLSDirectory(video) {
    if ((0, video_privacy_1.isVideoInPrivateDirectory)(video.privacy)) {
        return (0, path_1.join)(constants_1.DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, video.uuid);
    }
    return (0, path_1.join)(constants_1.DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC, video.uuid);
}
exports.getHLSDirectory = getHLSDirectory;
function getHLSRedundancyDirectory(video) {
    return (0, path_1.join)(constants_1.DIRECTORIES.HLS_REDUNDANCY, video.uuid);
}
exports.getHLSRedundancyDirectory = getHLSRedundancyDirectory;
function getHlsResolutionPlaylistFilename(videoFilename) {
    return (0, core_utils_1.removeFragmentedMP4Ext)(videoFilename) + '.m3u8';
}
exports.getHlsResolutionPlaylistFilename = getHlsResolutionPlaylistFilename;
function generateHLSMasterPlaylistFilename(isLive = false) {
    if (isLive)
        return 'master.m3u8';
    return (0, extra_utils_1.buildUUID)() + '-master.m3u8';
}
exports.generateHLSMasterPlaylistFilename = generateHLSMasterPlaylistFilename;
function generateHlsSha256SegmentsFilename(isLive = false) {
    if (isLive)
        return 'segments-sha256.json';
    return (0, extra_utils_1.buildUUID)() + '-segments-sha256.json';
}
exports.generateHlsSha256SegmentsFilename = generateHlsSha256SegmentsFilename;
function generateTorrentFileName(videoOrPlaylist, resolution) {
    const extension = '.torrent';
    const uuid = (0, extra_utils_1.buildUUID)();
    if ((0, models_1.isStreamingPlaylist)(videoOrPlaylist)) {
        return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}`;
    }
    return uuid + '-' + resolution + extension;
}
exports.generateTorrentFileName = generateTorrentFileName;
function getFSTorrentFilePath(videoFile) {
    return (0, path_1.join)(config_1.CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename);
}
exports.getFSTorrentFilePath = getFSTorrentFilePath;
//# sourceMappingURL=paths.js.map