'use strict';

const bhttp = require('bhttp');

const { fetchLatest, fetchUpcoming, scrapeScene, fetchProfile } = require('./gamma');

async function fetchScene(url, site) {
    // const res = await bhttp.get(url);
    const res = await bhttp.get(`https://www.blowpass.com/en/video/${site.id}/${new URL(url).pathname.split('/').slice(-2).join('/')}`);

    const release = await scrapeScene(res.body.toString(), url, site);
    release.channel = release.$('.siteNameSpan')
        .text()
        .trim()
        .toLowerCase()
        .replace('.com', '');

    if (['onlyteenblowjobs.com', 'mommyblowsbest.com'].includes(release.channel)) release.url = url.replace(/video\/\w+\//, 'scene/');
    else release.url = url.replace(/video\/\w+\//, 'video/');

    return release;
}

function getActorReleasesUrl(actorPath, page = 1) {
    return `https://www.blowpass.com/en/videos/blowpass/latest/All-Categories/0${actorPath}/${page}`;
}

async function networkFetchProfile(actorName, siteSlug) {
    return fetchProfile(actorName, siteSlug, null, getActorReleasesUrl);
}

module.exports = {
    fetchLatest,
    fetchProfile: networkFetchProfile,
    fetchUpcoming,
    fetchScene,
};
