Fix linter issues in sites/

This commit is contained in:
freearhey 2025-01-01 12:27:22 +03:00
parent d6d20b6413
commit 5df982bb7c
129 changed files with 3316 additions and 3226 deletions

View file

@ -1,81 +1,85 @@
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(customParseFormat)
dayjs.extend(timezone)
module.exports = {
site: 'cosmotetv.gr',
days: 5,
request: {
cache: {
ttl: 60 * 60 * 1000 // 1 hour
},
method: 'GET',
headers: {
'referer': 'https://www.cosmotetv.gr/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.9',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Origin': 'https://www.cosmotetv.gr',
'Sec-Ch-Ua': '"Not.A/Brand";v="24", "Chromium";v="131", "Google Chrome";v="131"',
'Sec-Ch-Ua-Mobile': '?0',
'Sec-Ch-Ua-Platform': '"Windows"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'cross-site'
}
},
url: function ({date, channel}) {
const startOfDay = dayjs(date).startOf('day').utc().unix()
const endOfDay = dayjs(date).endOf('day').utc().unix()
return `https://mwapi-prod.cosmotetvott.gr/api/v3.4/epg/listings/el?from=${startOfDay}&to=${endOfDay}&callSigns=${channel.site_id}&endingIncludedInRange=false`
},
parser: function ({ date, content }) {
let programs = []
const data = JSON.parse(content)
data.channels.forEach(channel => {
channel.items.forEach(item => {
const start = dayjs(item.startTime).utc().toISOString()
const stop = dayjs(item.endTime).utc().toISOString()
programs.push({
title: item.title,
description: item.description || 'No description available',
category: item.qoe.genre,
image: item.thumbnails.standard,
start,
stop
})
})
})
return programs
},
async channels() {
const axios = require('axios')
try {
const response = await axios.get('https://mwapi-prod.cosmotetvott.gr/api/v3.4/epg/channels/all/el', {
headers: this.request.headers
})
const data = response.data
if (data && data.channels) {
return data.channels.map(item => ({
lang: 'el',
site_id: item.callSign,
name: item.title,
//logo: item.logos.square
}))
} else {
console.error('Unexpected response structure:', data)
return []
}
} catch (error) {
console.error('Error fetching channel data:', error)
return []
}
}
}
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(customParseFormat)
dayjs.extend(timezone)
module.exports = {
site: 'cosmotetv.gr',
days: 5,
request: {
cache: {
ttl: 60 * 60 * 1000 // 1 hour
},
method: 'GET',
headers: {
referer: 'https://www.cosmotetv.gr/',
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
Accept: '*/*',
'Accept-Language': 'en-US,en;q=0.9',
'Accept-Encoding': 'gzip, deflate, br, zstd',
Origin: 'https://www.cosmotetv.gr',
'Sec-Ch-Ua': '"Not.A/Brand";v="24", "Chromium";v="131", "Google Chrome";v="131"',
'Sec-Ch-Ua-Mobile': '?0',
'Sec-Ch-Ua-Platform': '"Windows"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'cross-site'
}
},
url: function ({ date, channel }) {
const startOfDay = dayjs(date).startOf('day').utc().unix()
const endOfDay = dayjs(date).endOf('day').utc().unix()
return `https://mwapi-prod.cosmotetvott.gr/api/v3.4/epg/listings/el?from=${startOfDay}&to=${endOfDay}&callSigns=${channel.site_id}&endingIncludedInRange=false`
},
parser: function ({ content }) {
let programs = []
const data = JSON.parse(content)
data.channels.forEach(channel => {
channel.items.forEach(item => {
const start = dayjs(item.startTime).utc().toISOString()
const stop = dayjs(item.endTime).utc().toISOString()
programs.push({
title: item.title,
description: item.description || 'No description available',
category: item.qoe.genre,
image: item.thumbnails.standard,
start,
stop
})
})
})
return programs
},
async channels() {
const axios = require('axios')
try {
const response = await axios.get(
'https://mwapi-prod.cosmotetvott.gr/api/v3.4/epg/channels/all/el',
{
headers: this.request.headers
}
)
const data = response.data
if (data && data.channels) {
return data.channels.map(item => ({
lang: 'el',
site_id: item.callSign,
name: item.title
//logo: item.logos.square
}))
} else {
console.error('Unexpected response structure:', data)
return []
}
} catch (error) {
console.error('Error fetching channel data:', error)
return []
}
}
}

View file

@ -1,81 +1,76 @@
const { parser, url, channels } = require('./cosmotetv.gr.config.js')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
const timezone = require('dayjs/plugin/timezone')
const axios = require('axios')
dayjs.extend(utc)
dayjs.extend(customParseFormat)
dayjs.extend(timezone)
jest.mock('axios')
const date = dayjs.utc('2024-12-26', 'YYYY-MM-DD').startOf('d')
const channel = { site_id: 'vouli', xmltv_id: 'HellenicParliamentTV.gr' }
const mockChannelData = {
"channels": [
{
"guid": "XTV100000954",
"title": "ΒΟΥΛΗ HD",
"callSign": "vouli",
"logos": {
"square": "https://tr.static.cdn.cosmotetvott.gr/ote-prod/channel_logos/vouli1-normal.png",
"wide": "https://tr.static.cdn.cosmotetvott.gr/ote-prod/channel_logos/vouli1-wide.png"
}
}
]
}
const mockEpgData = {
"channels": [
{
"items": [
{
"startTime": "2024-12-26T23:00:00+00:00",
"endTime": "2024-12-27T00:00:00+00:00",
"title": "Τι Λέει ο Νόμος",
"description": "νημερωτική εκπομπή. Συζήτηση με τους εισηγητές των κομμάτων για το νομοθετικό έργο.",
"qoe": {
"genre": "Special"
},
"thumbnails": {
"standard": "https://gr-ermou-prod-cache05.static.cdn.cosmotetvott.gr/ote-prod/70/280/040029714812000800_1734415727199.jpg"
}
}
]
}
]
}
it('can generate valid url', () => {
const startOfDay = dayjs(date).startOf('day').utc().unix()
const endOfDay = dayjs(date).endOf('day').utc().unix()
expect(url({ date, channel })).toBe(`https://mwapi-prod.cosmotetvott.gr/api/v3.4/epg/listings/el?from=${startOfDay}&to=${endOfDay}&callSigns=${channel.site_id}&endingIncludedInRange=false`)
})
it('can parse response', () => {
const content = JSON.stringify(mockEpgData)
const result = parser({ date, content }).map(p => {
p.start = dayjs(p.start).toISOString()
p.stop = dayjs(p.stop).toISOString()
return p
})
expect(result).toMatchObject([
{
title: "Τι Λέει ο Νόμος",
description: "νημερωτική εκπομπή. Συζήτηση με τους εισηγητές των κομμάτων για το νομοθετικό έργο.",
category: "Special",
image: "https://gr-ermou-prod-cache05.static.cdn.cosmotetvott.gr/ote-prod/70/280/040029714812000800_1734415727199.jpg",
start: "2024-12-26T23:00:00.000Z",
stop: "2024-12-27T00:00:00.000Z"
}
])
})
it('can handle empty guide', () => {
const result = parser({ date, channel, content: '{"date":"2024-12-26","categories":[],"channels":[]}' });
expect(result).toMatchObject([])
})
const { parser, url } = require('./cosmotetv.gr.config.js')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(customParseFormat)
dayjs.extend(timezone)
jest.mock('axios')
const date = dayjs.utc('2024-12-26', 'YYYY-MM-DD').startOf('d')
const channel = { site_id: 'vouli', xmltv_id: 'HellenicParliamentTV.gr' }
const mockEpgData = {
channels: [
{
items: [
{
startTime: '2024-12-26T23:00:00+00:00',
endTime: '2024-12-27T00:00:00+00:00',
title: 'Τι Λέει ο Νόμος',
description:
'νημερωτική εκπομπή. Συζήτηση με τους εισηγητές των κομμάτων για το νομοθετικό έργο.',
qoe: {
genre: 'Special'
},
thumbnails: {
standard:
'https://gr-ermou-prod-cache05.static.cdn.cosmotetvott.gr/ote-prod/70/280/040029714812000800_1734415727199.jpg'
}
}
]
}
]
}
it('can generate valid url', () => {
const startOfDay = dayjs(date).startOf('day').utc().unix()
const endOfDay = dayjs(date).endOf('day').utc().unix()
expect(url({ date, channel })).toBe(
`https://mwapi-prod.cosmotetvott.gr/api/v3.4/epg/listings/el?from=${startOfDay}&to=${endOfDay}&callSigns=${channel.site_id}&endingIncludedInRange=false`
)
})
it('can parse response', () => {
const content = JSON.stringify(mockEpgData)
const result = parser({ date, content }).map(p => {
p.start = dayjs(p.start).toISOString()
p.stop = dayjs(p.stop).toISOString()
return p
})
expect(result).toMatchObject([
{
title: 'Τι Λέει ο Νόμος',
description:
'νημερωτική εκπομπή. Συζήτηση με τους εισηγητές των κομμάτων για το νομοθετικό έργο.',
category: 'Special',
image:
'https://gr-ermou-prod-cache05.static.cdn.cosmotetvott.gr/ote-prod/70/280/040029714812000800_1734415727199.jpg',
start: '2024-12-26T23:00:00.000Z',
stop: '2024-12-27T00:00:00.000Z'
}
])
})
it('can handle empty guide', () => {
const result = parser({
date,
channel,
content: '{"date":"2024-12-26","categories":[],"channels":[]}'
})
expect(result).toMatchObject([])
})