From 55ab8741602a02db25ed1ce9725f7b787ac4a9c5 Mon Sep 17 00:00:00 2001 From: Animenosekai <40539549+Animenosekai@users.noreply.github.com> Date: Tue, 27 Aug 2024 18:01:09 +0200 Subject: [PATCH] [update] add @BellezaEmporium code --- .../skyperfectv.co.jp.config.js | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/sites/skyperfectv.co.jp/skyperfectv.co.jp.config.js b/sites/skyperfectv.co.jp/skyperfectv.co.jp.config.js index 8fa6db6f..08f4e85c 100644 --- a/sites/skyperfectv.co.jp/skyperfectv.co.jp.config.js +++ b/sites/skyperfectv.co.jp/skyperfectv.co.jp.config.js @@ -18,14 +18,24 @@ module.exports = { url: function ({ date, channel }) { let [type, ...code] = channel.site_id.split('_') code = code.join('_') - console.log(`https://www.skyperfectv.co.jp/program/schedule/${type}/channel:${code}/date:${date.format('YYMMDD')}`) return `https://www.skyperfectv.co.jp/program/schedule/${type}/channel:${code}/date:${date.format('YYMMDD')}` }, - logo: function ({channel}) { + logo: function ({ channel }) { return `https://www.skyperfectv.co.jp/library/common/img/channel/icon/basic/m_${channel.site_id.toLowerCase()}.gif` }, - parser: function ({ content, date }) { - const $ = cheerio.load(content) + // Specific function that permits to gather NSFW channels (needs confirmation) + async fetchSchedule({ date, channel }) { + const url = this.url({ date, channel }) + const response = await axios.get(url, { + headers: { + 'Cookie': 'adult_auth=true' + } + }) + return response.data + }, + async parser({ date, channel }) { + const sched = await this.fetchSchedule({ date, channel }) + const $ = cheerio.load(sched) const programs = [] const sections = [ @@ -39,26 +49,20 @@ module.exports = { // `td` is a column for a day // the next `td` will be the next day const today = date.add(index + addition, 'd').tz('Asia/Tokyo') - + const parseTime = (timeString) => { // timeString is in the format "HH:mm" // replace `today` with the time from timeString const [hour, minute] = timeString.split(':').map(Number) return today.hour(hour).minute(minute) } - + const $element = $(element) // Wrap element with Cheerio $element.find('.p-program__item').each((itemIndex, itemElement) => { const $itemElement = $(itemElement) // Wrap itemElement with Cheerio const [start, stop] = $itemElement.find('.p-program__range').first().text().split('〜').map(parseTime) const title = $itemElement.find('.p-program__name').first().text() const image = $itemElement.find('.js-program_thumbnail').first().attr('data-lazysrc') - console.log({ - title, - start, - stop, - image - }) programs.push({ title, start, @@ -68,7 +72,7 @@ module.exports = { }) }) }) - + return programs }, async channels() { @@ -78,18 +82,22 @@ module.exports = { const $ = cheerio.load(content) const channels = [] - + $('.p-channel').each((index, element) => { const site_id = `${type}_${$(element).find('.p-channel__id').text()}` const name = $(element).find('.p-channel__name').text() channels.push({ site_id, name, lang: 'ja' }) }) - + return channels } const getChannels = async (type) => { - const response = await axios.get(`https://www.skyperfectv.co.jp/program/schedule/${type}/`) + const response = await axios.get(`https://www.skyperfectv.co.jp/program/schedule/${type}/`, { + headers: { + 'Cookie': 'adult_auth=true;' + } + }) return pageParser(response.data, type) } @@ -102,4 +110,4 @@ module.exports = { return await fetchAllChannels() } -} +} \ No newline at end of file