Switch to async/await
This commit is contained in:
parent
87459b2acc
commit
18021e0ef8
10 changed files with 53 additions and 8837 deletions
|
@ -15,16 +15,16 @@ if (!(process.env.GOOGLE_EMAIL && process.env.GOOGLE_PASSWORD) && !(process.env.
|
|||
const creds = {
|
||||
androidId: process.env.GOOGLE_ANDROID_ID,
|
||||
masterToken: process.env.GOOGLE_MASTER_TOKEN,
|
||||
}
|
||||
};
|
||||
|
||||
let ready = pm.initAsync(creds).catch(function(err) {
|
||||
debug(err);
|
||||
});
|
||||
|
||||
export function* lookupId(id, type) {
|
||||
yield ready;
|
||||
export async function lookupId(id, type) {
|
||||
await ready;
|
||||
if (type === 'album') {
|
||||
const album = yield pm.getAlbumAsync(id, false);
|
||||
const album = await pm.getAlbumAsync(id, false);
|
||||
return {
|
||||
service: 'google',
|
||||
type: 'album',
|
||||
|
@ -41,7 +41,7 @@ export function* lookupId(id, type) {
|
|||
},
|
||||
};
|
||||
} else if (type === 'track') {
|
||||
const track = yield pm.getAllAccessTrackAsync(id);
|
||||
const track = await pm.getAllAccessTrackAsync(id);
|
||||
return {
|
||||
service: 'google',
|
||||
type: 'track',
|
||||
|
@ -92,8 +92,8 @@ function looseMatch(needle, haystack, type) {
|
|||
});
|
||||
}
|
||||
|
||||
export function* search(data, original = {}, cleaned = false) {
|
||||
yield ready;
|
||||
export async function search(data, original = {}, cleaned = false) {
|
||||
await ready;
|
||||
let query;
|
||||
let album;
|
||||
const type = data.type;
|
||||
|
@ -106,7 +106,7 @@ export function* search(data, original = {}, cleaned = false) {
|
|||
album = data.albumName;
|
||||
}
|
||||
|
||||
const result = yield pm.searchAsync(query, 5);
|
||||
const result = await pm.searchAsync(query, 5);
|
||||
|
||||
if (!result.entries) {
|
||||
if (cleaned) {
|
||||
|
@ -121,7 +121,7 @@ export function* search(data, original = {}, cleaned = false) {
|
|||
cleanedData.albumName = data.albumName.match(/^[^([]+/)[0].trim();
|
||||
cleanedData.name = data.name.match(/^[^([]+/)[0].trim();
|
||||
}
|
||||
return yield search(cleanedData, data, true);
|
||||
return await search(cleanedData, data, true);
|
||||
}
|
||||
return { service: 'google' };
|
||||
}
|
||||
|
@ -137,15 +137,15 @@ export function* search(data, original = {}, cleaned = false) {
|
|||
return { service: 'google' };
|
||||
}
|
||||
if (type === 'album') {
|
||||
return yield lookupId(match.album.albumId, type);
|
||||
return await lookupId(match.album.albumId, type);
|
||||
} else if (type === 'track') {
|
||||
return yield lookupId(match.track.storeId, type);
|
||||
return await lookupId(match.track.storeId, type);
|
||||
}
|
||||
return { service: 'google' };
|
||||
}
|
||||
|
||||
export function* parseUrl(url) {
|
||||
yield ready;
|
||||
export async function parseUrl(url) {
|
||||
await ready;
|
||||
const parsed = parse(url.replace(/\+/g, '%20'));
|
||||
const path = parsed.path;
|
||||
const hash = parsed.hash;
|
||||
|
@ -163,11 +163,11 @@ export function* parseUrl(url) {
|
|||
if (id.length > 0) {
|
||||
return { id, type };
|
||||
}
|
||||
return yield search({ type, name: album, artist: { name: artist } });
|
||||
return await search({ type, name: album, artist: { name: artist } });
|
||||
} else if (path) {
|
||||
const matches = path.match(/\/music\/m\/([\w]+)/);
|
||||
const type = matches[1][0] === 'T' ? 'track' : 'album';
|
||||
return yield lookupId(matches[1], type);
|
||||
return await lookupId(matches[1], type);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue