'use strict'; const unprint = require('unprint'); const http = require('../utils/http'); const qu = require('../utils/qu'); function scrapeAll(scenes) { return scenes.map(({ query }) => { const release = {}; release.title = query.content('.video-title div'); console.log(release); return release; }); } async function fetchLatest(channel, page) { const session = http.session(); await http.get(channel.url, { session }); await http.post(`${channel.url}/adult_confirmation_and_accept_cookie`, null, { session }); const checkRes = await http.get(`${channel.url}/check_adult_confirmation_and_accept_cookie`, { session }); const res = await http.get(`${channel.url}/videos?sort=published_at&page=${page}`, { session }); // const res = await http.get(`${channel.url}/videos?sort=published_at&page=${page}`, { selectAll: '.row a[video-id]' }); console.log(checkRes.body); console.log(res.body); if (res.ok) { return scrapeAll(res.context, channel); } return res.status; } /* function confirmAdultCookie() { // console.log('confirmed Adult'); $('#adult_confirmation').modal('hide'); var adultCookieRequest = $.ajax({ xhrFields: { withCredentials: true }, type: "POST", url: "https://www.delphinefilms.com/adult_confirmation_and_accept_cookie" }); $.when(adultCookieRequest).done(function() { // console.log('Both requests completed successfully'); waitForSessionUpdateAndRefresh(); }); return false; } function waitForSessionUpdateAndRefresh() { var interval = setInterval(function() { $.ajax({ type: "GET", url: "https://www.delphinefilms.com/check_adult_confirmation_and_accept_cookie", success: function(response) { // console.log(response) if (response === "1") { // console.log('Session updated: Adult confirmed and cookie accepted'); clearInterval(interval); location.reload(); } else { // console.log('Session not updated: Adult not confirmed or cookie not accepted'); } } }); }, 100); } */ module.exports = { fetchLatest, };