diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index 42d9ee1679..4222339ce9 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -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 diff --git a/scripts/format.js b/scripts/format.js index 58f24b4f6c..087d90bba6 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -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() diff --git a/scripts/sort.js b/scripts/sort.js new file mode 100644 index 0000000000..974f2592ce --- /dev/null +++ b/scripts/sort.js @@ -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()