mirror of
https://github.com/iptv-org/iptv.git
synced 2026-11-24 01:01:01 +02:00
Sort internal playlists after stream updates
This commit is contained in:
@@ -9,6 +9,7 @@ import { loadData, data } from '../../api'
|
||||
import cliProgress from 'cli-progress'
|
||||
import { eachLimit } from 'async'
|
||||
import os from 'node:os'
|
||||
import { sortStreams } from '../../core/sortStreams'
|
||||
|
||||
program
|
||||
.argument('[filepath...]', 'Path to file to format')
|
||||
@@ -110,16 +111,7 @@ async function main() {
|
||||
progressBar.stop()
|
||||
|
||||
logger.info('sorting links...')
|
||||
streams = streams.sortBy(
|
||||
[
|
||||
(stream: Stream) => stream.title,
|
||||
(stream: Stream) => (stream.isGeoBlocked ? -1 : 0),
|
||||
(stream: Stream) => (stream.isNot247 ? -1 : 0),
|
||||
(stream: Stream) => stream.getVerticalResolution(),
|
||||
(stream: Stream) => stream.url
|
||||
],
|
||||
['asc', 'desc', 'desc', 'desc', 'asc']
|
||||
)
|
||||
streams = sortStreams(streams)
|
||||
|
||||
logger.info('saving...')
|
||||
const groupedStreams = streams.groupBy((stream: Stream) => stream.getFilepath())
|
||||
|
||||
@@ -6,9 +6,11 @@ import { Logger, Collection } from '@freearhey/core'
|
||||
import { Storage } from '@freearhey/storage-js'
|
||||
import { PlaylistParser } from '../../core'
|
||||
import * as sdk from '@iptv-org/sdk'
|
||||
import { sortStreams } from '../../core/sortStreams'
|
||||
|
||||
const processedIssues = new Collection<Issue>()
|
||||
const skippedIssues = new Collection<Issue>()
|
||||
const changedFiles = new Set<string>()
|
||||
const logger = new Logger({ level: 5 })
|
||||
|
||||
let streams = new Collection<Stream>()
|
||||
@@ -67,6 +69,7 @@ async function saveStreams() {
|
||||
for (const filepath of groupedStreams.keys()) {
|
||||
let filteredStreams = new Collection<Stream>(groupedStreams.get(filepath))
|
||||
filteredStreams = filteredStreams.filter((stream: Stream) => stream.removed === false)
|
||||
if (changedFiles.has(filepath)) filteredStreams = sortStreams(filteredStreams)
|
||||
|
||||
const playlist = new Playlist(filteredStreams, { public: false, raw: true })
|
||||
await streamsStorage.save(filepath, playlist.toString())
|
||||
@@ -126,6 +129,7 @@ async function removeStream(issue: Issue) {
|
||||
const found: Stream = streams.first((_stream: Stream) => _stream.url === link.trim())
|
||||
if (found) {
|
||||
found.removed = true
|
||||
changedFiles.add(found.getFilepath())
|
||||
changed = true
|
||||
log.info(`The stream with the URL "${link}" has been removed from the playlists`)
|
||||
} else {
|
||||
@@ -164,6 +168,7 @@ async function editStream(issue: Issue) {
|
||||
|
||||
cacheData()
|
||||
|
||||
const previousFilepath = stream.getFilepath()
|
||||
stream.updateWithIssue(data)
|
||||
|
||||
stream.setGuides(apiData.guidesGroupedByStreamId.get(stream.getId()))
|
||||
@@ -182,6 +187,8 @@ async function editStream(issue: Issue) {
|
||||
|
||||
log.info('The stream description has been updated')
|
||||
|
||||
changedFiles.add(previousFilepath)
|
||||
changedFiles.add(stream.getFilepath())
|
||||
processedIssues.add(issue)
|
||||
}
|
||||
|
||||
@@ -290,5 +297,6 @@ async function addStream(issue: Issue) {
|
||||
|
||||
log.info('The stream has been added to playlists')
|
||||
|
||||
changedFiles.add(stream.getFilepath())
|
||||
processedIssues.add(issue)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user