'use strict';

const path = require('path');
const Promise = require('bluebird');
const fs = require('fs-extra');
const fetchScene = require('../scrape-releases');

const argv = require('../argv');

async function renameFiles() {
    const filenames = await fs.readdir(process.cwd());

    const curated = await Promise.map(filenames, async (filename) => {
        const shootId = filename.split(' ')[1];
        const scene = await fetchScene(`https://kink.com/shoot/${shootId}`);

        if (argv.confirm) {
            await fs.rename(path.join(process.cwd(), filename), path.join(process.cwd(), `${scene.filename}.mp4`));
        }

        return scene.filename;
    }, {
        concurrency: 5,
    });

    console.log(curated);
}

renameFiles();
