Fix itunes matching
This commit is contained in:
parent
62b7121301
commit
7b36e8bf0c
6 changed files with 91 additions and 38 deletions
|
@ -21,8 +21,21 @@ services:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
command: yarn run watch-server
|
command: yarn run watch-server
|
||||||
worker:
|
worker:
|
||||||
extends: app
|
|
||||||
build: ./
|
build: ./
|
||||||
|
environment:
|
||||||
|
DEBUG: "combine.fm*"
|
||||||
|
VUE_ENV: server
|
||||||
|
DATABASE_URL:
|
||||||
|
REDIS_URL:
|
||||||
|
GOOGLE_EMAIL:
|
||||||
|
GOOGLE_PASSWORD:
|
||||||
|
XBOX_CLIENT_ID:
|
||||||
|
XBOX_CLIENT_SECRET:
|
||||||
|
YOUTUBE_KEY:
|
||||||
|
SPOTIFY_CLIENT_ID:
|
||||||
|
SPOTIFY_CLIENT_SECRET:
|
||||||
|
volumes:
|
||||||
|
- ./:/app:cached
|
||||||
command: yarn run worker
|
command: yarn run worker
|
||||||
ports:
|
ports:
|
||||||
- "3001:3000"
|
- "3001:3000"
|
||||||
|
|
|
@ -11,14 +11,19 @@ export function* parseUrl(url) {
|
||||||
const matches = parsed.path.match(/[/]?([/]?[a-z]{2}?)?[/]+album[/]+([^/]+)[/]+([^?]+)/);
|
const matches = parsed.path.match(/[/]?([/]?[a-z]{2}?)?[/]+album[/]+([^/]+)[/]+([^?]+)/);
|
||||||
const query = querystring.parse(parsed.query);
|
const query = querystring.parse(parsed.query);
|
||||||
|
|
||||||
|
let itunesId = matches[3];
|
||||||
|
|
||||||
if (matches) {
|
if (matches) {
|
||||||
let type = 'album';
|
let type = 'album';
|
||||||
let id = matches[3].substr(2);
|
if (matches[3].match(/^id/)) {
|
||||||
|
itunesId = matches[3].substr(2);
|
||||||
if (query.i) {
|
if (query.i) {
|
||||||
type = 'track';
|
type = 'track';
|
||||||
id = query.i;
|
itunesId = query.i;
|
||||||
}
|
}
|
||||||
return yield module.exports.lookupId(id, type, matches[1] || 'us');
|
}
|
||||||
|
|
||||||
|
return yield module.exports.lookupId(itunesId, type, matches[1] || 'us');
|
||||||
}
|
}
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
|
@ -30,15 +35,14 @@ export function* lookupId(possibleId, type, countrycode) {
|
||||||
cc = possibleId.substr(0, 2);
|
cc = possibleId.substr(0, 2);
|
||||||
id = possibleId.substr(2);
|
id = possibleId.substr(2);
|
||||||
}
|
}
|
||||||
|
console.log(id)
|
||||||
let path = `/lookup?id=${id}`;
|
let path = `/lookup?id=${id}`;
|
||||||
if (cc) {
|
if (cc) {
|
||||||
path = `/${cc}${path}`;
|
path = `/${cc}${path}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = yield request.get(apiRoot + path);
|
const response = yield request.get(apiRoot + path);
|
||||||
let result = JSON.parse(response.text);
|
let result = JSON.parse(response.text);
|
||||||
|
console.log(result);
|
||||||
if (!result.results || result.resultCount === 0 || !result.results[0].collectionId) {
|
if (!result.results || result.resultCount === 0 || !result.results[0].collectionId) {
|
||||||
const error = new Error('Not Found');
|
const error = new Error('Not Found');
|
||||||
error.status = 404;
|
error.status = 404;
|
||||||
|
|
65
package-lock.json
generated
65
package-lock.json
generated
|
@ -413,6 +413,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.10.0.tgz",
|
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.10.0.tgz",
|
||||||
"integrity": "sha1-muuabF6IY4qtFx4Wf1kAq+JINdA="
|
"integrity": "sha1-muuabF6IY4qtFx4Wf1kAq+JINdA="
|
||||||
},
|
},
|
||||||
|
"bluebird": {
|
||||||
|
"version": "3.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
|
||||||
|
"integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA=="
|
||||||
|
},
|
||||||
"boxen": {
|
"boxen": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/boxen/-/boxen-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/boxen/-/boxen-1.2.1.tgz",
|
||||||
|
@ -572,6 +577,24 @@
|
||||||
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=",
|
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"co-mocha": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/co-mocha/-/co-mocha-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-hlgDSWGXG1PuXiBTWUi+9ewhy0gII2hbNpS4lE0Esyr/eJlYx2xuIVV8ufEYxcBCzYOqiwcEZ7ck1CidWGNWkA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"co": "4.6.0",
|
||||||
|
"is-generator": "1.0.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"co": {
|
||||||
|
"version": "4.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
|
||||||
|
"integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"code-point-at": {
|
"code-point-at": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
|
||||||
|
@ -1919,13 +1942,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"string_decoder": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"bundled": true,
|
|
||||||
"requires": {
|
|
||||||
"safe-buffer": "5.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"string-width": {
|
"string-width": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
|
@ -1935,6 +1951,13 @@
|
||||||
"strip-ansi": "3.0.1"
|
"strip-ansi": "3.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"string_decoder": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"bundled": true,
|
||||||
|
"requires": {
|
||||||
|
"safe-buffer": "5.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"stringstream": {
|
"stringstream": {
|
||||||
"version": "0.0.5",
|
"version": "0.0.5",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
|
@ -2371,6 +2394,12 @@
|
||||||
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
|
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"is-generator": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-generator/-/is-generator-1.0.3.tgz",
|
||||||
|
"integrity": "sha1-wUwhBX7TbjKNuANHlmxpP4hjifM=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"is-glob": {
|
"is-glob": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz",
|
||||||
|
@ -3080,9 +3109,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"parallelshell": {
|
"parallelshell": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/parallelshell/-/parallelshell-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/parallelshell/-/parallelshell-3.0.2.tgz",
|
||||||
"integrity": "sha512-xsSQGhJTFjbSW3WGsnSFTg1G17dcDU+gMH7bWxjAiy/3H579KPFbSp3fhkZ+jx2wcZuoav46nq+QVX0I0xPcyA==",
|
"integrity": "sha512-aW73W8tmYiFZtQi41pweV3WWT6o/EvSxAVQHbumOhN53H47OuWQwrRc11xQ2i44GFvR5AjtzhD92r8Kv9X+7Iw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"parse-glob": {
|
"parse-glob": {
|
||||||
|
@ -3646,14 +3675,6 @@
|
||||||
"duplexer": "0.1.1"
|
"duplexer": "0.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"string_decoder": {
|
|
||||||
"version": "1.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
|
|
||||||
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
|
|
||||||
"requires": {
|
|
||||||
"safe-buffer": "5.1.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"string-width": {
|
"string-width": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
|
||||||
|
@ -3681,6 +3702,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"string_decoder": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
|
||||||
|
"requires": {
|
||||||
|
"safe-buffer": "5.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"strip-ansi": {
|
"strip-ansi": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
"babel-preset-es2015": "^6.0.0",
|
"babel-preset-es2015": "^6.0.0",
|
||||||
"babel-preset-latest-minimal": "^1.1.2",
|
"babel-preset-latest-minimal": "^1.1.2",
|
||||||
"babel-register": "^6.26.0",
|
"babel-register": "^6.26.0",
|
||||||
"bluebird": "^3.4.1",
|
"bluebird": "^3.5.1",
|
||||||
"bulma": "^0.6.0",
|
"bulma": "^0.6.0",
|
||||||
"co": "~4.6.0",
|
"co": "~4.6.0",
|
||||||
"css-loader": "^0.28.1",
|
"css-loader": "^0.28.1",
|
||||||
|
@ -95,14 +95,14 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-plugin-transform-runtime": "^6.15.0",
|
"babel-plugin-transform-runtime": "^6.15.0",
|
||||||
"babel-runtime": "^6.26.0",
|
"babel-runtime": "^6.26.0",
|
||||||
"co-mocha": "^1.2.0",
|
"co-mocha": "^1.2.1",
|
||||||
"eslint": "^4.7.0",
|
"eslint": "^4.7.0",
|
||||||
"eslint-config-airbnb": "^15.1.0",
|
"eslint-config-airbnb": "^15.1.0",
|
||||||
"eslint-plugin-import": "^2.7.0",
|
"eslint-plugin-import": "^2.7.0",
|
||||||
"istanbul": "^0.4.0",
|
"istanbul": "^0.4.0",
|
||||||
"mocha": "^3.5.3",
|
"mocha": "^3.5.3",
|
||||||
"nodemon": "^1.12.1",
|
"nodemon": "^1.12.1",
|
||||||
"parallelshell": "^3.0.1",
|
"parallelshell": "^3.0.2",
|
||||||
"should": "^13.0.1"
|
"should": "^13.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
import { parse } from 'url';
|
import { parse } from 'url';
|
||||||
import kue from 'kue';
|
import kue from 'kue';
|
||||||
|
import debuglog from 'debug';
|
||||||
|
|
||||||
import lookup from '../lib/lookup';
|
import lookup from '../lib/lookup';
|
||||||
import services from '../lib/services';
|
import services from '../lib/services';
|
||||||
import { find, create } from '../lib/share';
|
import { find, create } from '../lib/share';
|
||||||
|
|
||||||
|
const debug = debuglog('combine.fm:search');
|
||||||
|
|
||||||
const queue = kue.createQueue({
|
const queue = kue.createQueue({
|
||||||
redis: process.env.REDIS_URL,
|
redis: process.env.REDIS_URL,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function* () {
|
export default function* () {
|
||||||
const url = parse(this.request.body.url);
|
const url = parse(this.request.body.url);
|
||||||
|
debug(`URL ${url}`);
|
||||||
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.' } });
|
||||||
|
|
||||||
const music = yield lookup(this.request.body.url);
|
const music = yield lookup(this.request.body.url);
|
||||||
|
|
18
yarn.lock
18
yarn.lock
|
@ -993,10 +993,14 @@ bluebird@^2.3.2:
|
||||||
version "2.11.0"
|
version "2.11.0"
|
||||||
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1"
|
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1"
|
||||||
|
|
||||||
bluebird@^3.0.5, bluebird@^3.1.1, bluebird@^3.3.4, bluebird@^3.4.1, bluebird@^3.4.6:
|
bluebird@^3.0.5, bluebird@^3.1.1, bluebird@^3.3.4, bluebird@^3.4.6:
|
||||||
version "3.5.0"
|
version "3.5.0"
|
||||||
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c"
|
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c"
|
||||||
|
|
||||||
|
bluebird@^3.5.1:
|
||||||
|
version "3.5.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9"
|
||||||
|
|
||||||
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
|
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
|
||||||
version "4.11.6"
|
version "4.11.6"
|
||||||
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215"
|
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215"
|
||||||
|
@ -1344,9 +1348,9 @@ co-body@^5.1.0:
|
||||||
raw-body "^2.2.0"
|
raw-body "^2.2.0"
|
||||||
type-is "^1.6.14"
|
type-is "^1.6.14"
|
||||||
|
|
||||||
co-mocha@^1.2.0:
|
co-mocha@^1.2.1:
|
||||||
version "1.2.0"
|
version "1.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/co-mocha/-/co-mocha-1.2.0.tgz#d9be35a2a2d16f4b1b0e83f6973401ca4b6660af"
|
resolved "https://registry.yarnpkg.com/co-mocha/-/co-mocha-1.2.1.tgz#145b997d58acd56616b3de557ff24df3d7cd63ba"
|
||||||
dependencies:
|
dependencies:
|
||||||
co "^4.0.0"
|
co "^4.0.0"
|
||||||
is-generator "^1.0.1"
|
is-generator "^1.0.1"
|
||||||
|
@ -4134,9 +4138,9 @@ pako@~0.2.0:
|
||||||
version "0.2.9"
|
version "0.2.9"
|
||||||
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
|
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
|
||||||
|
|
||||||
parallelshell@^3.0.1:
|
parallelshell@^3.0.2:
|
||||||
version "3.0.1"
|
version "3.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/parallelshell/-/parallelshell-3.0.1.tgz#0587ce1535350543916d8f3d329fbfa4a0355f22"
|
resolved "https://registry.yarnpkg.com/parallelshell/-/parallelshell-3.0.2.tgz#fffc55aaa145bdd44b5381cf7fd5e521fc21aa7b"
|
||||||
|
|
||||||
parse-asn1@^5.0.0:
|
parse-asn1@^5.0.0:
|
||||||
version "5.1.0"
|
version "5.1.0"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue