Make Youtube matching work a little again
This commit is contained in:
parent
f757152c7d
commit
a919d80f64
8 changed files with 49 additions and 29 deletions
|
@ -2,6 +2,7 @@ import { parse } from 'url';
|
|||
import querystring from 'querystring';
|
||||
import request from 'superagent';
|
||||
import Nodebrainz from 'nodebrainz';
|
||||
import { toSeconds, parse as ptParse } from 'iso8601-duration';
|
||||
import 'superagent-bluebird-promise';
|
||||
import debuglog from 'debug';
|
||||
import urlMatch from './url';
|
||||
|
@ -18,40 +19,54 @@ const credentials = {
|
|||
|
||||
const apiRoot = 'https://www.googleapis.com/youtube/v3';
|
||||
|
||||
const nodebrainz = new Nodebrainz({
|
||||
userAgent: 'combine.fm ( https://combine.fm )',
|
||||
defaultLimit: 10,
|
||||
retryOn: true,
|
||||
retryDelay: 3000,
|
||||
retryCount: 10,
|
||||
});
|
||||
// const nodebrainz = new Nodebrainz({
|
||||
// userAgent: 'combine.fm ( https://combine.fm )',
|
||||
// defaultLimit: 10,
|
||||
// retryOn: true,
|
||||
// retryDelay: 3000,
|
||||
// retryCount: 10,
|
||||
// });
|
||||
|
||||
export function* lookupId(id) {
|
||||
const path = `/videos?part=snippet%2CtopicDetails%2CcontentDetails&id=${id}&key=${credentials.key}`;
|
||||
const path = `/videos?part=snippet%2CcontentDetails&id=${id}&key=${credentials.key}`;
|
||||
try {
|
||||
const result = yield request.get(apiRoot + path).promise();
|
||||
const item = result.body.items[0];
|
||||
const item = result.body.items[0].snippet;
|
||||
|
||||
nodebrainz.luceneSearch('release', { query: item.snippet.title }, (err, response) => {
|
||||
response.releases.forEach((release) => {
|
||||
//console.log(release);
|
||||
});
|
||||
});
|
||||
const duration = toSeconds(ptParse(result.body.items[0].contentDetails.duration));
|
||||
|
||||
const split = item.title.match(/([^-]+)-(.*)/);
|
||||
|
||||
const artist = split[1].trim();
|
||||
const name = split[2].match(/^[^([]+/)[0].trim();
|
||||
|
||||
// nodebrainz.luceneSearch('recording', {artist, query: release }, (err, response) => {
|
||||
// const recording = response.recordings[0];
|
||||
// debug(recording.releases[0].media[0].track[0].title)
|
||||
// artist = recording['artist-credit'].name;
|
||||
// release = recording.media;
|
||||
// });
|
||||
|
||||
const match = {
|
||||
id,
|
||||
type: 'album',
|
||||
service: 'youtube',
|
||||
name: item.snippet.title,
|
||||
type: 'track',
|
||||
album: { name: '' },
|
||||
name,
|
||||
artist: { name: artist },
|
||||
streamUrl: `https://youtu.be/${id}`,
|
||||
purchaseUrl: null,
|
||||
artwork: {
|
||||
small: item.snippet.thumbnails.medium.url,
|
||||
large: item.snippet.thumbnails.high.url,
|
||||
small: item.thumbnails.medium.url,
|
||||
large: item.thumbnails.high.url,
|
||||
},
|
||||
};
|
||||
|
||||
// Hacky check whether this is long enough to be an album
|
||||
if (duration < 1200) {
|
||||
match.type = 'track';
|
||||
match.album = { name: '' };
|
||||
}
|
||||
|
||||
return match;
|
||||
} catch (err) {
|
||||
debug(err);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue