tivie.id: Clean hidden text and fix program categories.

Signed-off-by: Toha <tohenk@yahoo.com>
This commit is contained in:
Toha
2026-05-06 09:55:06 +07:00
parent 6db4043647
commit b457de9c3a

View File

@@ -14,6 +14,7 @@ dayjs.extend(customParseFormat)
doFetch.setDebugger(debug) doFetch.setDebugger(debug)
const tz = 'Asia/Jakarta' const tz = 'Asia/Jakarta'
let $
module.exports = { module.exports = {
site: 'tivie.id', site: 'tivie.id',
@@ -24,7 +25,7 @@ module.exports = {
async parser({ content, date }) { async parser({ content, date }) {
const programs = [] const programs = []
if (content) { if (content) {
const $ = cheerio.load(content) $ = cheerio.load(content)
const items = $('ul[x-data] > li[id*="event-"] > div.w-full') const items = $('ul[x-data] > li[id*="event-"] > div.w-full')
.toArray() .toArray()
.map(item => { .map(item => {
@@ -37,10 +38,11 @@ module.exports = {
} }
if (detail.length) { if (detail.length) {
const subtitle = detail.find('div') const subtitle = detail.find('div')
p.title = parseText(subtitle.length ? subtitle : detail) p.title = parseText(subtitle.length ? prune(subtitle, '.sr-only') :
prune(detail, '.sr-only'))
p.url = detail.attr('href') p.url = detail.attr('href')
} else { } else {
p.title = parseText(info) p.title = parseText(prune(info, '.sr-only'))
} }
if (p.title) { if (p.title) {
const [, , season, episode] = p.title.match(/( S(\d+))?, Ep\. (\d+)/) || [ const [, , season, episode] = p.title.match(/( S(\d+))?, Ep\. (\d+)/) || [
@@ -69,20 +71,17 @@ module.exports = {
if (queues.length) { if (queues.length) {
await doFetch(queues, (queue, res) => { await doFetch(queues, (queue, res) => {
if (res) { if (res) {
const $ = cheerio.load(res) $ = cheerio.load(res)
const info = $('#main-content > div > div:nth-child(2)') const info = $('#main-content > div > div:nth-child(2)')
// program description // program description
const desc = info.find('div[class=""] > p') const desc = info.find('div[class=""] > p')
if (desc.length) { if (desc.length) {
desc.find('.hidden') queue.i.description = parseText(prune(desc, '.hidden'))
.toArray()
.forEach(el => $(el).remove())
queue.i.description = parseText(desc)
} }
// program categories // program categories
const cat = info.find('div[class=""] > a') const cat = info.find('div[class=""] > a')
if (cat.length) { if (cat.length) {
queue.i.categories = parseText(cat).split(', ') queue.i.categories = cat.toArray().map(el => parseText($(el)))
} }
// program image // program image
const img = $('#main-content > div > div:nth-child(1) img') const img = $('#main-content > div > div:nth-child(1) img')
@@ -133,14 +132,18 @@ module.exports = {
} }
function parseText($item) { function parseText($item) {
let text = $item.text().replace(/\t/g, '').replace(/\n/g, ' ').trim() return $item.text()
while (true) { .replace(/\t/g, '')
if (text.match(/\s{2,}/)) { .replace(/\n/g, ' ')
text = text.replace(/\s{2,}/g, ' ') .replace(/\s{2,}/g, ' ')
continue .trim()
}
break
} }
return text function prune($item, selector) {
if ($) {
$item.find(selector)
.toArray()
.forEach(el => $(el).remove())
}
return $item
} }