Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1171,13 +1171,25 @@ function addBatchToPlayQueue( files, autoplay = false ) {
});
}

function extractFileNameFromPath(path) {
if (typeof path !== 'string') return '';

const lastSlashIndex = path.lastIndexOf('/');
const lastDotIndex = path.lastIndexOf('.');

const start = lastSlashIndex >= 0 ? lastSlashIndex + 1 : 0;
const end = lastDotIndex > start ? lastDotIndex : path.length;

return path.substring(start, end);
}

/**
* Add audio metadata to a playlist item or audio element
*/
function addMetadata( metadata, target ) {
const trackData = target.dataset,
sourceData = metadata.dataset,
{ album, artist, picture, title, year } = metadata.common || {},
{ album, artist, picture, title, year, track } = metadata.common || {},
{ bitrate, bitsPerSample, codec, codecProfile, container,
duration, lossless, numberOfChannels, sampleRate } = metadata.format || {};

Expand All @@ -1189,6 +1201,10 @@ function addMetadata( metadata, target ) {
trackData.title = title || trackData.title;
trackData.album = album ? album + ( year ? ' (' + year + ')' : '' ) : trackData.album;
trackData.codec = codec || container ? ( codec || container ) + ' (' + numberOfChannels + 'ch)' : trackData.codec;
trackData.trackNumber = track.no || trackData.trackNumber;
trackData.fullTrackName = trackData._title && trackData.title.length > 0 ?
`${trackData.trackNumber ? (trackData.trackNumber + ': ') : ''} ${trackData.title} ${trackData.title} - ${trackData.artist}` :
extractFileNameFromPath(trackData.file);

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

Expand Down
4 changes: 2 additions & 2 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ kbd.wide {
position: relative;
}
#playlist li::before {
content: attr(data-title);
content: attr(data-full-track-name);
display: inline-block;
overflow: hidden;
vertical-align: text-bottom;
Expand All @@ -1193,7 +1193,7 @@ kbd.wide {
padding-left: .25em;
}
#playlist li.current::before {
content: "\25b8"" " attr(data-title);
content: "\25b8"" " attr(data-full-track-name);
}

#console .error {
Expand Down