Disable google service

This commit is contained in:
Renato "Lond" Cerqueira 2021-01-17 16:41:47 +01:00
parent d1a87622fb
commit 6d9d32d347
2 changed files with 2 additions and 72 deletions

View file

@ -101,54 +101,7 @@ function looseMatch(needle, haystack, type) {
}
export async function search(data, original = {}, cleaned = false) {
await ready;
let query;
let album;
const type = data.type;
if (type === 'album') {
query = `${data.artist.name} ${data.name}`;
album = data.name;
} else if (type === 'track') {
query = `${data.artist.name} ${data.albumName} ${data.name}`;
album = data.albumName;
}
const result = await pm.searchAsync(query, 5);
if (!result.entries) {
if (cleaned) {
return { service: 'google' };
}
const matches = album.match(/^[^([]+/);
if (matches && matches[0]) {
const cleanedData = JSON.parse(JSON.stringify(data));
if (type === 'album') {
cleanedData.name = data.name.match(/^[^([]+/)[0].trim();
} else if (type === 'track') {
cleanedData.albumName = data.albumName.match(/^[^([]+/)[0].trim();
cleanedData.name = data.name.match(/^[^([]+/)[0].trim();
}
return await search(cleanedData, data, true);
}
return { service: 'google' };
}
const name = original.name || data.name;
let match = exactMatch(name, result.entries, data.type);
if (!match) {
match = looseMatch(name, result.entries, data.type);
}
if (!match) {
return { service: 'google' };
}
if (type === 'album') {
return await lookupId(match.album.albumId, type);
} else if (type === 'track') {
return await lookupId(match.track.storeId, type);
}
// Disable google since it doesn't respond anymore
return { service: 'google' };
}