Files
epg/sites/magentatv.at/magentatv.at.config.js
T

142 lines
3.9 KiB
JavaScript
Raw Normal View History

2023-10-15 14:08:23 +03:00
const axios = require('axios')
2023-11-15 14:34:46 +01:00
const crypto = require('crypto')
2023-10-15 14:08:23 +03:00
const dayjs = require('dayjs')
2023-11-15 14:34:46 +01:00
const API_ENDPOINT = 'https://tv-at-prod.yo-digital.com/at-bifrost'
const headers = {
'Device-Id': crypto.randomUUID(),
'app_key': 'CTnKA63ruKM0JM1doxAXwwyQLLmQiEiy',
'app_version': '02.0.830',
'X-User-Agent': 'web|web|Firefox-120|02.0.830|1',
'x-request-tracking-id': crypto.randomUUID()
}
2023-10-15 14:08:23 +03:00
module.exports = {
site: 'magentatv.at',
days: 2,
request: {
2023-11-15 14:34:46 +01:00
headers,
2023-10-15 14:08:23 +03:00
cache: {
ttl: 60 * 60 * 1000 // 1 hour
}
},
2023-11-15 14:34:46 +01:00
url: function ({ channel, date }) {
return `${API_ENDPOINT}/epg/channel/schedules/v2?station_ids=${channel.site_id}&date=${date.format('YYYY-MM-DD')}&hour_offset=${date.format('H')}&hour_range=3&natco_code=at`
2023-10-15 14:08:23 +03:00
},
async parser({ content, channel, date }) {
let programs = []
2023-11-15 14:34:46 +01:00
if (!content) return programs
let items = parseItems(JSON.parse(content), channel)
2023-10-15 14:08:23 +03:00
if (!items.length) return programs
2023-11-15 14:34:46 +01:00
const promises = [3, 6, 9, 12, 15, 18, 21].map(i =>
axios.get(`${API_ENDPOINT}/epg/channel/schedules/v2?station_ids=${channel.site_id}&date=${date.format('YYYY-MM-DD')}&hour_offset=${i}&hour_range=3&natco_code=at`, {headers}))
2023-10-15 14:08:23 +03:00
await Promise.allSettled(promises)
.then(results => {
results.forEach(r => {
if (r.status === 'fulfilled') {
const parsed = parseItems(r.value.data, channel)
items = items.concat(parsed)
}
})
})
.catch(console.error)
for (let item of items) {
const detail = await loadProgramDetails(item)
programs.push({
2023-11-15 14:34:46 +01:00
title: item.description,
description: parseDescription(detail),
date: parseDate(item),
category: parseCategory(item),
icon: detail.poster_image_url,
actors: parseRoles(detail, 'Schauspieler'),
directors: parseRoles(detail, 'Regisseur'),
producers: parseRoles(detail, 'Produzent'),
season: parseSeason(item),
episode: parseEpisode(item),
2023-10-15 14:08:23 +03:00
start: parseStart(item),
stop: parseStop(item)
})
}
return programs
},
async channels() {
const data = await axios
2023-11-15 14:34:46 +01:00
.get(`${API_ENDPOINT}/epg/channel?natco_code=at`, {headers})
2023-10-15 14:08:23 +03:00
.then(r => r.data)
.catch(console.log)
return data.channels.map(item => {
return {
lang: 'de',
2023-11-15 14:34:46 +01:00
site_id: item.station_id,
name: item.title
2023-10-15 14:08:23 +03:00
}
})
}
}
async function loadProgramDetails(item) {
2023-11-15 14:34:46 +01:00
if (!item.program_id) return {}
const url = `${API_ENDPOINT}/details/series/${item.program_id}?natco_code=at`
2023-10-15 14:08:23 +03:00
const data = await axios
2023-11-15 14:34:46 +01:00
.get(url, {headers})
2023-10-15 14:08:23 +03:00
.then(r => r.data)
.catch(console.log)
return data || {}
}
2023-11-15 14:34:46 +01:00
function parseDate(item) {
return item && item.release_year ? item.release_year.toString() : null
}
2023-10-15 14:08:23 +03:00
function parseStart(item) {
2023-11-15 14:34:46 +01:00
return dayjs(item.start_time)
2023-10-15 14:08:23 +03:00
}
function parseStop(item) {
2023-11-15 14:34:46 +01:00
return dayjs(item.end_time)
2023-10-15 14:08:23 +03:00
}
2023-11-15 14:34:46 +01:00
function parseItems(data, channel) {
if (!data || !data.channels) return []
const channelData = data.channels[channel.site_id]
2023-10-15 14:08:23 +03:00
if (!channelData) return []
2023-11-15 14:34:46 +01:00
return channelData
2023-10-15 14:08:23 +03:00
}
2023-11-15 14:34:46 +01:00
function parseCategory(item) {
if (!item.genres) return null
return item.genres.map(genre => genre.id)
2023-10-15 14:08:23 +03:00
}
2023-11-15 14:34:46 +01:00
function parseSeason(item) {
if(item.season_display_number === 'Folgen') return null
return item.season_number
}
function parseEpisode(item) {
if(item.episode_number) return parseInt(item.episode_number)
if(item.season_display_number === 'Folgen') return item.season_number
return null
}
function parseDescription(item) {
if (!item.details) return null
return item.details.description
}
function parseRoles(item, role_name) {
if (!item.roles) return null
return item.roles
.filter(role => role.role_name === role_name)
.map(role => role.person_name)
2023-10-15 14:08:23 +03:00
}