diff options
author | (quasar) nebula <towerofnix@gmail.com> | 2021-04-03 15:30:41 -0300 |
---|---|---|
committer | (quasar) nebula <towerofnix@gmail.com> | 2021-04-03 15:30:41 -0300 |
commit | 1ca458abc3503ba951c5e19362a54208a285833c (patch) | |
tree | f0f2f42d84246394373d687056f6b06eaca248be | |
parent | c685a6bb545b80192aa6aeaa0654a8390c5ea755 (diff) | |
parent | 80577b066352fe2dfecd706302e183a5705c193b (diff) |
Merge branch 'master' into socket-mtui
-rw-r--r-- | playlist-utils.js | 45 | ||||
-rw-r--r-- | todo.txt | 3 |
2 files changed, 40 insertions, 8 deletions
diff --git a/playlist-utils.js b/playlist-utils.js index 899a349..979c6d6 100644 --- a/playlist-utils.js +++ b/playlist-utils.js @@ -536,24 +536,29 @@ function getTrackIndexInParent(track) { const nameWithoutTrackNumberSymbol = Symbol('Cached name without track number') function getNameWithoutTrackNumber(track) { // A "part" is a series of numeric digits, separated from other parts by - // whitespace and dashes, always preceding either the first non-numeric/ - // separator character or (if there are no such characters) the first word - // (i.e. last whitespace). + // whitespace, dashes, and dots, always preceding either the first non- + // numeric/separator character or (if there are no such characters) the + // first word (i.e. last whitespace). const getNumberOfParts = ({ name }) => { - const match = name.match(/[^0-9\-\s]/) + name = name.replace(/^[\-\s.]+$/, '') + const match = name.match(/[^0-9\-\s.]/) if (match) { - name = name.slice(0, match.index) + if (match.index === 0) { + return 0 + } else { + name = name.slice(0, match.index) + } } else if (name.includes(' ')) { name = name.slice(0, name.lastIndexOf(' ')) } else { return 0 } - name = name.replace(/[\-\s]+$/, '') - return name.split(/[\-\s]+/g).length + name = name.replace(/[\-\s.]+$/, '') + return name.split(/[\-\s.]+/g).length } const removeParts = (name, numParts) => { - const regex = new RegExp(`([0-9]+[\\-\\s]+){${numParts},${numParts}}`) + const regex = new RegExp(String.raw`[\-\s.]{0,}([0-9]+[\-\s.]+){${numParts},${numParts}}`) return track.name.replace(regex, '') } @@ -1032,4 +1037,28 @@ if (require.main === module) { ]}) ) )) + + { + const group = updateGroupFormat({items: [ + {name: '- 1.01 Hello World 425', downloaderArg: 'x'}, + {name: '1.02 Aww Yeah 371', downloaderArg: 'x'}, + {name: ' 1.03 Here Goes 472', downloaderArg: 'x'} + ]}) + + for (let i = 0; i < group.items.length; i++) { + console.log(group.items[i].name, '->', getNameWithoutTrackNumber(group.items[i])) + } + } + + { + const group = updateGroupFormat({items: [ + {name: 'BAM #1', downloaderArg: 'x'}, + {name: 'BAM #2', downloaderArg: 'x'}, + {name: 'BAM #3.1 - no', downloaderArg: 'x'} + ]}) + + for (let i = 0; i < group.items.length; i++) { + console.log(group.items[i].name, '->', getNameWithoutTrackNumber(group.items[i])) + } + } } diff --git a/todo.txt b/todo.txt index 34784cc..ed7c830 100644 --- a/todo.txt +++ b/todo.txt @@ -569,10 +569,13 @@ TODO: Multipage context menu doesn't work well in the queue - fix this by TODO: Names like "10. Banana" don't get cropped! Dots/dashes *after* a number apparently don't get caught. Oops. + (Done!) TODO: "BAM #45.3 - no" displays as "BAM #45.no" in the queue? Seems wrong! + (Done!) TODO: "Challenge 1 (Tricks)" etc in FP World 3 are "Challenge (Tricks)"! Bad. + (Done!) TODO: Pressing next track (shift+N) on the last track should start the first track, if the queue is being looped. |