Fix linter issues

This commit is contained in:
freearhey 2025-01-16 13:33:18 +03:00
parent 10475ab929
commit 8d1348cc46
3 changed files with 156 additions and 151 deletions

View file

@ -1,64 +1,64 @@
const axios = require('axios') const axios = require('axios')
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone') const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat') const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc) dayjs.extend(utc)
dayjs.extend(timezone) dayjs.extend(timezone)
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
module.exports = { module.exports = {
site: 'galamtv.kz', site: 'galamtv.kz',
timezone: 'Asia/Almaty', timezone: 'Asia/Almaty',
days: 2, days: 2,
request: { request: {
method: 'GET', method: 'GET',
headers: { headers: {
Referer: 'https://galamtv.kz/', Referer: 'https://galamtv.kz/',
Origin: 'https://galamtv.kz', Origin: 'https://galamtv.kz',
Accept: '*/*', Accept: '*/*',
'Accept-Encoding': 'gzip, deflate, br, zstd' 'Accept-Encoding': 'gzip, deflate, br, zstd'
} }
}, },
url({ channel, date }) { url({ channel, date }) {
const todayEpoch = date.startOf('day').unix() const todayEpoch = date.startOf('day').unix()
const nextDayEpoch = date.add(1, 'day').startOf('day').unix() const nextDayEpoch = date.add(1, 'day').startOf('day').unix()
return `https://galam.server-api.lfstrm.tv/channels/${channel.site_id}/programs?period=${todayEpoch}:${nextDayEpoch}` return `https://galam.server-api.lfstrm.tv/channels/${channel.site_id}/programs?period=${todayEpoch}:${nextDayEpoch}`
}, },
parser: function ({ content }) { parser: function ({ content }) {
let programs = [] let programs = []
const data = JSON.parse(content) const data = JSON.parse(content)
const programsData = data.programs || [] const programsData = data.programs || []
programsData.forEach(program => { programsData.forEach(program => {
const start = dayjs.unix(program.scheduleInfo.start) const start = dayjs.unix(program.scheduleInfo.start)
const stop = dayjs.unix(program.scheduleInfo.end) const stop = dayjs.unix(program.scheduleInfo.end)
programs.push({ programs.push({
title: program.metaInfo.title, title: program.metaInfo.title,
description: program.metaInfo.description, description: program.metaInfo.description,
image: program.mediaInfo.thumbnails[0].url, image: program.mediaInfo.thumbnails[0].url,
start, start,
stop stop
}) })
}) })
return programs return programs
}, },
async channels() { async channels() {
try { try {
const response = await axios.get(`https://galam.server-api.lfstrm.tv/channels-now`) const response = await axios.get('https://galam.server-api.lfstrm.tv/channels-now')
return response.data.channels.map(item => { return response.data.channels.map(item => {
return { return {
lang: 'kk', lang: 'kk',
site_id: item.channels.id, site_id: item.channels.id,
name: item.channels.info.metaInfo.title name: item.channels.info.metaInfo.title
} }
}) })
} catch (error) { } catch (error) {
console.error('Error fetching channels:', error) console.error('Error fetching channels:', error)
return [] return []
} }
} }
} }

View file

@ -1,66 +1,71 @@
const { parser, url, channels } = require('./galamtv.kz.config.js') const { parser, url } = require('./galamtv.kz.config.js')
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat') const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
dayjs.extend(utc) dayjs.extend(utc)
const date = dayjs.utc('2025-01-10', 'YYYY-MM-DD').startOf('d') const date = dayjs.utc('2025-01-10', 'YYYY-MM-DD').startOf('d')
const channel = { const channel = {
site_id: '636e54cf8a8f73bae8244f41', site_id: '636e54cf8a8f73bae8244f41',
xmltv_id: 'Qazaqstan.kz' xmltv_id: 'Qazaqstan.kz'
} }
it('can generate valid url', () => { it('can generate valid url', () => {
expect(url({ date, channel })).toBe(`https://galam.server-api.lfstrm.tv/channels/${channel.site_id}/programs?period=${date.unix()}:${date.add(1, 'day').unix()}`) expect(url({ date, channel })).toBe(
}) `https://galam.server-api.lfstrm.tv/channels/${
channel.site_id
it('can parse response', () => { }/programs?period=${date.unix()}:${date.add(1, 'day').unix()}`
const content = JSON.stringify({ )
programs: [ })
{
metaInfo: { it('can parse response', () => {
title: "Гимн", const content = JSON.stringify({
description: "Государственный гимн Республики Казахстан" programs: [
}, {
scheduleInfo: { metaInfo: {
start: 1736470800, title: 'Гимн',
end: 1736471100 description: 'Государственный гимн Республики Казахстан'
}, },
mediaInfo: { scheduleInfo: {
thumbnails: [ start: 1736470800,
{ end: 1736471100
url: "http://galam.server-img.lfstrm.tv:80/image/aHR0cDovL2dhbGFtLmltZy1vcmlnaW5hbHMubGZzdHJtLnR2OjgwL3R2aW1hZ2VzL3RodW1iL2YyNWFmYWY2ZDkzYjU5YjdkMjBiZDNiODhiZjg4NWI0X29yaWcuanBn" },
} mediaInfo: {
] thumbnails: [
} {
} url: 'http://galam.server-img.lfstrm.tv:80/image/aHR0cDovL2dhbGFtLmltZy1vcmlnaW5hbHMubGZzdHJtLnR2OjgwL3R2aW1hZ2VzL3RodW1iL2YyNWFmYWY2ZDkzYjU5YjdkMjBiZDNiODhiZjg4NWI0X29yaWcuanBn'
] }
}) ]
}
const result = parser({ content, channel }).map(p => { }
p.start = p.start.toJSON() ]
p.stop = p.stop.toJSON() })
return p
}) const result = parser({ content, channel }).map(p => {
p.start = p.start.toJSON()
expect(result).toMatchObject([ p.stop = p.stop.toJSON()
{ return p
start: '2025-01-10T01:00:00.000Z', })
stop: '2025-01-10T01:05:00.000Z',
title: 'Гимн', expect(result).toMatchObject([
description: 'Государственный гимн Республики Казахстан', {
image: 'http://galam.server-img.lfstrm.tv:80/image/aHR0cDovL2dhbGFtLmltZy1vcmlnaW5hbHMubGZzdHJtLnR2OjgwL3R2aW1hZ2VzL3RodW1iL2YyNWFmYWY2ZDkzYjU5YjdkMjBiZDNiODhiZjg4NWI0X29yaWcuanBn', start: '2025-01-10T01:00:00.000Z',
} stop: '2025-01-10T01:05:00.000Z',
]) title: 'Гимн',
}) description: 'Государственный гимн Республики Казахстан',
image:
it('can handle empty guide', () => { 'http://galam.server-img.lfstrm.tv:80/image/aHR0cDovL2dhbGFtLmltZy1vcmlnaW5hbHMubGZzdHJtLnR2OjgwL3R2aW1hZ2VzL3RodW1iL2YyNWFmYWY2ZDkzYjU5YjdkMjBiZDNiODhiZjg4NWI0X29yaWcuanBn'
const result = parser({ }
date, ])
channel, })
content: '{"programs":[]}'
}) it('can handle empty guide', () => {
expect(result).toMatchObject([]) const result = parser({
}) date,
channel,
content: '{"programs":[]}'
})
expect(result).toMatchObject([])
})

View file

@ -1,21 +1,21 @@
# galamtv.kz # galamtv.kz
https://galamtv.kz/channels/now https://galamtv.kz/channels/now
### Download the guide ### Download the guide
```sh ```sh
npm run grab --- --site=galamtv.kz npm run grab --- --site=galamtv.kz
``` ```
### Update channel list ### Update channel list
```sh ```sh
npm run channels:parse --- --config=./sites/galamtv.kz/galamtv.kz.config.js --output=./sites/galamtv.kz/galamtv.kz.channels.xml npm run channels:parse --- --config=./sites/galamtv.kz/galamtv.kz.config.js --output=./sites/galamtv.kz/galamtv.kz.channels.xml
``` ```
### Test ### Test
```sh ```sh
npm test --- galamtv.kz npm test --- galamtv.kz
``` ```