Remove support for Amazon because they are banned me for not making money off this.
This commit is contained in:
parent
c32b756aba
commit
fc33d1ea92
12 changed files with 5 additions and 197 deletions
|
@ -1,143 +0,0 @@
|
|||
import { parse } from 'url';
|
||||
import { inspect } from 'util';
|
||||
import amazon from 'amazon-product-api';
|
||||
import debuglog from 'debug';
|
||||
import urlMatch from './url';
|
||||
|
||||
const debug = debuglog('combine.fm:youtube');
|
||||
|
||||
|
||||
const client = amazon.createClient({
|
||||
awsId: process.env.AWS_ACCESS_KEY_ID,
|
||||
awsSecret: process.env.AWS_SECRET_ACCESS_KEY,
|
||||
awsTag: process.env.AWS_TAG,
|
||||
});
|
||||
|
||||
export async function lookupId(id, type) {
|
||||
try {
|
||||
const results = await client.itemLookup({
|
||||
itemId: id,
|
||||
responseGroup: 'ItemAttributes,Images,ItemIds',
|
||||
});
|
||||
|
||||
const result = results[0];
|
||||
|
||||
if (!result || result.Error) {
|
||||
return { service: 'amazon' };
|
||||
}
|
||||
|
||||
if (type === 'album') {
|
||||
return {
|
||||
service: 'amazon',
|
||||
type: 'album',
|
||||
id: result.ASIN[0],
|
||||
name: result.ItemAttributes[0].Title[0],
|
||||
streamUrl: result.DetailPageURL[0],
|
||||
purchaseUrl: result.DetailPageURL[0],
|
||||
artwork: {
|
||||
small: result.SmallImage[0].URL[0],
|
||||
large: result.LargeImage[0].URL[0],
|
||||
},
|
||||
artist: {
|
||||
name: result.ItemAttributes[0].Creator[0]._,
|
||||
},
|
||||
};
|
||||
} else if (type === 'track') {
|
||||
return {
|
||||
service: 'amazon',
|
||||
type: 'track',
|
||||
id: result.ASIN[0],
|
||||
name: result.ItemAttributes[0].Title[0],
|
||||
streamUrl: result.DetailPageURL[0],
|
||||
purchaseUrl: result.DetailPageURL[0],
|
||||
artwork: {
|
||||
small: result.SmallImage[0].URL[0],
|
||||
large: result.LargeImage[0].URL[0],
|
||||
},
|
||||
album: {
|
||||
name: result.ItemAttributes[0],
|
||||
},
|
||||
artist: {
|
||||
name: result.ItemAttributes[0].Creator[0]._,
|
||||
},
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
debug(inspect(err, { depth: null }));
|
||||
}
|
||||
return { service: 'amazon' };
|
||||
}
|
||||
|
||||
export async function search(data) {
|
||||
try {
|
||||
const type = data.type;
|
||||
const results = await client.itemSearch({
|
||||
author: data.artist.name.replace(':', ' '),
|
||||
title: data.name.replace(':', ' '),
|
||||
searchIndex: 'MP3Downloads',
|
||||
responseGroup: 'ItemAttributes,Tracks,Images,ItemIds',
|
||||
});
|
||||
|
||||
const result = results[0];
|
||||
|
||||
if (!result || result.Error) {
|
||||
return { service: 'amazon' };
|
||||
}
|
||||
|
||||
if (type === 'album') {
|
||||
return {
|
||||
service: 'amazon',
|
||||
type,
|
||||
id: result.ASIN[0],
|
||||
name: result.ItemAttributes[0].Title[0],
|
||||
streamUrl: result.DetailPageURL[0],
|
||||
purchaseUrl: result.DetailPageURL[0],
|
||||
artwork: {
|
||||
small: result.SmallImage[0].URL[0],
|
||||
large: result.LargeImage[0].URL[0],
|
||||
},
|
||||
artist: {
|
||||
name: result.ItemAttributes[0].Creator[0]._,
|
||||
},
|
||||
};
|
||||
} else if (type === 'track') {
|
||||
return {
|
||||
service: 'amazon',
|
||||
type,
|
||||
id: result.ASIN[0],
|
||||
name: result.ItemAttributes[0].Title[0],
|
||||
streamUrl: result.DetailPageURL[0],
|
||||
purchaseUrl: result.DetailPageURL[0],
|
||||
artwork: {
|
||||
small: result.SmallImage[0].URL[0],
|
||||
large: result.LargeImage[0].URL[0],
|
||||
},
|
||||
artist: {
|
||||
name: result.ItemAttributes[0].Creator[0]._,
|
||||
},
|
||||
album: {
|
||||
name: '',
|
||||
},
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
debug(inspect(err, { depth: 4 }));
|
||||
if (err[0].Error[0].Code[0] === 'RequestThrottled') {
|
||||
debug('Rate Limited');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
return { service: 'amazon' };
|
||||
}
|
||||
|
||||
export function parseUrl(url) {
|
||||
const matches = parse(url).path.match(/\/(albums|tracks)[/]+([^?]+)/);
|
||||
|
||||
if (matches && matches[2]) {
|
||||
return { type: matches[1].substring(0, 5), id: matches[2] };
|
||||
}
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
export const id = 'amazon';
|
||||
export const match = urlMatch;
|
|
@ -1,11 +0,0 @@
|
|||
import { parse } from 'url';
|
||||
|
||||
export default function match(url) {
|
||||
const parsed = parse(url);
|
||||
if (!parsed.host.match(/\.amazon\.com$/)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const matches = parse(url).path.match(/\/(albums)[/]+([^/]+)/);
|
||||
return (matches && !!matches[2]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue