mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-13 02:20:03 -04:00
Update scripts
This commit is contained in:
parent
67b90d14bd
commit
143a8c8376
2 changed files with 23 additions and 45 deletions
|
@ -1,9 +1,8 @@
|
||||||
import { Logger, Storage, Collection, Dictionary, File } from '@freearhey/core'
|
import { Logger, Storage, Collection, Dictionary } from '@freearhey/core'
|
||||||
import { PlaylistParser } from '../../core'
|
import { PlaylistParser } from '../../core'
|
||||||
import { Channel, Stream, Blocked } from '../../models'
|
import { Channel, Stream, Blocked } from '../../models'
|
||||||
import { program } from 'commander'
|
import { program } from 'commander'
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
import { transliterate } from 'transliteration'
|
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import { DATA_DIR, STREAMS_DIR } from '../../constants'
|
import { DATA_DIR, STREAMS_DIR } from '../../constants'
|
||||||
|
|
||||||
|
@ -42,15 +41,12 @@ async function main() {
|
||||||
const streams = groupedStreams.get(filepath)
|
const streams = groupedStreams.get(filepath)
|
||||||
if (!streams) continue
|
if (!streams) continue
|
||||||
|
|
||||||
const file = new File(filepath)
|
|
||||||
const [, countryCode] = file.basename().match(/([a-z]{2})(|_.*)\.m3u/i) || [null, '']
|
|
||||||
|
|
||||||
const log = new Collection()
|
const log = new Collection()
|
||||||
const buffer = new Dictionary()
|
const buffer = new Dictionary()
|
||||||
streams.forEach((stream: Stream) => {
|
streams.forEach((stream: Stream) => {
|
||||||
const channelNotInDatabase =
|
const invalidId =
|
||||||
stream.channel && !channels.first((channel: Channel) => channel.id === stream.channel)
|
stream.channel && !channels.first((channel: Channel) => channel.id === stream.channel)
|
||||||
if (channelNotInDatabase) {
|
if (invalidId) {
|
||||||
log.add({
|
log.add({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
line: stream.line,
|
line: stream.line,
|
||||||
|
@ -58,8 +54,8 @@ async function main() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const alreadyOnPlaylist = stream.url && buffer.has(stream.url)
|
const duplicate = stream.url && buffer.has(stream.url)
|
||||||
if (alreadyOnPlaylist) {
|
if (duplicate) {
|
||||||
log.add({
|
log.add({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
line: stream.line,
|
line: stream.line,
|
||||||
|
@ -69,29 +65,22 @@ async function main() {
|
||||||
buffer.set(stream.url, true)
|
buffer.set(stream.url, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const channelId = generateChannelId(stream.name, countryCode)
|
const blocked = blocklist.first(blocked => stream.channel === blocked.channel)
|
||||||
const blocked = blocklist.first(
|
|
||||||
blocked =>
|
|
||||||
stream.channel.toLowerCase() === blocked.channel.toLowerCase() ||
|
|
||||||
channelId.toLowerCase() === blocked.channel.toLowerCase()
|
|
||||||
)
|
|
||||||
if (blocked) {
|
if (blocked) {
|
||||||
|
if (blocked.reason === 'dmca') {
|
||||||
log.add({
|
log.add({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
line: stream.line,
|
line: stream.line,
|
||||||
message: `"${stream.name}" is on the blocklist due to claims of copyright holders or NSFW content (${blocked.ref})`
|
message: `"${stream.channel}" is on the blocklist due to claims of copyright holders (${blocked.ref})`
|
||||||
})
|
})
|
||||||
}
|
} else if (blocked.reason === 'nsfw') {
|
||||||
|
|
||||||
const channel_NSFW = stream.channel && channels.first((channel: Channel) => (channel.id === stream.channel) && (channel.isNSFW === true))
|
|
||||||
if(channel_NSFW) {
|
|
||||||
log.add({
|
log.add({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
line: stream.line,
|
line: stream.line,
|
||||||
message: `Since January 30th, 2024, NSFW channels are no longer allowed in our playlists. Please see https://github.com/iptv-org/iptv/issues/15723 for further information.`
|
message: `"${stream.channel}" is on the blocklist due to NSFW content (${blocked.ref})`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (log.notEmpty()) {
|
if (log.notEmpty()) {
|
||||||
|
@ -124,17 +113,3 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
function generateChannelId(name: string, code: string) {
|
|
||||||
if (!name || !code) return ''
|
|
||||||
|
|
||||||
name = name.replace(/ *\([^)]*\) */g, '')
|
|
||||||
name = name.replace(/ *\[[^)]*\] */g, '')
|
|
||||||
name = name.replace(/\+/gi, 'Plus')
|
|
||||||
name = name.replace(/[^a-z\d]+/gi, '')
|
|
||||||
name = name.trim()
|
|
||||||
name = transliterate(name)
|
|
||||||
code = code.toLowerCase()
|
|
||||||
|
|
||||||
return `${name}.${code}`
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
type BlockedProps = {
|
type BlockedProps = {
|
||||||
channel: string
|
channel: string
|
||||||
|
reason: string
|
||||||
ref: string
|
ref: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Blocked {
|
export class Blocked {
|
||||||
channel: string
|
channel: string
|
||||||
|
reason: string
|
||||||
ref: string
|
ref: string
|
||||||
|
|
||||||
constructor({ ref, channel }: BlockedProps) {
|
constructor({ ref, reason, channel }: BlockedProps) {
|
||||||
this.channel = channel
|
this.channel = channel
|
||||||
|
this.reason = reason
|
||||||
this.ref = ref
|
this.ref = ref
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue