Fixes linter errors

This commit is contained in:
freearhey
2023-10-15 14:08:23 +03:00
parent 57e508fc3b
commit 63c86a2b30
393 changed files with 28447 additions and 28443 deletions

View File

@@ -1,107 +1,107 @@
const dayjs = require('dayjs')
const axios = require('axios')
const parser = require('epg-parser')
const isBetween = require('dayjs/plugin/isBetween')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(isBetween)
dayjs.extend(customParseFormat)
const API_ENDPOINT = 'https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master'
module.exports = {
site: 'i.mjh.nz',
days: 2,
request: {
cache: {
ttl: 3 * 60 * 60 * 1000 // 3h
},
maxContentLength: 100 * 1024 * 1024 // 100Mb
},
url: function ({ channel }) {
const [path] = channel.site_id.split('#')
return `${API_ENDPOINT}/${path}.xml`
},
parser: function ({ content, channel, date }) {
const items = parseItems(content, channel, date)
let programs = items.map(item => {
return {
...item,
title: getTitle(item),
description: getDescription(item),
categories: getCategories(item)
}
})
programs = mergeMovieParts(programs)
return programs
},
async channels({ path, lang = 'en' }) {
let xml = await axios
.get(`${API_ENDPOINT}/${path}.xml`)
.then(r => r.data)
.catch(console.log)
let data = parser.parse(xml)
return data.channels.map(channel => {
return {
lang,
site_id: `${path}#${channel.id}`,
name: channel.name[0].value
}
})
}
}
function mergeMovieParts(programs) {
let output = []
programs.forEach(prog => {
let prev = output[output.length - 1]
let found =
prev &&
prog.categories.includes('Movie') &&
prev.title === prog.title &&
prev.description === prog.description
if (found) {
prev.stop = prog.stop
} else {
output.push(prog)
}
})
return output
}
function getTitle(item) {
return item.title.length ? item.title[0].value : null
}
function getDescription(item) {
return item.desc.length ? item.desc[0].value : null
}
function getCategories(item) {
return item.category.map(c => c.value)
}
function parseItems(content, channel, date) {
try {
const curr_day = date
const next_day = date.add(1, 'd')
const [, site_id] = channel.site_id.split('#')
const data = parser.parse(content)
if (!data || !Array.isArray(data.programs)) return []
return data.programs.filter(
p =>
p.channel === site_id && dayjs(p.start, 'YYYYMMDDHHmmss ZZ').isBetween(curr_day, next_day)
)
} catch (error) {
return []
}
}
const dayjs = require('dayjs')
const axios = require('axios')
const parser = require('epg-parser')
const isBetween = require('dayjs/plugin/isBetween')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(isBetween)
dayjs.extend(customParseFormat)
const API_ENDPOINT = 'https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master'
module.exports = {
site: 'i.mjh.nz',
days: 2,
request: {
cache: {
ttl: 3 * 60 * 60 * 1000 // 3h
},
maxContentLength: 100 * 1024 * 1024 // 100Mb
},
url: function ({ channel }) {
const [path] = channel.site_id.split('#')
return `${API_ENDPOINT}/${path}.xml`
},
parser: function ({ content, channel, date }) {
const items = parseItems(content, channel, date)
let programs = items.map(item => {
return {
...item,
title: getTitle(item),
description: getDescription(item),
categories: getCategories(item)
}
})
programs = mergeMovieParts(programs)
return programs
},
async channels({ path, lang = 'en' }) {
let xml = await axios
.get(`${API_ENDPOINT}/${path}.xml`)
.then(r => r.data)
.catch(console.log)
let data = parser.parse(xml)
return data.channels.map(channel => {
return {
lang,
site_id: `${path}#${channel.id}`,
name: channel.name[0].value
}
})
}
}
function mergeMovieParts(programs) {
let output = []
programs.forEach(prog => {
let prev = output[output.length - 1]
let found =
prev &&
prog.categories.includes('Movie') &&
prev.title === prog.title &&
prev.description === prog.description
if (found) {
prev.stop = prog.stop
} else {
output.push(prog)
}
})
return output
}
function getTitle(item) {
return item.title.length ? item.title[0].value : null
}
function getDescription(item) {
return item.desc.length ? item.desc[0].value : null
}
function getCategories(item) {
return item.category.map(c => c.value)
}
function parseItems(content, channel, date) {
try {
const curr_day = date
const next_day = date.add(1, 'd')
const [, site_id] = channel.site_id.split('#')
const data = parser.parse(content)
if (!data || !Array.isArray(data.programs)) return []
return data.programs.filter(
p =>
p.channel === site_id && dayjs(p.start, 'YYYYMMDDHHmmss ZZ').isBetween(curr_day, next_day)
)
} catch (error) {
return []
}
}

View File

@@ -1,50 +1,50 @@
// npm run channels:parse -- --config=./sites/i.mjh.nz/i.mjh.nz.config.js --output=./sites/i.mjh.nz/i.mjh.nz_pluto.channels.xml --set=path:PlutoTV/all
// npm run grab -- --site=i.mjh.nz
const { parser, url } = require('./i.mjh.nz.config.js')
const fs = require('fs')
const path = require('path')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
const date = dayjs.utc('2023-06-23', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'Plex/all#5e20b730f2f8d5003d739db7-5eea605674085f0040ddc7a6',
xmltv_id: 'DarkMatterTV.us',
lang: 'en'
}
it('can generate valid url', () => {
expect(url({ channel })).toBe(
'https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master/Plex/all.xml'
)
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.xml'))
const results = parser({ content, channel, date })
expect(results.length).toBe(11)
expect(results[0]).toMatchObject({
start: '2023-06-23T07:14:32.000Z',
stop: '2023-06-23T09:09:36.000Z',
title: 'Killers Within',
date: ['20180101'],
description:
'With her son being held captive by a criminal gang, police officer Amanda Doyle, together with her ex-husband and three unlikely allies, takes part in a desperate plot to hold a wealthy banker and his family to ransom. But this is no ordinary family.',
icon: ['https://provider-static.plex.tv/epg/images/thumbnails/darkmatter-tv-fallback.jpg'],
categories: ['Movie']
})
})
it('can handle empty guide', () => {
const result = parser({
content: '404: Not Found',
channel,
date
})
expect(result).toMatchObject([])
})
// npm run channels:parse -- --config=./sites/i.mjh.nz/i.mjh.nz.config.js --output=./sites/i.mjh.nz/i.mjh.nz_pluto.channels.xml --set=path:PlutoTV/all
// npm run grab -- --site=i.mjh.nz
const { parser, url } = require('./i.mjh.nz.config.js')
const fs = require('fs')
const path = require('path')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
const date = dayjs.utc('2023-06-23', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'Plex/all#5e20b730f2f8d5003d739db7-5eea605674085f0040ddc7a6',
xmltv_id: 'DarkMatterTV.us',
lang: 'en'
}
it('can generate valid url', () => {
expect(url({ channel })).toBe(
'https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master/Plex/all.xml'
)
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.xml'))
const results = parser({ content, channel, date })
expect(results.length).toBe(11)
expect(results[0]).toMatchObject({
start: '2023-06-23T07:14:32.000Z',
stop: '2023-06-23T09:09:36.000Z',
title: 'Killers Within',
date: ['20180101'],
description:
'With her son being held captive by a criminal gang, police officer Amanda Doyle, together with her ex-husband and three unlikely allies, takes part in a desperate plot to hold a wealthy banker and his family to ransom. But this is no ordinary family.',
icon: ['https://provider-static.plex.tv/epg/images/thumbnails/darkmatter-tv-fallback.jpg'],
categories: ['Movie']
})
})
it('can handle empty guide', () => {
const result = parser({
content: '404: Not Found',
channel,
date
})
expect(result).toMatchObject([])
})