Merge pull request #316 from renatolond/misc/disable_google
Disable google service
This commit is contained in:
commit
d2ca7b5195
2 changed files with 2 additions and 72 deletions
|
@ -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' };
|
||||
}
|
||||
|
||||
|
|
|
@ -1,29 +1,6 @@
|
|||
import { parse } from 'url';
|
||||
|
||||
export default function match(url) {
|
||||
const parsed = parse(url.replace(/\+/g, '%20'));
|
||||
if (!parsed.host.match(/play\.google\.com$/)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const path = parsed.path;
|
||||
const hash = parsed.hash;
|
||||
|
||||
if (hash) {
|
||||
const parts = hash.split('/');
|
||||
const id = parts[2];
|
||||
const artist = parts[3];
|
||||
|
||||
if (id.length > 0) {
|
||||
return true;
|
||||
} else if (artist.length > 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (path) {
|
||||
const matches = path.match(/\/music\/m\/([\w]+)/);
|
||||
if (matches[1]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Disable google since it doesn't respond anymore
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue