Merge pull request #2168 from iptv-org/remove-duplicates-from-index-country
Remove duplicates from index.country.m3u
This commit is contained in:
commit
e6a64f0880
|
@ -8,6 +8,7 @@ db.load = function () {
|
||||||
const items = parser.parseIndex()
|
const items = parser.parseIndex()
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const playlist = parser.parsePlaylist(item.url)
|
const playlist = parser.parsePlaylist(item.url)
|
||||||
|
db.playlists.add(playlist)
|
||||||
for (const channel of playlist.channels) {
|
for (const channel of playlist.channels) {
|
||||||
db.channels.add(channel)
|
db.channels.add(channel)
|
||||||
|
|
||||||
|
@ -166,4 +167,28 @@ db.categories = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.playlists = {
|
||||||
|
list: [],
|
||||||
|
add(playlist) {
|
||||||
|
this.list.push(playlist)
|
||||||
|
},
|
||||||
|
all() {
|
||||||
|
return this.list
|
||||||
|
},
|
||||||
|
only(list = []) {
|
||||||
|
return this.list.filter(playlist => list.includes(playlist.name))
|
||||||
|
},
|
||||||
|
except(list = []) {
|
||||||
|
return this.list.filter(playlist => !list.includes(playlist.name))
|
||||||
|
},
|
||||||
|
sortBy(fields) {
|
||||||
|
this.list = utils.sortBy(this.list, fields)
|
||||||
|
|
||||||
|
return this
|
||||||
|
},
|
||||||
|
count() {
|
||||||
|
return this.list.length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = db
|
module.exports = db
|
||||||
|
|
|
@ -67,20 +67,19 @@ function generateCountryIndex() {
|
||||||
const filename = `${ROOT_DIR}/index.country.m3u`
|
const filename = `${ROOT_DIR}/index.country.m3u`
|
||||||
utils.createFile(filename, '#EXTM3U\n')
|
utils.createFile(filename, '#EXTM3U\n')
|
||||||
|
|
||||||
const channels = db.channels.sortBy(['name', 'url']).forCountry({ code: null }).get()
|
const unsorted = db.playlists.only(['unsorted'])[0]
|
||||||
for (const channel of channels) {
|
for (const channel of unsorted.channels) {
|
||||||
const category = channel.category
|
const category = channel.category
|
||||||
channel.category = ''
|
channel.category = ''
|
||||||
utils.appendToFile(filename, channel.toString())
|
utils.appendToFile(filename, channel.toString())
|
||||||
channel.category = category
|
channel.category = category
|
||||||
}
|
}
|
||||||
|
|
||||||
const countries = db.countries.sortBy(['name']).all()
|
const playlists = db.playlists.sortBy(['country']).except(['unsorted'])
|
||||||
for (const country of countries) {
|
for (const playlist of playlists) {
|
||||||
const channels = db.channels.sortBy(['name', 'url']).forCountry(country).get()
|
for (const channel of playlist.channels) {
|
||||||
for (const channel of channels) {
|
|
||||||
const category = channel.category
|
const category = channel.category
|
||||||
channel.category = country.name
|
channel.category = playlist.country
|
||||||
utils.appendToFile(filename, channel.toString())
|
utils.appendToFile(filename, channel.toString())
|
||||||
channel.category = category
|
channel.category = category
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ const playlistParser = require('iptv-playlist-parser')
|
||||||
const epgParser = require('epg-parser')
|
const epgParser = require('epg-parser')
|
||||||
const utils = require('./utils')
|
const utils = require('./utils')
|
||||||
const categories = require('./categories')
|
const categories = require('./categories')
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
const parser = {}
|
const parser = {}
|
||||||
|
|
||||||
|
@ -15,8 +16,10 @@ parser.parseIndex = function () {
|
||||||
parser.parsePlaylist = function (filename) {
|
parser.parsePlaylist = function (filename) {
|
||||||
const content = utils.readFile(filename)
|
const content = utils.readFile(filename)
|
||||||
const result = playlistParser.parse(content)
|
const result = playlistParser.parse(content)
|
||||||
|
const name = path.parse(filename).name
|
||||||
|
const country = utils.code2name(name)
|
||||||
|
|
||||||
return new Playlist({ header: result.header, items: result.items, url: filename })
|
return new Playlist({ header: result.header, items: result.items, url: filename, country, name })
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.parseEPG = async function (url) {
|
parser.parseEPG = async function (url) {
|
||||||
|
@ -32,8 +35,10 @@ parser.parseEPG = async function (url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Playlist {
|
class Playlist {
|
||||||
constructor({ header, items, url }) {
|
constructor({ header, items, url, name, country }) {
|
||||||
this.url = url
|
this.url = url
|
||||||
|
this.name = name
|
||||||
|
this.country = country
|
||||||
this.header = header
|
this.header = header
|
||||||
this.channels = items
|
this.channels = items
|
||||||
.map(item => new Channel({ data: item, header, sourceUrl: url }))
|
.map(item => new Channel({ data: item, header, sourceUrl: url }))
|
||||||
|
|
Loading…
Reference in New Issue