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,79 +1,79 @@
const axios = require('axios')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(timezone)
dayjs.extend(utc)
const API_ENDPOINT = 'https://www.kplus.vn/Schedule/getSchedule'
module.exports = {
site: 'kplus.vn',
days: 2,
url: API_ENDPOINT,
request: {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data({ date }) {
const params = new URLSearchParams()
params.append('date', date.format('D-M-YYYY'))
params.append('categories', '')
return params
},
method: 'POST'
},
parser: function ({ content, channel }) {
let programs = []
const items = parseItems(content, channel)
items.forEach(item => {
const prev = programs[programs.length - 1]
const start = parseStart(item)
const stop = start.add(1, 'h')
if (prev) prev.stop = start
programs.push({
title: item.Program.Name,
icon: item.Program.Images,
category: item.Program.Genres,
start,
stop
})
})
return programs
},
async channels() {
const params = new URLSearchParams()
params.append('date', dayjs().format('D-M-YYYY'))
params.append('categories', '')
const data = await axios
.post(API_ENDPOINT, params, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(r => r.data)
.catch(console.log)
return data.Channels.map(item => {
return {
lang: 'vi',
site_id: item.Id,
name: item.Name
}
})
}
}
function parseStart(item) {
return dayjs.tz(item.ShowingTime, 'Asia/Ho_Chi_Minh')
}
function parseItems(content, channel) {
const data = JSON.parse(content)
if (!data || !Array.isArray(data.Schedules)) return []
return data.Schedules.filter(i => i.ChannelId == channel.site_id)
}
const axios = require('axios')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(timezone)
dayjs.extend(utc)
const API_ENDPOINT = 'https://www.kplus.vn/Schedule/getSchedule'
module.exports = {
site: 'kplus.vn',
days: 2,
url: API_ENDPOINT,
request: {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data({ date }) {
const params = new URLSearchParams()
params.append('date', date.format('D-M-YYYY'))
params.append('categories', '')
return params
},
method: 'POST'
},
parser: function ({ content, channel }) {
let programs = []
const items = parseItems(content, channel)
items.forEach(item => {
const prev = programs[programs.length - 1]
const start = parseStart(item)
const stop = start.add(1, 'h')
if (prev) prev.stop = start
programs.push({
title: item.Program.Name,
icon: item.Program.Images,
category: item.Program.Genres,
start,
stop
})
})
return programs
},
async channels() {
const params = new URLSearchParams()
params.append('date', dayjs().format('D-M-YYYY'))
params.append('categories', '')
const data = await axios
.post(API_ENDPOINT, params, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(r => r.data)
.catch(console.log)
return data.Channels.map(item => {
return {
lang: 'vi',
site_id: item.Id,
name: item.Name
}
})
}
}
function parseStart(item) {
return dayjs.tz(item.ShowingTime, 'Asia/Ho_Chi_Minh')
}
function parseItems(content, channel) {
const data = JSON.parse(content)
if (!data || !Array.isArray(data.Schedules)) return []
return data.Schedules.filter(i => i.ChannelId == channel.site_id)
}

View File

@@ -1,67 +1,67 @@
// npm run channels:parse -- --config=sites/kplus.vn/kplus.vn.config.js --output=sites/kplus.vn/kplus.vn.channels.xml
// npm run grab -- --site=kplus.vn
const { parser, url, request } = require('./kplus.vn.config.js')
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('2022-03-15', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '7019',
xmltv_id: 'KPlus1HD.vn'
}
it('can generate valid url', () => {
expect(url).toBe('https://www.kplus.vn/Schedule/getSchedule')
})
it('can generate valid request headers', () => {
expect(request.headers).toMatchObject({
'Content-Type': 'application/x-www-form-urlencoded'
})
})
it('can generate valid request data', () => {
const data = request.data({ date })
expect(data.get('date')).toBe('15-3-2022')
expect(data.get('categories')).toBe('')
})
it('can parse response', () => {
const content =
'{"SchedulesCount":1105,"ChannelsCount":28,"Schedules":[{"Id":12195,"ChannelId":7019,"ProgramId":35111026,"EpgProgramId":"1252496\\r","ShowingTime":"2022-03-15T06:15:00","EpgBroadcastId":"HD_ENT_DOC_LNO_21_2649421_2652183_4383385_OnAir","EpgId":"HD_ENT_DOC_LNO_21_2649421_2652183_4383385_OnAir","IsDeleted":false,"CreatedOn":"2022-03-15T06:22:45","UpdatedOn":"0001-01-01T00:00:00","Channel":{"Id":7019,"Name":"K+1 HD","Image":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","LiveUrlSegment":"highlights/broadcast-schedule/K-1-HD","FeatureImage":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","EpgId":null,"IsOTTEnabled":false,"StartOver":0,"DisplayOrder":0},"Program":{"Id":35111026,"Name":"WEEKLY FILMS AND STARS, EP740","BodyContent":"","Cast":"","Director":"","Duration":0,"EpgId":"93701","EpgProgramId":null,"Episode":0,"Genres":"Documentary","Images":"https://img.kplus.vn/images?filename=Media/HDVN/2022_02/ENT_DOC_LNO_21_2649421_2652183_2652183.jpg","IsFeatured":false,"IsOTTEnabled":true,"IsRebroadcast":false,"ShortDescription":"","SubTitle":"","Trailers":"","UrlSegment":"highlights/broadcast-schedule/93701/weekly-films-and-stars-ep740","CreatedOn":"2022-03-16T00:15:45","UpdatedOn":"2022-03-16T00:15:45","ParentalRating":null},"RelatedSchedules":null},{"Id":12196,"ChannelId":7019,"ProgramId":35111279,"EpgProgramId":"798685\\r","ShowingTime":"2022-03-15T07:00:00","EpgBroadcastId":"HD_MOV_COM__2632318_4383386_OnAir","EpgId":"HD_MOV_COM__2632318_4383386_OnAir","IsDeleted":false,"CreatedOn":"2022-03-15T07:02:46","UpdatedOn":"0001-01-01T00:00:00","Channel":{"Id":7019,"Name":"K+1 HD","Image":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","LiveUrlSegment":"highlights/broadcast-schedule/K-1-HD","FeatureImage":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","EpgId":null,"IsOTTEnabled":false,"StartOver":0,"DisplayOrder":0},"Program":{"Id":35111279,"Name":"ST. VINCENT","BodyContent":"","Cast":"Bill Murray, Melissa McCarthy, Naomi Watts","Director":"Theodore Melfi","Duration":0,"EpgId":"93959","EpgProgramId":null,"Episode":0,"Genres":"Comedy","Images":"https://img.kplus.vn/images?filename=Media/HDVN/2020_05/MOV_COM__2632318_2632318.jpg","IsFeatured":false,"IsOTTEnabled":true,"IsRebroadcast":false,"ShortDescription":"","SubTitle":"","Trailers":"","UrlSegment":"highlights/broadcast-schedule/93959/st-vincent","CreatedOn":"2022-03-16T00:15:45","UpdatedOn":"2022-03-16T00:15:45","ParentalRating":null},"RelatedSchedules":null}]}'
const result = parser({ content, channel }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2022-03-14T23:15:00.000Z',
stop: '2022-03-15T00:00:00.000Z',
title: 'WEEKLY FILMS AND STARS, EP740',
icon: 'https://img.kplus.vn/images?filename=Media/HDVN/2022_02/ENT_DOC_LNO_21_2649421_2652183_2652183.jpg',
category: 'Documentary'
},
{
start: '2022-03-15T00:00:00.000Z',
stop: '2022-03-15T01:00:00.000Z',
title: 'ST. VINCENT',
icon: 'https://img.kplus.vn/images?filename=Media/HDVN/2020_05/MOV_COM__2632318_2632318.jpg',
category: 'Comedy'
}
])
})
it('can handle empty guide', () => {
const result = parser({
content: '{"SchedulesCount":0,"ChannelsCount":0,"Schedules":[],"Channels":[],"MinDuration":0}',
channel
})
expect(result).toMatchObject([])
})
// npm run channels:parse -- --config=sites/kplus.vn/kplus.vn.config.js --output=sites/kplus.vn/kplus.vn.channels.xml
// npm run grab -- --site=kplus.vn
const { parser, url, request } = require('./kplus.vn.config.js')
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('2022-03-15', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '7019',
xmltv_id: 'KPlus1HD.vn'
}
it('can generate valid url', () => {
expect(url).toBe('https://www.kplus.vn/Schedule/getSchedule')
})
it('can generate valid request headers', () => {
expect(request.headers).toMatchObject({
'Content-Type': 'application/x-www-form-urlencoded'
})
})
it('can generate valid request data', () => {
const data = request.data({ date })
expect(data.get('date')).toBe('15-3-2022')
expect(data.get('categories')).toBe('')
})
it('can parse response', () => {
const content =
'{"SchedulesCount":1105,"ChannelsCount":28,"Schedules":[{"Id":12195,"ChannelId":7019,"ProgramId":35111026,"EpgProgramId":"1252496\\r","ShowingTime":"2022-03-15T06:15:00","EpgBroadcastId":"HD_ENT_DOC_LNO_21_2649421_2652183_4383385_OnAir","EpgId":"HD_ENT_DOC_LNO_21_2649421_2652183_4383385_OnAir","IsDeleted":false,"CreatedOn":"2022-03-15T06:22:45","UpdatedOn":"0001-01-01T00:00:00","Channel":{"Id":7019,"Name":"K+1 HD","Image":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","LiveUrlSegment":"highlights/broadcast-schedule/K-1-HD","FeatureImage":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","EpgId":null,"IsOTTEnabled":false,"StartOver":0,"DisplayOrder":0},"Program":{"Id":35111026,"Name":"WEEKLY FILMS AND STARS, EP740","BodyContent":"","Cast":"","Director":"","Duration":0,"EpgId":"93701","EpgProgramId":null,"Episode":0,"Genres":"Documentary","Images":"https://img.kplus.vn/images?filename=Media/HDVN/2022_02/ENT_DOC_LNO_21_2649421_2652183_2652183.jpg","IsFeatured":false,"IsOTTEnabled":true,"IsRebroadcast":false,"ShortDescription":"","SubTitle":"","Trailers":"","UrlSegment":"highlights/broadcast-schedule/93701/weekly-films-and-stars-ep740","CreatedOn":"2022-03-16T00:15:45","UpdatedOn":"2022-03-16T00:15:45","ParentalRating":null},"RelatedSchedules":null},{"Id":12196,"ChannelId":7019,"ProgramId":35111279,"EpgProgramId":"798685\\r","ShowingTime":"2022-03-15T07:00:00","EpgBroadcastId":"HD_MOV_COM__2632318_4383386_OnAir","EpgId":"HD_MOV_COM__2632318_4383386_OnAir","IsDeleted":false,"CreatedOn":"2022-03-15T07:02:46","UpdatedOn":"0001-01-01T00:00:00","Channel":{"Id":7019,"Name":"K+1 HD","Image":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","LiveUrlSegment":"highlights/broadcast-schedule/K-1-HD","FeatureImage":"https://kplus-website-production-cdn.azureedge.net/content/upload/7/images-mkt/logo-k-1-hd-new.png","EpgId":null,"IsOTTEnabled":false,"StartOver":0,"DisplayOrder":0},"Program":{"Id":35111279,"Name":"ST. VINCENT","BodyContent":"","Cast":"Bill Murray, Melissa McCarthy, Naomi Watts","Director":"Theodore Melfi","Duration":0,"EpgId":"93959","EpgProgramId":null,"Episode":0,"Genres":"Comedy","Images":"https://img.kplus.vn/images?filename=Media/HDVN/2020_05/MOV_COM__2632318_2632318.jpg","IsFeatured":false,"IsOTTEnabled":true,"IsRebroadcast":false,"ShortDescription":"","SubTitle":"","Trailers":"","UrlSegment":"highlights/broadcast-schedule/93959/st-vincent","CreatedOn":"2022-03-16T00:15:45","UpdatedOn":"2022-03-16T00:15:45","ParentalRating":null},"RelatedSchedules":null}]}'
const result = parser({ content, channel }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2022-03-14T23:15:00.000Z',
stop: '2022-03-15T00:00:00.000Z',
title: 'WEEKLY FILMS AND STARS, EP740',
icon: 'https://img.kplus.vn/images?filename=Media/HDVN/2022_02/ENT_DOC_LNO_21_2649421_2652183_2652183.jpg',
category: 'Documentary'
},
{
start: '2022-03-15T00:00:00.000Z',
stop: '2022-03-15T01:00:00.000Z',
title: 'ST. VINCENT',
icon: 'https://img.kplus.vn/images?filename=Media/HDVN/2020_05/MOV_COM__2632318_2632318.jpg',
category: 'Comedy'
}
])
})
it('can handle empty guide', () => {
const result = parser({
content: '{"SchedulesCount":0,"ChannelsCount":0,"Schedules":[],"Channels":[],"MinDuration":0}',
channel
})
expect(result).toMatchObject([])
})