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 querystring from 'querystring';
|
||||||
import request from 'superagent';
|
import request from 'superagent';
|
||||||
import Nodebrainz from 'nodebrainz';
|
import Nodebrainz from 'nodebrainz';
|
||||||
|
import { toSeconds, parse as ptParse } from 'iso8601-duration';
|
||||||
import 'superagent-bluebird-promise';
|
import 'superagent-bluebird-promise';
|
||||||
import debuglog from 'debug';
|
import debuglog from 'debug';
|
||||||
import urlMatch from './url';
|
import urlMatch from './url';
|
||||||
|
@ -18,40 +19,54 @@ const credentials = {
|
||||||
|
|
||||||
const apiRoot = 'https://www.googleapis.com/youtube/v3';
|
const apiRoot = 'https://www.googleapis.com/youtube/v3';
|
||||||
|
|
||||||
const nodebrainz = new Nodebrainz({
|
// const nodebrainz = new Nodebrainz({
|
||||||
userAgent: 'combine.fm ( https://combine.fm )',
|
// userAgent: 'combine.fm ( https://combine.fm )',
|
||||||
defaultLimit: 10,
|
// defaultLimit: 10,
|
||||||
retryOn: true,
|
// retryOn: true,
|
||||||
retryDelay: 3000,
|
// retryDelay: 3000,
|
||||||
retryCount: 10,
|
// retryCount: 10,
|
||||||
});
|
// });
|
||||||
|
|
||||||
export function* lookupId(id) {
|
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 {
|
try {
|
||||||
const result = yield request.get(apiRoot + path).promise();
|
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) => {
|
const duration = toSeconds(ptParse(result.body.items[0].contentDetails.duration));
|
||||||
response.releases.forEach((release) => {
|
|
||||||
//console.log(release);
|
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 = {
|
const match = {
|
||||||
id,
|
id,
|
||||||
|
type: 'album',
|
||||||
service: 'youtube',
|
service: 'youtube',
|
||||||
name: item.snippet.title,
|
name,
|
||||||
type: 'track',
|
artist: { name: artist },
|
||||||
album: { name: '' },
|
|
||||||
streamUrl: `https://youtu.be/${id}`,
|
streamUrl: `https://youtu.be/${id}`,
|
||||||
purchaseUrl: null,
|
purchaseUrl: null,
|
||||||
artwork: {
|
artwork: {
|
||||||
small: item.snippet.thumbnails.medium.url,
|
small: item.thumbnails.medium.url,
|
||||||
large: item.snippet.thumbnails.high.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;
|
return match;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debug(err);
|
debug(err);
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
"ejs": "^2.5.7",
|
"ejs": "^2.5.7",
|
||||||
"extract-text-webpack-plugin": "^2.1.0",
|
"extract-text-webpack-plugin": "^2.1.0",
|
||||||
"file-loader": "^0.11.1",
|
"file-loader": "^0.11.1",
|
||||||
|
"iso8601-duration": "^1.1.1",
|
||||||
"json-loader": "^0.5.4",
|
"json-loader": "^0.5.4",
|
||||||
"kcors": "^1.0.1",
|
"kcors": "^1.0.1",
|
||||||
"koa": "^1.2.1",
|
"koa": "^1.2.1",
|
||||||
|
|
|
@ -38,7 +38,7 @@ export default {
|
||||||
this.submitting = false;
|
this.submitting = false;
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
const item = res.body;
|
const item = res.body;
|
||||||
this.$router.push(`/${item.service}/${item.albumName ? 'track' : 'album'}/${item.externalId}`);
|
this.$router.push(`/${item.service}/${item.type}/${item.externalId}`);
|
||||||
} else {
|
} else {
|
||||||
this.error = res.body.message;
|
this.error = res.body.message;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<div class="container" v-if="item.name">
|
<div class="container" v-if="item.name">
|
||||||
<social v-bind:name="item.name" v-bind:artist="item.artist.name" v-bind:url="`https://combine.fm/${item.service}/${item.type}/${item.externalId}`"></social>
|
<social v-bind:name="item.name" v-bind:artist="item.artist.name" v-bind:url="`https://combine.fm/${item.service}/${item.type}/${item.externalId}`"></social>
|
||||||
<div class="share-heading">
|
<div class="share-heading">
|
||||||
<h3 class="title is-3">Matched {{ item.albumName ? 'tracks' : 'albums' }} for</h3>
|
<h3 class="title is-3">Matched {{ item.type === 'track' ? 'tracks' : 'albums' }} for</h3>
|
||||||
<h2 class="title is-2"><strong>{{ item.name }}</strong> - {{ item.artist.name }}</h2>
|
<h2 class="title is-2"><strong>{{ item.name }}</strong> - {{ item.artist.name }}</h2>
|
||||||
</div>
|
</div>
|
||||||
<ul class="columns is-multiline">
|
<ul class="columns is-multiline">
|
||||||
|
|
|
@ -13,11 +13,11 @@ const queue = kue.createQueue({
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function* () {
|
export default function* () {
|
||||||
|
try {
|
||||||
const url = parse(this.request.body.url);
|
const url = parse(this.request.body.url);
|
||||||
debug(`URL ${url.href}`);
|
debug(`URL ${url.href}`);
|
||||||
this.assert(url.host, 400, { error: { message: 'You need to submit a url.' } });
|
this.assert(url.host, 400, { error: { message: 'You need to submit a url.' } });
|
||||||
|
|
||||||
try {
|
|
||||||
const music = yield lookup(this.request.body.url);
|
const music = yield lookup(this.request.body.url);
|
||||||
|
|
||||||
this.assert(music, 400, { error: { message: 'No supported music found at that link :(' } });
|
this.assert(music, 400, { error: { message: 'No supported music found at that link :(' } });
|
||||||
|
@ -29,7 +29,7 @@ export default function* () {
|
||||||
|
|
||||||
services.forEach((service) => {
|
services.forEach((service) => {
|
||||||
if (service.id !== share.service) {
|
if (service.id !== share.service) {
|
||||||
const job = queue.create('search', { share, service })
|
const job = queue.create('search', { title: `Matching ${share.name} on ${service.id}`, share, service })
|
||||||
.attempts(3)
|
.attempts(3)
|
||||||
.backoff({ type: 'exponential' })
|
.backoff({ type: 'exponential' })
|
||||||
.save((err) => {
|
.save((err) => {
|
||||||
|
@ -58,7 +58,7 @@ export default function* () {
|
||||||
this.body = share;
|
this.body = share;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debug(e);
|
debug(e);
|
||||||
this.throw(500, { error: { message: 'Unexpected error looking up music. Please try again later.' } });
|
this.throw(400, { error: { message: 'Unexpected error looking up music. Please try again later.' } });
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ export default function* (serviceId, type, itemId, format) {
|
||||||
|
|
||||||
services.forEach((service) => {
|
services.forEach((service) => {
|
||||||
if (service.id !== share.service) {
|
if (service.id !== share.service) {
|
||||||
const job = queue.create('search', { share, service })
|
const job = queue.create('search', { title: `Matching ${share.name} on ${service.id}`, share, service })
|
||||||
.attempts(3)
|
.attempts(3)
|
||||||
.backoff({ type: 'exponential' })
|
.backoff({ type: 'exponential' })
|
||||||
.save((err) => {
|
.save((err) => {
|
||||||
|
|
|
@ -64,7 +64,7 @@ function search(data, done) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.process('search', (job, done) => {
|
queue.process('search', 5, (job, done) => {
|
||||||
search(job.data, done);
|
search(job.data, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3071,6 +3071,10 @@ isexe@^2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
|
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
|
||||||
|
|
||||||
|
iso8601-duration@^1.1.1:
|
||||||
|
version "1.1.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/iso8601-duration/-/iso8601-duration-1.1.1.tgz#236379eaf0dd00255377fd73a6d487b34f91f915"
|
||||||
|
|
||||||
isobject@^2.0.0:
|
isobject@^2.0.0:
|
||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89"
|
resolved "https://registry.yarnpkg.com/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue