Replace LF endings with CRLF

This commit is contained in:
freearhey
2025-07-31 22:29:01 +03:00
parent 17e3b4ddda
commit 29aa427923
379 changed files with 29332 additions and 29332 deletions

View File

@@ -1,167 +1,167 @@
const axios = require('axios')
const cheerio = require('cheerio')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
const doFetch = require('@ntlab/sfetch')
const debug = require('debug')('site:mncvision.id')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
doFetch.setCheckResult(false).setDebugger(debug)
const languages = { en: 'english', id: 'indonesia' }
const cookies = {}
const timeout = 30000
module.exports = {
site: 'mncvision.id',
days: 2,
url: 'https://www.mncvision.id/schedule/table',
request: {
method: 'POST',
data({ channel, date }) {
const formData = new URLSearchParams()
formData.append('search_model', 'channel')
formData.append('af0rmelement', 'aformelement')
formData.append('fdate', date.format('YYYY-MM-DD'))
formData.append('fchannel', channel.site_id)
formData.append('submit', 'Search')
return formData
},
async headers({ channel }) {
const headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
if (channel) {
if (!cookies[channel.lang]) {
cookies[channel.lang] = await loadLangCookies(channel)
}
if (cookies[channel.lang]) {
headers.Cookie = cookies[channel.lang]
}
}
return headers
},
jar: null
},
async parser({ content, headers, date, channel }) {
if (!cookies[channel.lang]) {
cookies[channel.lang] = parseCookies(headers)
}
return await parseItems(content, date, cookies[channel.lang])
},
async channels({ lang = 'id' }) {
const result = await axios
.get('https://www.mncvision.id/schedule')
.then(response => response.data)
.catch(console.error)
const $ = cheerio.load(result)
const items = $('select[name="fchannel"] option').toArray()
const channels = items.map(item => {
const $item = $(item)
return {
lang,
site_id: $item.attr('value'),
name: $item.text().split(' - ')[0].trim()
}
})
return channels
}
}
function parseSeason($item) {
const title = parseTitle($item)
const [, season] = title.match(/ S(\d+)/) || [null, null]
return season ? parseInt(season) : null
}
function parseEpisode($item) {
const title = parseTitle($item)
const [, episode] = title.match(/ Ep (\d+)/) || [null, null]
return episode ? parseInt(episode) : null
}
function parseDuration($item) {
let duration = $item.find('td:nth-child(3)').text()
const match = duration.match(/(\d{2}):(\d{2})/)
const hours = parseInt(match[1])
const minutes = parseInt(match[2])
return hours * 60 + minutes
}
function parseStart($item, date) {
let time = $item.find('td:nth-child(1)').text()
time = `${date.format('DD/MM/YYYY')} ${time}`
return dayjs.tz(time, 'DD/MM/YYYY HH:mm', 'Asia/Jakarta')
}
function parseTitle($item) {
return $item.find('td:nth-child(2) > a').text()
}
async function parseItems(content, date, cookies) {
const programs = []
const $ = cheerio.load(content)
const items = $('tr[valign="top"]').toArray()
if (items.length) {
const queues = []
for (const item of items) {
const $item = $(item)
const url = $item.find('a').attr('href')
const headers = {
'X-Requested-With': 'XMLHttpRequest',
Cookie: cookies
}
queues.push({ i: $item, url, params: { headers, timeout } })
}
await doFetch(queues, (queue, res) => {
const $item = queue.i
const description = res ? cheerio.load(res)('.synopsis').text().trim() : null
const start = parseStart($item, date)
const duration = parseDuration($item)
const stop = start.add(duration, 'm')
programs.push({
title: parseTitle($item),
season: parseSeason($item),
episode: parseEpisode($item),
description: description && description !== '-' ? description : null,
start,
stop
})
})
}
return programs
}
function loadLangCookies(channel) {
const url = `https://www.mncvision.id/language_switcher/setlang/${languages[channel.lang]}/`
return axios
.get(url, { timeout })
.then(r => parseCookies(r.headers))
.catch(error => console.error(error.message))
}
function parseCookies(headers) {
const cookies = []
if (Array.isArray(headers['set-cookie'])) {
headers['set-cookie'].forEach(cookie => {
cookies.push(cookie.split('; ')[0])
})
}
return cookies.length ? cookies.join('; ') : null
}
const axios = require('axios')
const cheerio = require('cheerio')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
const doFetch = require('@ntlab/sfetch')
const debug = require('debug')('site:mncvision.id')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
doFetch.setCheckResult(false).setDebugger(debug)
const languages = { en: 'english', id: 'indonesia' }
const cookies = {}
const timeout = 30000
module.exports = {
site: 'mncvision.id',
days: 2,
url: 'https://www.mncvision.id/schedule/table',
request: {
method: 'POST',
data({ channel, date }) {
const formData = new URLSearchParams()
formData.append('search_model', 'channel')
formData.append('af0rmelement', 'aformelement')
formData.append('fdate', date.format('YYYY-MM-DD'))
formData.append('fchannel', channel.site_id)
formData.append('submit', 'Search')
return formData
},
async headers({ channel }) {
const headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
if (channel) {
if (!cookies[channel.lang]) {
cookies[channel.lang] = await loadLangCookies(channel)
}
if (cookies[channel.lang]) {
headers.Cookie = cookies[channel.lang]
}
}
return headers
},
jar: null
},
async parser({ content, headers, date, channel }) {
if (!cookies[channel.lang]) {
cookies[channel.lang] = parseCookies(headers)
}
return await parseItems(content, date, cookies[channel.lang])
},
async channels({ lang = 'id' }) {
const result = await axios
.get('https://www.mncvision.id/schedule')
.then(response => response.data)
.catch(console.error)
const $ = cheerio.load(result)
const items = $('select[name="fchannel"] option').toArray()
const channels = items.map(item => {
const $item = $(item)
return {
lang,
site_id: $item.attr('value'),
name: $item.text().split(' - ')[0].trim()
}
})
return channels
}
}
function parseSeason($item) {
const title = parseTitle($item)
const [, season] = title.match(/ S(\d+)/) || [null, null]
return season ? parseInt(season) : null
}
function parseEpisode($item) {
const title = parseTitle($item)
const [, episode] = title.match(/ Ep (\d+)/) || [null, null]
return episode ? parseInt(episode) : null
}
function parseDuration($item) {
let duration = $item.find('td:nth-child(3)').text()
const match = duration.match(/(\d{2}):(\d{2})/)
const hours = parseInt(match[1])
const minutes = parseInt(match[2])
return hours * 60 + minutes
}
function parseStart($item, date) {
let time = $item.find('td:nth-child(1)').text()
time = `${date.format('DD/MM/YYYY')} ${time}`
return dayjs.tz(time, 'DD/MM/YYYY HH:mm', 'Asia/Jakarta')
}
function parseTitle($item) {
return $item.find('td:nth-child(2) > a').text()
}
async function parseItems(content, date, cookies) {
const programs = []
const $ = cheerio.load(content)
const items = $('tr[valign="top"]').toArray()
if (items.length) {
const queues = []
for (const item of items) {
const $item = $(item)
const url = $item.find('a').attr('href')
const headers = {
'X-Requested-With': 'XMLHttpRequest',
Cookie: cookies
}
queues.push({ i: $item, url, params: { headers, timeout } })
}
await doFetch(queues, (queue, res) => {
const $item = queue.i
const description = res ? cheerio.load(res)('.synopsis').text().trim() : null
const start = parseStart($item, date)
const duration = parseDuration($item)
const stop = start.add(duration, 'm')
programs.push({
title: parseTitle($item),
season: parseSeason($item),
episode: parseEpisode($item),
description: description && description !== '-' ? description : null,
start,
stop
})
})
}
return programs
}
function loadLangCookies(channel) {
const url = `https://www.mncvision.id/language_switcher/setlang/${languages[channel.lang]}/`
return axios
.get(url, { timeout })
.then(r => parseCookies(r.headers))
.catch(error => console.error(error.message))
}
function parseCookies(headers) {
const cookies = []
if (Array.isArray(headers['set-cookie'])) {
headers['set-cookie'].forEach(cookie => {
cookies.push(cookie.split('; ')[0])
})
}
return cookies.length ? cookies.join('; ') : null
}

View File

@@ -1,132 +1,132 @@
const { parser, url, request } = require('./mncvision.id.config.js')
const fs = require('fs')
const path = require('path')
const axios = require('axios')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
jest.mock('axios')
const date = dayjs.utc('2023-11-19').startOf('d')
const channel = {
site_id: '154',
xmltv_id: 'AXN.id',
lang: 'id'
}
const indonesiaHeaders = {
'set-cookie': [
's1nd0vL=uo6gsashc1rmloqbb50m6b13qkglfvpl; expires=Sat, 18-Nov-2023 20:45:02 GMT; Max-Age=7200; path=/; HttpOnly'
]
}
const englishHeaders = {
'set-cookie': [
's1nd0vL=imtot2v1cs0pbemaohj9fee3hlbqo699; expires=Sat, 18-Nov-2023 20:38:31 GMT; Max-Age=7200; path=/; HttpOnly'
]
}
axios.get.mockImplementation((url, opts) => {
if (url === 'https://www.mncvision.id/language_switcher/setlang/indonesia/') {
return Promise.resolve({
headers: indonesiaHeaders
})
}
if (url === 'https://www.mncvision.id/language_switcher/setlang/english/') {
return Promise.resolve({
headers: englishHeaders
})
}
if (
url === 'https://www.mncvision.id/schedule/detail/20231119001500154/Blue-Bloods-S13-Ep-19/1'
) {
const getCookie = headers => {
if (Array.isArray(headers['set-cookie'])) {
return headers['set-cookie'][0].split('; ')[0]
}
}
if (opts.headers['Cookie'] === getCookie(indonesiaHeaders)) {
return Promise.resolve({
data: fs.readFileSync(path.resolve(__dirname, '__data__/program_id.html'))
})
}
if (opts.headers['Cookie'] === getCookie(englishHeaders)) {
return Promise.resolve({
data: fs.readFileSync(path.resolve(__dirname, '__data__/program_en.html'))
})
}
}
return Promise.resolve({ data: '' })
})
it('can generate valid url', () => {
expect(url).toBe('https://www.mncvision.id/schedule/table')
})
it('can generate valid request method', () => {
expect(request.method).toBe('POST')
})
it('can generate valid request headers', async () => {
expect(await request.headers({ channel })).toMatchObject({
'Content-Type': 'application/x-www-form-urlencoded'
})
})
it('can generate valid request data', () => {
const data = request.data({ channel, date })
expect(data.get('search_model')).toBe('channel')
expect(data.get('af0rmelement')).toBe('aformelement')
expect(data.get('fdate')).toBe('2023-11-19')
expect(data.get('fchannel')).toBe('154')
expect(data.get('submit')).toBe('Search')
})
it('can parse response', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
const indonesiaResults = (
await parser({ date, content, channel, headers: indonesiaHeaders })
).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(indonesiaResults[0]).toMatchObject({
start: '2023-11-18T17:15:00.000Z',
stop: '2023-11-18T18:05:00.000Z',
title: 'Blue Bloods S13, Ep 19',
episode: 19,
description:
'Jamie bekerja sama dengan FDNY untuk menemukan pelaku pembakaran yang bertanggung jawab atas kebakaran hebat yang terjadi di fasilitas penyimpanan bukti milik NYPD.'
})
const englishResults = (
await parser({ date, content, channel: { ...channel, lang: 'en' }, headers: englishHeaders })
).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(englishResults[0]).toMatchObject({
start: '2023-11-18T17:15:00.000Z',
stop: '2023-11-18T18:05:00.000Z',
title: 'Blue Bloods S13, Ep 19',
episode: 19,
description:
'Jamie partners with the FDNY to find the arsonist responsible for a massive fire at an NYPD evidence storage facility.'
})
})
it('can handle empty guide', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
const results = await parser({
date,
channel,
content,
headers: indonesiaHeaders
})
expect(results).toMatchObject([])
})
const { parser, url, request } = require('./mncvision.id.config.js')
const fs = require('fs')
const path = require('path')
const axios = require('axios')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
jest.mock('axios')
const date = dayjs.utc('2023-11-19').startOf('d')
const channel = {
site_id: '154',
xmltv_id: 'AXN.id',
lang: 'id'
}
const indonesiaHeaders = {
'set-cookie': [
's1nd0vL=uo6gsashc1rmloqbb50m6b13qkglfvpl; expires=Sat, 18-Nov-2023 20:45:02 GMT; Max-Age=7200; path=/; HttpOnly'
]
}
const englishHeaders = {
'set-cookie': [
's1nd0vL=imtot2v1cs0pbemaohj9fee3hlbqo699; expires=Sat, 18-Nov-2023 20:38:31 GMT; Max-Age=7200; path=/; HttpOnly'
]
}
axios.get.mockImplementation((url, opts) => {
if (url === 'https://www.mncvision.id/language_switcher/setlang/indonesia/') {
return Promise.resolve({
headers: indonesiaHeaders
})
}
if (url === 'https://www.mncvision.id/language_switcher/setlang/english/') {
return Promise.resolve({
headers: englishHeaders
})
}
if (
url === 'https://www.mncvision.id/schedule/detail/20231119001500154/Blue-Bloods-S13-Ep-19/1'
) {
const getCookie = headers => {
if (Array.isArray(headers['set-cookie'])) {
return headers['set-cookie'][0].split('; ')[0]
}
}
if (opts.headers['Cookie'] === getCookie(indonesiaHeaders)) {
return Promise.resolve({
data: fs.readFileSync(path.resolve(__dirname, '__data__/program_id.html'))
})
}
if (opts.headers['Cookie'] === getCookie(englishHeaders)) {
return Promise.resolve({
data: fs.readFileSync(path.resolve(__dirname, '__data__/program_en.html'))
})
}
}
return Promise.resolve({ data: '' })
})
it('can generate valid url', () => {
expect(url).toBe('https://www.mncvision.id/schedule/table')
})
it('can generate valid request method', () => {
expect(request.method).toBe('POST')
})
it('can generate valid request headers', async () => {
expect(await request.headers({ channel })).toMatchObject({
'Content-Type': 'application/x-www-form-urlencoded'
})
})
it('can generate valid request data', () => {
const data = request.data({ channel, date })
expect(data.get('search_model')).toBe('channel')
expect(data.get('af0rmelement')).toBe('aformelement')
expect(data.get('fdate')).toBe('2023-11-19')
expect(data.get('fchannel')).toBe('154')
expect(data.get('submit')).toBe('Search')
})
it('can parse response', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
const indonesiaResults = (
await parser({ date, content, channel, headers: indonesiaHeaders })
).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(indonesiaResults[0]).toMatchObject({
start: '2023-11-18T17:15:00.000Z',
stop: '2023-11-18T18:05:00.000Z',
title: 'Blue Bloods S13, Ep 19',
episode: 19,
description:
'Jamie bekerja sama dengan FDNY untuk menemukan pelaku pembakaran yang bertanggung jawab atas kebakaran hebat yang terjadi di fasilitas penyimpanan bukti milik NYPD.'
})
const englishResults = (
await parser({ date, content, channel: { ...channel, lang: 'en' }, headers: englishHeaders })
).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(englishResults[0]).toMatchObject({
start: '2023-11-18T17:15:00.000Z',
stop: '2023-11-18T18:05:00.000Z',
title: 'Blue Bloods S13, Ep 19',
episode: 19,
description:
'Jamie partners with the FDNY to find the arsonist responsible for a massive fire at an NYPD evidence storage facility.'
})
})
it('can handle empty guide', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
const results = await parser({
date,
channel,
content,
headers: indonesiaHeaders
})
expect(results).toMatchObject([])
})