"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const ffmpeg_1 = require("../../../helpers/ffmpeg");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test audio only video transcoding', function () {
    let servers = [];
    let videoUUID;
    let webtorrentAudioFileUrl;
    let fragmentedAudioFileUrl;
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            const configOverride = {
                transcoding: {
                    enabled: true,
                    resolutions: {
                        '0p': true,
                        '144p': false,
                        '240p': true,
                        '360p': false,
                        '480p': false,
                        '720p': false,
                        '1080p': false,
                        '1440p': false,
                        '2160p': false
                    },
                    hls: {
                        enabled: true
                    },
                    webtorrent: {
                        enabled: true
                    }
                }
            };
            servers = yield (0, server_commands_1.createMultipleServers)(2, configOverride);
            yield (0, server_commands_1.setAccessTokensToServers)(servers);
            yield (0, server_commands_1.doubleFollow)(servers[0], servers[1]);
        });
    });
    it('Should upload a video and transcode it', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            const { uuid } = yield servers[0].videos.upload({ attributes: { name: 'audio only' } });
            videoUUID = uuid;
            yield (0, server_commands_1.waitJobs)(servers);
            for (const server of servers) {
                const video = yield server.videos.get({ id: videoUUID });
                (0, chai_1.expect)(video.streamingPlaylists).to.have.lengthOf(1);
                for (const files of [video.files, video.streamingPlaylists[0].files]) {
                    (0, chai_1.expect)(files).to.have.lengthOf(3);
                    (0, chai_1.expect)(files[0].resolution.id).to.equal(720);
                    (0, chai_1.expect)(files[1].resolution.id).to.equal(240);
                    (0, chai_1.expect)(files[2].resolution.id).to.equal(0);
                }
                if (server.serverNumber === 1) {
                    webtorrentAudioFileUrl = video.files[2].fileUrl;
                    fragmentedAudioFileUrl = video.streamingPlaylists[0].files[2].fileUrl;
                }
            }
        });
    });
    it('0p transcoded video should not have video', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const paths = [
                servers[0].servers.buildWebTorrentFilePath(webtorrentAudioFileUrl),
                servers[0].servers.buildFragmentedFilePath(videoUUID, fragmentedAudioFileUrl)
            ];
            for (const path of paths) {
                const { audioStream } = yield (0, ffmpeg_1.getAudioStream)(path);
                (0, chai_1.expect)(audioStream['codec_name']).to.be.equal('aac');
                (0, chai_1.expect)(audioStream['bit_rate']).to.be.at.most(384 * 8000);
                const size = yield (0, ffmpeg_1.getVideoStreamDimensionsInfo)(path);
                (0, chai_1.expect)(size.height).to.equal(0);
                (0, chai_1.expect)(size.width).to.equal(0);
                (0, chai_1.expect)(size.isPortraitMode).to.be.false;
                (0, chai_1.expect)(size.ratio).to.equal(0);
                (0, chai_1.expect)(size.resolution).to.equal(0);
            }
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)(servers);
        });
    });
});
//# sourceMappingURL=audio-only.js.map