Updated Playlist.save() method

This commit is contained in:
Aleksandr Statciuk 2021-08-02 19:07:10 +03:00
parent 27136370aa
commit 1c05547389
5 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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())
}
}
}

View File

@ -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