From daa8c4cd672106c3c87ca2e075cd415aa0e4e1e9 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sat, 22 Jul 2023 09:24:46 -0500 Subject: [PATCH] Update:Remove sort index from podcast episodes --- client/components/modals/item/tabs/Episodes.vue | 16 ++++++---------- server/managers/PodcastManager.js | 2 +- server/objects/mediaTypes/Podcast.js | 14 -------------- server/scanner/MediaFileScanner.js | 3 +-- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/client/components/modals/item/tabs/Episodes.vue b/client/components/modals/item/tabs/Episodes.vue index f64eea4e..661f41e0 100644 --- a/client/components/modals/item/tabs/Episodes.vue +++ b/client/components/modals/item/tabs/Episodes.vue @@ -20,18 +20,14 @@
{{ $strings.MessageNoEpisodes }}
- - - - - + + + + - -
Sort #{{ $strings.LabelEpisode }}{{ $strings.EpisodeTitle }}{{ $strings.EpisodeDuration }}{{ $strings.EpisodeSize }}{{ $strings.LabelEpisode }}{{ $strings.LabelEpisodeTitle }}{{ $strings.LabelEpisodeDuration }}{{ $strings.LabelEpisodeSize }}
-

{{ episode.index }}

-
-

{{ episode.episode }}

+
+

{{ episode.episode }}

{{ episode.title }} diff --git a/server/managers/PodcastManager.js b/server/managers/PodcastManager.js index ce16c2d3..9fe96793 100644 --- a/server/managers/PodcastManager.js +++ b/server/managers/PodcastManager.js @@ -50,7 +50,7 @@ class PodcastManager { } async downloadPodcastEpisodes(libraryItem, episodesToDownload, isAutoDownload) { - let index = libraryItem.media.episodes.length + 1 + let index = Math.max(...libraryItem.media.episodes.filter(ep => ep.index == null || isNaN(ep.index)).map(ep => Number(ep.index))) + 1 for (const ep of episodesToDownload) { const newPe = new PodcastEpisode() newPe.setData(ep, index++) diff --git a/server/objects/mediaTypes/Podcast.js b/server/objects/mediaTypes/Podcast.js index d4023740..808bfe32 100644 --- a/server/objects/mediaTypes/Podcast.js +++ b/server/objects/mediaTypes/Podcast.js @@ -285,7 +285,6 @@ class Podcast { addPodcastEpisode(podcastEpisode) { this.episodes.push(podcastEpisode) - this.reorderEpisodes() } addNewEpisodeFromAudioFile(audioFile, index) { @@ -297,19 +296,6 @@ class Podcast { this.episodes.push(pe) } - reorderEpisodes() { - var hasUpdates = false - - this.episodes = naturalSort(this.episodes).desc((ep) => ep.publishedAt) - for (let i = 0; i < this.episodes.length; i++) { - if (this.episodes[i].index !== (i + 1)) { - this.episodes[i].index = i + 1 - hasUpdates = true - } - } - return hasUpdates - } - removeEpisode(episodeId) { const episode = this.episodes.find(ep => ep.id === episodeId) if (episode) { diff --git a/server/scanner/MediaFileScanner.js b/server/scanner/MediaFileScanner.js index 5831ec49..a644a6e0 100644 --- a/server/scanner/MediaFileScanner.js +++ b/server/scanner/MediaFileScanner.js @@ -278,11 +278,10 @@ class MediaFileScanner { const existingAudioFiles = mediaScanResult.audioFiles.filter(af => libraryItem.media.findFileWithInode(af.ino)) if (newAudioFiles.length) { - let newIndex = libraryItem.media.episodes.length + 1 + let newIndex = Math.max(...libraryItem.media.episodes.filter(ep => ep.index == null || isNaN(ep.index)).map(ep => Number(ep.index))) + 1 newAudioFiles.forEach((newAudioFile) => { libraryItem.media.addNewEpisodeFromAudioFile(newAudioFile, newIndex++) }) - libraryItem.media.reorderEpisodes() hasUpdated = true }