mirror of
https://github.com/iptv-org/iptv
synced 2026-05-17 23:15:10 -04:00
[Bot] Update playlists (#4600)
* Update Playlist.js * Install axios package * Create epg.js * Update db.js * Update format.js * Update Channel.js * Update db.js * Update generate.js * [Bot] Format playlists * [Bot] Remove duplicates * [Bot] Sort channels * [Bot] Update README.md * [Bot] Format playlists * [Bot] Remove duplicates * [Bot] Sort channels * [Bot] Update README.md Co-authored-by: Aleksandr Statciuk <free.arhey@gmail.com> Co-authored-by: iptv-bot[bot] <84861620+iptv-bot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -187,10 +187,6 @@ function parseRequests(requests) {
|
||||
|
||||
function updateDescription(channel, playlist) {
|
||||
const code = playlist.country.code
|
||||
// tvg-name
|
||||
if (!channel.tvg.name && channel.name) {
|
||||
channel.tvg.name = channel.name.replace(/\"/gi, '')
|
||||
}
|
||||
// tvg-id
|
||||
if (!channel.tvg.id && channel.tvg.name) {
|
||||
const id = utils.name2id(channel.tvg.name)
|
||||
|
||||
@@ -36,13 +36,16 @@ function createNoJekyllFile() {
|
||||
|
||||
function generateIndex() {
|
||||
log.print('Generating index.m3u...\n')
|
||||
const channels = db.channels.sortBy(['name', 'url']).removeDuplicates().removeOffline().get()
|
||||
const guides = channels.map(channel => channel.tvg.url)
|
||||
|
||||
const filename = `${ROOT_DIR}/index.m3u`
|
||||
file.create(filename, '#EXTM3U\n')
|
||||
const urlTvg = generateUrlTvg(guides)
|
||||
file.create(filename, `#EXTM3U url-tvg="${urlTvg}"\n`)
|
||||
|
||||
const nsfwFilename = `${ROOT_DIR}/index.nsfw.m3u`
|
||||
file.create(nsfwFilename, '#EXTM3U\n')
|
||||
file.create(nsfwFilename, `#EXTM3U url-tvg="${urlTvg}"\n`)
|
||||
|
||||
const channels = db.channels.sortBy(['name', 'url']).removeDuplicates().removeOffline().get()
|
||||
for (const channel of channels) {
|
||||
if (!channel.isNSFW()) {
|
||||
file.append(filename, channel.toString())
|
||||
@@ -53,14 +56,17 @@ function generateIndex() {
|
||||
|
||||
function generateCategoryIndex() {
|
||||
log.print('Generating index.category.m3u...\n')
|
||||
const filename = `${ROOT_DIR}/index.category.m3u`
|
||||
file.create(filename, '#EXTM3U\n')
|
||||
|
||||
const channels = db.channels
|
||||
.sortBy(['category', 'name', 'url'])
|
||||
.removeDuplicates()
|
||||
.removeOffline()
|
||||
.get()
|
||||
const guides = channels.map(channel => channel.tvg.url)
|
||||
|
||||
const filename = `${ROOT_DIR}/index.category.m3u`
|
||||
const urlTvg = generateUrlTvg(guides)
|
||||
file.create(filename, `#EXTM3U url-tvg="${urlTvg}"\n`)
|
||||
|
||||
for (const channel of channels) {
|
||||
file.append(filename, channel.toString())
|
||||
}
|
||||
@@ -68,50 +74,56 @@ function generateCategoryIndex() {
|
||||
|
||||
function generateCountryIndex() {
|
||||
log.print('Generating index.country.m3u...\n')
|
||||
const filename = `${ROOT_DIR}/index.country.m3u`
|
||||
file.create(filename, '#EXTM3U\n')
|
||||
|
||||
const guides = []
|
||||
const lines = []
|
||||
for (const country of [{ code: 'undefined' }, ...db.countries.sortBy(['name']).all()]) {
|
||||
const channels = db.channels
|
||||
.sortBy(['name', 'url'])
|
||||
.forCountry(country)
|
||||
.removeDuplicates()
|
||||
.removeNSFW()
|
||||
.removeOffline()
|
||||
.get()
|
||||
for (const channel of channels) {
|
||||
const groupTitle = channel.group.title
|
||||
const nsfw = channel.isNSFW()
|
||||
channel.group.title = country.name || ''
|
||||
if (!nsfw) {
|
||||
file.append(filename, channel.toString())
|
||||
}
|
||||
lines.push(channel.toString())
|
||||
channel.group.title = groupTitle
|
||||
guides.push(channel.tvg.url)
|
||||
}
|
||||
}
|
||||
|
||||
const filename = `${ROOT_DIR}/index.country.m3u`
|
||||
const urlTvg = generateUrlTvg(guides)
|
||||
file.create(filename, `#EXTM3U url-tvg="${urlTvg}"\n${lines.join('')}`)
|
||||
}
|
||||
|
||||
function generateLanguageIndex() {
|
||||
log.print('Generating index.language.m3u...\n')
|
||||
const filename = `${ROOT_DIR}/index.language.m3u`
|
||||
file.create(filename, '#EXTM3U\n')
|
||||
|
||||
const guides = []
|
||||
const lines = []
|
||||
for (const language of [{ code: 'undefined' }, ...db.languages.sortBy(['name']).all()]) {
|
||||
const channels = db.channels
|
||||
.sortBy(['name', 'url'])
|
||||
.forLanguage(language)
|
||||
.removeDuplicates()
|
||||
.removeNSFW()
|
||||
.removeOffline()
|
||||
.get()
|
||||
for (const channel of channels) {
|
||||
const groupTitle = channel.group.title
|
||||
const nsfw = channel.isNSFW()
|
||||
channel.group.title = language.name || ''
|
||||
if (!nsfw) {
|
||||
file.append(filename, channel.toString())
|
||||
}
|
||||
lines.push(channel.toString())
|
||||
channel.group.title = groupTitle
|
||||
guides.push(channel.tvg.url)
|
||||
}
|
||||
}
|
||||
|
||||
const filename = `${ROOT_DIR}/index.language.m3u`
|
||||
const urlTvg = generateUrlTvg(guides)
|
||||
file.create(filename, `#EXTM3U url-tvg="${urlTvg}"\n${lines.join('')}`)
|
||||
}
|
||||
|
||||
function generateCategories() {
|
||||
@@ -120,15 +132,17 @@ function generateCategories() {
|
||||
file.createDir(outputDir)
|
||||
|
||||
for (const category of [...db.categories.all(), { id: 'other' }]) {
|
||||
const filename = `${outputDir}/${category.id}.m3u`
|
||||
file.create(filename, '#EXTM3U\n')
|
||||
|
||||
const channels = db.channels
|
||||
.sortBy(['name', 'url'])
|
||||
.forCategory(category)
|
||||
.removeDuplicates()
|
||||
.removeOffline()
|
||||
.get()
|
||||
const guides = channels.map(channel => channel.tvg.url)
|
||||
|
||||
const filename = `${outputDir}/${category.id}.m3u`
|
||||
const urlTvg = generateUrlTvg(guides)
|
||||
file.create(filename, `#EXTM3U url-tvg="${urlTvg}"\n`)
|
||||
for (const channel of channels) {
|
||||
file.append(filename, channel.toString())
|
||||
}
|
||||
@@ -141,19 +155,20 @@ function generateCountries() {
|
||||
file.createDir(outputDir)
|
||||
|
||||
for (const country of [...db.countries.all(), { code: 'undefined' }]) {
|
||||
const filename = `${outputDir}/${country.code}.m3u`
|
||||
file.create(filename, '#EXTM3U\n')
|
||||
|
||||
const channels = db.channels
|
||||
.sortBy(['name', 'url'])
|
||||
.forCountry(country)
|
||||
.removeDuplicates()
|
||||
.removeOffline()
|
||||
.removeNSFW()
|
||||
.get()
|
||||
const guides = channels.map(channel => channel.tvg.url)
|
||||
|
||||
const filename = `${outputDir}/${country.code}.m3u`
|
||||
const urlTvg = generateUrlTvg(guides)
|
||||
file.create(filename, `#EXTM3U url-tvg="${urlTvg}"\n`)
|
||||
for (const channel of channels) {
|
||||
if (!channel.isNSFW()) {
|
||||
file.append(filename, channel.toString())
|
||||
}
|
||||
file.append(filename, channel.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,19 +179,20 @@ function generateLanguages() {
|
||||
file.createDir(outputDir)
|
||||
|
||||
for (const language of [...db.languages.all(), { code: 'undefined' }]) {
|
||||
const filename = `${outputDir}/${language.code}.m3u`
|
||||
file.create(filename, '#EXTM3U\n')
|
||||
|
||||
const channels = db.channels
|
||||
.sortBy(['name', 'url'])
|
||||
.forLanguage(language)
|
||||
.removeDuplicates()
|
||||
.removeOffline()
|
||||
.removeNSFW()
|
||||
.get()
|
||||
const guides = channels.map(channel => channel.tvg.url)
|
||||
|
||||
const filename = `${outputDir}/${language.code}.m3u`
|
||||
const urlTvg = generateUrlTvg(guides)
|
||||
file.create(filename, `#EXTM3U url-tvg="${urlTvg}"\n`)
|
||||
for (const channel of channels) {
|
||||
if (!channel.isNSFW()) {
|
||||
file.append(filename, channel.toString())
|
||||
}
|
||||
file.append(filename, channel.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,4 +213,13 @@ function showResults() {
|
||||
)
|
||||
}
|
||||
|
||||
function generateUrlTvg(guides) {
|
||||
const output = guides.reduce((acc, curr) => {
|
||||
if (curr && !acc.includes(curr)) acc.push(curr)
|
||||
return acc
|
||||
}, [])
|
||||
|
||||
return output.sort().join(',')
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@@ -148,7 +148,7 @@ module.exports = class Channel {
|
||||
countries: this.countries,
|
||||
tvg: {
|
||||
id: this.tvg.id || null,
|
||||
name: this.tvg.name || null,
|
||||
name: this.tvg.name || this.name.replace(/\"/gi, ''),
|
||||
url: this.tvg.url || null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,17 +11,21 @@ module.exports = class Playlist {
|
||||
this.updated = false
|
||||
}
|
||||
|
||||
toString(options = {}) {
|
||||
const config = { raw: false, ...options }
|
||||
let parts = ['#EXTM3U']
|
||||
getHeader() {
|
||||
let header = ['#EXTM3U']
|
||||
for (let key in this.header.attrs) {
|
||||
let value = this.header.attrs[key]
|
||||
if (value) {
|
||||
parts.push(`${key}="${value}"`)
|
||||
header.push(`${key}="${value}"`)
|
||||
}
|
||||
}
|
||||
|
||||
let output = `${parts.join(' ')}\n`
|
||||
return header.join(' ')
|
||||
}
|
||||
|
||||
toString(options = {}) {
|
||||
const config = { raw: false, ...options }
|
||||
let output = `${this.getHeader()}\n`
|
||||
for (let channel of this.channels) {
|
||||
output += channel.toString(config.raw)
|
||||
}
|
||||
|
||||
@@ -2,15 +2,21 @@ const categories = require('../data/categories')
|
||||
const parser = require('./parser')
|
||||
const utils = require('./utils')
|
||||
const file = require('./file')
|
||||
const epg = require('./epg')
|
||||
|
||||
const db = {}
|
||||
|
||||
db.load = async function () {
|
||||
let files = await file.list()
|
||||
const files = await file.list()
|
||||
const codes = await epg.codes.load()
|
||||
for (const file of files) {
|
||||
const playlist = await parser.parsePlaylist(file)
|
||||
db.playlists.add(playlist)
|
||||
for (const channel of playlist.channels) {
|
||||
const code = codes.find(ch => ch['tvg_id'] === channel.tvg.id)
|
||||
if (code && Array.isArray(code.guides) && code.guides.length) {
|
||||
channel.tvg.url = code.guides[0]
|
||||
}
|
||||
|
||||
db.channels.add(channel)
|
||||
|
||||
for (const country of channel.countries) {
|
||||
@@ -25,6 +31,8 @@ db.load = async function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.playlists.add(playlist)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
12
scripts/helpers/epg.js
Normal file
12
scripts/helpers/epg.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const axios = require('axios')
|
||||
|
||||
module.exports = {
|
||||
codes: {
|
||||
async load() {
|
||||
return await axios
|
||||
.get('https://iptv-org.github.io/epg/codes.json')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user