Move sort operation to separate file

This commit is contained in:
Aleksandr Statciuk 2021-08-02 21:34:54 +03:00
parent 6c6fc992af
commit d9637bf158
3 changed files with 57 additions and 10 deletions

View File

@ -57,9 +57,30 @@ jobs:
commit_author: 'iptv-bot[bot] <84861620+iptv-bot[bot]@users.noreply.github.com>'
branch: bot/auto-update
file_pattern: channels/*
filter:
sort:
runs-on: ubuntu-latest
needs: format
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: bot/auto-update
- name: Install Dependencies
run: npm install
- name: Sort Channels
run: node scripts/sort.js
- name: Commit Changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: '[Bot] Sort channels'
commit_user_name: iptv-bot
commit_user_email: 84861620+iptv-bot[bot]@users.noreply.github.com
commit_author: 'iptv-bot[bot] <84861620+iptv-bot[bot]@users.noreply.github.com>'
branch: bot/auto-update
file_pattern: channels/*
filter:
runs-on: ubuntu-latest
needs: sort
steps:
- name: Checkout
uses: actions/checkout@v2

View File

@ -15,7 +15,6 @@ async function main() {
.parsePlaylist(playlist.url)
.then(removeWrongCategories)
.then(addMissingData)
.then(sortChannels)
.then(playlist => {
if (file.read(playlist.url) !== playlist.toString()) {
log.print('updated')
@ -65,12 +64,4 @@ async function addMissingData(playlist) {
return playlist
}
async function sortChannels(playlist) {
const channels = [...playlist.channels]
utils.sortBy(channels, ['name', 'url'])
playlist.channels = channels
return playlist
}
main()

35
scripts/sort.js Normal file
View File

@ -0,0 +1,35 @@
const parser = require('./helpers/parser')
const utils = require('./helpers/utils')
const log = require('./helpers/log')
async function main() {
log.start()
log.print(`Parsing 'index.m3u'...`)
let playlists = parser.parseIndex().filter(i => i.url !== 'channels/unsorted.m3u')
for (const playlist of playlists) {
log.print(`\nProcessing '${playlist.url}'...`)
await parser
.parsePlaylist(playlist.url)
.then(sortChannels)
.then(p => p.save())
}
log.print('\n')
log.finish()
}
async function sortChannels(playlist) {
const channels = [...playlist.channels]
utils.sortBy(channels, ['name', 'url'])
if (JSON.stringify(channels) !== JSON.stringify(playlist.channels)) {
log.print('updated')
playlist.channels = channels
playlist.updated = true
}
return playlist
}
main()