Skip to content

Commit 0a273b0

Browse files
committed
Use more verbose queue track names
In addition to the track title, include: - track number - artist If the title is not defined, use the file path
1 parent a6b6e3e commit 0a273b0

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,13 +1170,25 @@ function addBatchToPlayQueue( files, autoplay = false ) {
11701170
});
11711171
}
11721172

1173+
function extractFileNameFromPath(path) {
1174+
if (typeof path !== 'string') return '';
1175+
1176+
const lastSlashIndex = path.lastIndexOf('/');
1177+
const lastDotIndex = path.lastIndexOf('.');
1178+
1179+
const start = lastSlashIndex >= 0 ? lastSlashIndex + 1 : 0;
1180+
const end = lastDotIndex > start ? lastDotIndex : path.length;
1181+
1182+
return path.substring(start, end);
1183+
}
1184+
11731185
/**
11741186
* Add audio metadata to a playlist item or audio element
11751187
*/
11761188
function addMetadata( metadata, target ) {
11771189
const trackData = target.dataset,
11781190
sourceData = metadata.dataset,
1179-
{ album, artist, picture, title, year } = metadata.common || {},
1191+
{ album, artist, picture, title, year, track } = metadata.common || {},
11801192
{ bitrate, bitsPerSample, codec, codecProfile, container,
11811193
duration, lossless, numberOfChannels, sampleRate } = metadata.format || {};
11821194

@@ -1188,6 +1200,10 @@ function addMetadata( metadata, target ) {
11881200
trackData.title = title || trackData.title;
11891201
trackData.album = album ? album + ( year ? ' (' + year + ')' : '' ) : trackData.album;
11901202
trackData.codec = codec || container ? ( codec || container ) + ' (' + numberOfChannels + 'ch)' : trackData.codec;
1203+
trackData.trackNumber = track.no || trackData.trackNumber;
1204+
trackData.fullTrackName = trackData._title && trackData.title.length > 0 ?
1205+
`${trackData.trackNumber ? (trackData.trackNumber + ': ') : ''} ${trackData.title} ${trackData.title} - ${trackData.artist}` :
1206+
extractFileNameFromPath(trackData.file);
11911207

11921208
const khz = sampleRate ? Math.round( sampleRate / 1000 ) + 'kHz' : '';
11931209

src/styles.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ kbd.wide {
11781178
position: relative;
11791179
}
11801180
#playlist li::before {
1181-
content: attr(data-title);
1181+
content: attr(data-full-track-name);
11821182
display: inline-block;
11831183
overflow: hidden;
11841184
vertical-align: text-bottom;
@@ -1193,7 +1193,7 @@ kbd.wide {
11931193
padding-left: .25em;
11941194
}
11951195
#playlist li.current::before {
1196-
content: "\25b8"" " attr(data-title);
1196+
content: "\25b8"" " attr(data-full-track-name);
11971197
}
11981198

11991199
#console .error {

0 commit comments

Comments
 (0)