From 1c0554738988e4eaab41b09e8a05b1d4b389629a Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 2 Aug 2021 19:07:10 +0300 Subject: [PATCH] Updated Playlist.save() method --- scripts/clean.js | 1 + scripts/detect-resolution.js | 1 + scripts/format.js | 1 + scripts/helpers/Playlist.js | 7 +++---- scripts/remove-duplicates.js | 2 ++ 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/clean.js b/scripts/clean.js index cb5ecced2d..6b372cf2ab 100644 --- a/scripts/clean.js +++ b/scripts/clean.js @@ -90,6 +90,7 @@ async function checkStatus(playlist) { if (playlist.channels.length !== channels.length) { log.print(`File '${playlist.url}' has been updated\n`) playlist.channels = channels + playlist.updated = true } return playlist diff --git a/scripts/detect-resolution.js b/scripts/detect-resolution.js index 57c33267cf..5c01841f5d 100644 --- a/scripts/detect-resolution.js +++ b/scripts/detect-resolution.js @@ -86,6 +86,7 @@ async function detectResolution(playlist) { if (updated) { log.print(`File '${playlist.url}' has been updated\n`) playlist.channels = channels + playlist.updated = true } return playlist diff --git a/scripts/format.js b/scripts/format.js index b687eed2f0..0fa233f3f1 100644 --- a/scripts/format.js +++ b/scripts/format.js @@ -26,6 +26,7 @@ async function sortChannels(playlist) { if (JSON.stringify(playlist.channels) !== JSON.stringify(channels)) { log.print('updated') playlist.channels = channels + playlist.updated = true } return playlist diff --git a/scripts/helpers/Playlist.js b/scripts/helpers/Playlist.js index 5b26b4ac27..aaaf676ffc 100644 --- a/scripts/helpers/Playlist.js +++ b/scripts/helpers/Playlist.js @@ -10,6 +10,7 @@ module.exports = class Playlist { this.channels = items .map(item => new Channel({ data: item, header, sourceUrl: url })) .filter(channel => channel.url) + this.updated = false } toString(options = {}) { @@ -31,10 +32,8 @@ module.exports = class Playlist { } save() { - const original = file.read(this.url) - const output = this.toString() - if (original !== output) { - file.create(this.url, output) + if (this.updated) { + file.create(this.url, this.toString()) } } } diff --git a/scripts/remove-duplicates.js b/scripts/remove-duplicates.js index f2d62e919e..650fbab472 100644 --- a/scripts/remove-duplicates.js +++ b/scripts/remove-duplicates.js @@ -51,6 +51,7 @@ async function removeDuplicates(playlist) { if (playlist.channels.length !== channels.length) { log.print('updated') playlist.channels = channels + playlist.updated = true } return playlist @@ -74,6 +75,7 @@ async function removeUnsortedDuplicates(playlist) { if (channels.length !== playlist.channels.length) { log.print('updated') playlist.channels = channels + playlist.updated = true } return playlist