Merge pull request #446 from iptv-org/update-tvtv.us

Update tvtv.us
This commit is contained in:
Aleksandr Statciuk 2022-01-23 15:13:22 +03:00 committed by GitHub
commit 55d306456b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,25 +34,65 @@ module.exports = {
return programs
},
async channels({ country }) {
const channels = []
const data = await axios
.get(`https://www.tvtv.${country}/api/stations`)
.then(r => r.data)
.catch(console.log)
return data.data
.filter(i => ['Satellite'].includes(i.type))
.map(item => {
return {
lang: 'en',
site_id: item.id,
xmltv_id: item.shortName,
name: item.name,
logo: item.logo
}
})
const stations = data.data.filter(i => !['Radio Station'].includes(i.type))
for (const station of stations) {
const stationData = await axios
.get(`https://www.tvtv.us/gn/d/v1.1/stations/${station.id}`)
.then(r => r.data[0] || {})
.catch(console.log)
if (!stationData) continue
let channel
const logo = parseChannelLogo(stationData.preferredImage)
switch (stationData.type) {
case 'Low Power Broadcast':
case 'Full Power Broadcast':
channel = {
site_id: station.id,
name: stationData.name,
xmltv_id: parseChannelId(stationData),
logo
}
break
default:
channel = {
site_id: station.id,
name: stationData.name,
logo
}
break
}
if (channel) {
channels.push(channel)
}
}
return channels
}
}
function parseChannelLogo(image) {
return image && image.uri ? `http://tvtv.tmsimg.com/${image.uri}` : null
}
function parseChannelId(data) {
if (!data.callSign) return null
if (/^((CB|C[F-K]|V[A-G]|VO|VX|VY|X[J-O])[0-9A-Z-]+)/.test(data.callSign))
return `${data.callSign}.ca`
if (/^((XH|XE)[0-9A-Z-]+)/.test(data.callSign)) return `${data.callSign}.mx`
if (/^((K|N|W)[0-9A-Z-]+)/.test(data.callSign)) return `${data.callSign}.us`
return null
}
function parseItems(content) {
return JSON.parse(content)
}