fix(album-imports): get them to actually work
This commit is contained in:
parent
9b800815a5
commit
3591ed7157
2 changed files with 15 additions and 4 deletions
|
|
@ -1558,10 +1558,12 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
importOptions
|
importOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
const hasMultipleTypes =
|
const isLibraryImport =
|
||||||
result.tracks.length > 0 && (result.albums.length > 0 || result.artists.length > 0);
|
result.albums.length > 0 ||
|
||||||
|
result.artists.length > 0 ||
|
||||||
|
Object.keys(result.playlists).length > 1;
|
||||||
|
|
||||||
if (hasMultipleTypes) {
|
if (isLibraryImport) {
|
||||||
currentTrackElement.textContent = 'Adding to library...';
|
currentTrackElement.textContent = 'Adding to library...';
|
||||||
|
|
||||||
const importResults = await importToLibrary(result, db, (progress) => {
|
const importResults = await importToLibrary(result, db, (progress) => {
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,9 @@ const HEADER_MAPPINGS = {
|
||||||
};
|
};
|
||||||
|
|
||||||
function normalizeHeader(header) {
|
function normalizeHeader(header) {
|
||||||
|
if (!header) return '';
|
||||||
return header
|
return header
|
||||||
|
.replace(/^\uFEFF/, '')
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/[_\s]+/g, ' ');
|
.replace(/[_\s]+/g, ' ');
|
||||||
|
|
@ -255,12 +257,19 @@ export async function parseDynamicCSV(csvText, api, onProgress, options = {}) {
|
||||||
const typeValue = values[mappedHeaders.type]?.toLowerCase().trim();
|
const typeValue = values[mappedHeaders.type]?.toLowerCase().trim();
|
||||||
if (typeValue === 'album' || typeValue === 'favorite album') return 'album';
|
if (typeValue === 'album' || typeValue === 'favorite album') return 'album';
|
||||||
if (typeValue === 'artist' || typeValue === 'favorite artist') return 'artist';
|
if (typeValue === 'artist' || typeValue === 'favorite artist') return 'artist';
|
||||||
if (typeValue === 'track' || typeValue === 'favorite' || typeValue === 'favorite track') return 'track';
|
if (
|
||||||
|
typeValue === 'track' ||
|
||||||
|
typeValue === 'favorite' ||
|
||||||
|
typeValue === 'favorite track' ||
|
||||||
|
typeValue === 'playlist'
|
||||||
|
)
|
||||||
|
return 'track';
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasTrackName = mappedHeaders.track !== undefined && values[mappedHeaders.track];
|
const hasTrackName = mappedHeaders.track !== undefined && values[mappedHeaders.track];
|
||||||
const hasArtistName = mappedHeaders.artist !== undefined && values[mappedHeaders.artist];
|
const hasArtistName = mappedHeaders.artist !== undefined && values[mappedHeaders.artist];
|
||||||
const hasAlbumName = mappedHeaders.album !== undefined && values[mappedHeaders.album];
|
const hasAlbumName = mappedHeaders.album !== undefined && values[mappedHeaders.album];
|
||||||
|
if (hasTrackName && hasAlbumName && values[mappedHeaders.track] === values[mappedHeaders.album]) return 'album';
|
||||||
|
|
||||||
if (hasTrackName && hasArtistName) return 'track';
|
if (hasTrackName && hasArtistName) return 'track';
|
||||||
if (hasAlbumName && hasArtistName && !hasTrackName) return 'album';
|
if (hasAlbumName && hasArtistName && !hasTrackName) return 'album';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue