mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
document.addEventListener('alpine:init', () => {
|
|
Alpine.data('list', () => ({
|
|
isLoading: true,
|
|
query: '',
|
|
_query: '',
|
|
items: [],
|
|
|
|
search() {
|
|
this._query = this.query.toLowerCase()
|
|
},
|
|
|
|
async init() {
|
|
const countries = await fetch('api/countries.json')
|
|
.then(response => response.json())
|
|
.catch(console.log)
|
|
|
|
const channels = await fetch('api/channels.json')
|
|
.then(response => response.json())
|
|
.catch(console.log)
|
|
|
|
let items = {}
|
|
for (let channel of channels) {
|
|
if (!items[channel.country]) {
|
|
if (!countries[channel.country]) {
|
|
console.log('Warning: Wrong country code', channel)
|
|
continue
|
|
}
|
|
|
|
const country = countries[channel.country]
|
|
|
|
items[channel.country] = {
|
|
flag: country.flag,
|
|
name: country.name,
|
|
expanded: false,
|
|
channels: []
|
|
}
|
|
}
|
|
|
|
channel.hash = `${channel.id}_${channel.name}`.toLowerCase()
|
|
|
|
items[channel.country].channels.push(channel)
|
|
}
|
|
|
|
items = Object.values(items).sort((a, b) => {
|
|
if (a.name > b.name) return 1
|
|
if (a.name < b.name) return -1
|
|
return 0
|
|
})
|
|
|
|
this.items = items
|
|
this.isLoading = false
|
|
}
|
|
}))
|
|
})
|