From 147172fe720f8af8a219ba384c0407ca751e0321 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 23 Oct 2019 12:20:27 -0300 Subject: Add text/notes editor, using tui-text-editor :D! --- playlist-utils.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'playlist-utils.js') diff --git a/playlist-utils.js b/playlist-utils.js index de2c3f8..9c6f0ed 100644 --- a/playlist-utils.js +++ b/playlist-utils.js @@ -560,6 +560,15 @@ function isTrack(obj) { return !!(obj && obj.downloaderArg) } +function isPlayable(obj) { + return isGroup(obj) || isTrack(obj) +} + +function isOpenable(obj) { + return !!(obj && obj.url) +} + + function searchForItem(grouplike, value, preferredStartIndex = -1) { if (value.length) { // We prioritize searching past the index that the user opened the jump @@ -600,6 +609,31 @@ function searchForItem(grouplike, value, preferredStartIndex = -1) { return null } +function getCorrespondingFileForItem(item, extension) { + if (!(item && item.url)) { + return null + } + + const checkExtension = item => item.url && path.extname(item.url) === extension + + if (isPlayable(item)) { + const parent = item[parentSymbol] + + if (!parent) { + return null + } + + const basename = path.basename(item.url, path.extname(item.url)) + return parent.items.find(item => checkExtension(item) && path.basename(item.url, extension) === basename) + } + + if (checkExtension(item)) { + return item + } + + return null +} + module.exports = { parentSymbol, updatePlaylistFormat, updateGroupFormat, updateTrackFormat, @@ -618,5 +652,7 @@ module.exports = { getTrackIndexInParent, getNameWithoutTrackNumber, searchForItem, - isGroup, isTrack + getCorrespondingFileForItem, + isGroup, isTrack, + isOpenable, isPlayable } -- cgit 1.3.0-6-gf8a5