mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-04 02:05:06 +02:00
Music albums grouping and page
This commit is contained in:
parent
9de7be1cb4
commit
d6da161b13
11 changed files with 210 additions and 18 deletions
|
@ -1,4 +1,5 @@
|
|||
const { sort, createNewSortInstance } = require('../libs/fastSort')
|
||||
const Logger = require('../Logger')
|
||||
const { getTitlePrefixAtEnd, isNullOrNaN, getTitleIgnorePrefix } = require('../utils/index')
|
||||
const naturalSort = createNewSortInstance({
|
||||
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare
|
||||
|
@ -701,5 +702,34 @@ module.exports = {
|
|||
|
||||
return shelf
|
||||
})
|
||||
},
|
||||
|
||||
groupMusicLibraryItemsIntoAlbums(libraryItems) {
|
||||
const albums = {}
|
||||
|
||||
libraryItems.forEach((li) => {
|
||||
const albumTitle = li.media.metadata.album
|
||||
const albumArtist = li.media.metadata.albumArtist
|
||||
|
||||
if (albumTitle && !albums[albumTitle]) {
|
||||
albums[albumTitle] = {
|
||||
title: albumTitle,
|
||||
artist: albumArtist,
|
||||
libraryItemId: li.media.coverPath ? li.id : null,
|
||||
numTracks: 1
|
||||
}
|
||||
} else if (albumTitle && albums[albumTitle].artist === albumArtist) {
|
||||
if (!albums[albumTitle].libraryItemId && li.media.coverPath) albums[albumTitle].libraryItemId = li.id
|
||||
albums[albumTitle].numTracks++
|
||||
} else {
|
||||
if (albumTitle) {
|
||||
Logger.warn(`Music track "${li.media.metadata.title}" with album "${albumTitle}" has a different album artist then another track in the same album. This track album artist is "${albumArtist}" but the album artist is already set to "${albums[albumTitle].artist}"`)
|
||||
}
|
||||
if (!albums['_none_']) albums['_none_'] = { title: 'No Album', artist: 'Various Artists', libraryItemId: null, numTracks: 0 }
|
||||
albums['_none_'].numTracks++
|
||||
}
|
||||
})
|
||||
|
||||
return Object.values(albums)
|
||||
}
|
||||
}
|
|
@ -361,12 +361,12 @@ function getDataFromMediaDir(libraryMediaType, folderPath, relPath, serverSettin
|
|||
// Called from Scanner.js
|
||||
async function getLibraryItemFileData(libraryMediaType, folder, libraryItemPath, isSingleMediaItem, serverSettings = {}) {
|
||||
libraryItemPath = libraryItemPath.replace(/\\/g, '/')
|
||||
var folderFullPath = folder.fullPath.replace(/\\/g, '/')
|
||||
const folderFullPath = folder.fullPath.replace(/\\/g, '/')
|
||||
|
||||
var libraryItemDir = libraryItemPath.replace(folderFullPath, '').slice(1)
|
||||
var libraryItemData = {}
|
||||
const libraryItemDir = libraryItemPath.replace(folderFullPath, '').slice(1)
|
||||
let libraryItemData = {}
|
||||
|
||||
var fileItems = []
|
||||
let fileItems = []
|
||||
|
||||
if (isSingleMediaItem) { // Single media item in root of folder
|
||||
fileItems = [
|
||||
|
@ -388,8 +388,8 @@ async function getLibraryItemFileData(libraryMediaType, folder, libraryItemPath,
|
|||
libraryItemData = getDataFromMediaDir(libraryMediaType, folderFullPath, libraryItemDir, serverSettings, fileNames)
|
||||
}
|
||||
|
||||
var libraryItemDirStats = await getFileTimestampsWithIno(libraryItemData.path)
|
||||
var libraryItem = {
|
||||
const libraryItemDirStats = await getFileTimestampsWithIno(libraryItemData.path)
|
||||
const libraryItem = {
|
||||
ino: libraryItemDirStats.ino,
|
||||
mtimeMs: libraryItemDirStats.mtimeMs || 0,
|
||||
ctimeMs: libraryItemDirStats.ctimeMs || 0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue