diff --git a/lib/services/beats/index.js b/lib/services/beats/index.js index ee9ce21..46496e9 100644 --- a/lib/services/beats/index.js +++ b/lib/services/beats/index.js @@ -113,7 +113,7 @@ module.exports.search = function(data) { return request.get(apiRoot + path).promise().then(function(res) { if (!res.body.data[0]) { var matches = album.match(/^[^\(\[]+/); - if (matches[0] && matches[0] != album) { + if (matches && matches[0] && matches[0] != album) { var cleanedData = JSON.parse(JSON.stringify(data)); if (type == "album") { cleanedData.name = matches[0].trim(); diff --git a/lib/services/deezer/index.js b/lib/services/deezer/index.js index 402a17b..50ab04e 100644 --- a/lib/services/deezer/index.js +++ b/lib/services/deezer/index.js @@ -88,7 +88,7 @@ module.exports.search = function(data) { return request.get(apiRoot + path).promise().then(function(res) { if (!res.body.data[0]) { var matches = album.match(/^[^\(\[]+/); - if (matches[0] && matches[0] != album) { + if (matches && matches[0] && matches[0] != album) { var cleanedData = JSON.parse(JSON.stringify(data)); if (type == "album") { cleanedData.name = matches[0].trim(); diff --git a/lib/services/google/index.js b/lib/services/google/index.js index a453239..cd146d6 100644 --- a/lib/services/google/index.js +++ b/lib/services/google/index.js @@ -113,7 +113,7 @@ module.exports.search = function(data) { if (!result.entries) { var matches = album.match(/^[^\(\[]+/); - if (matches[0] && matches[0] != album) { + if (matches && matches[0] && matches[0] != album) { var cleanedData = JSON.parse(JSON.stringify(data)); if (type == "album") { cleanedData.name = matches[0].trim(); diff --git a/lib/services/itunes/index.js b/lib/services/itunes/index.js index 4aac392..ba37136 100644 --- a/lib/services/itunes/index.js +++ b/lib/services/itunes/index.js @@ -97,7 +97,7 @@ module.exports.search = function(data) { if (!result.results[0]) { var matches = album.match(/^[^\(\[]+/); - if (matches[0] && matches[0] != album) { + if (matches && matches[0] && matches[0] != album) { var cleanedData = JSON.parse(JSON.stringify(data)); if (type == "album") { cleanedData.name = matches[0].trim(); diff --git a/lib/services/youtube/index.js b/lib/services/youtube/index.js index e58939c..f2c1b81 100644 --- a/lib/services/youtube/index.js +++ b/lib/services/youtube/index.js @@ -37,44 +37,60 @@ module.exports.parseUrl = function(url) { module.exports.lookupId = function(id, type) { - var path = "/videos?part=snippet%2Cstatus%2CtopicDetails&id=" + id + "&key=" + credentials.key; + var path = "/videos?part=snippet%2CtopicDetails&id=" + id + "&key=" + credentials.key; return request.get(apiRoot + path).promise().then(function(res) { var item = res.body.items[0]; if (item.topicDetails.topicIds) { var promises = []; + var match = { + id: id, + service: "youtube", + name: item.snippet.title, + type: "track", + album: {name: ""}, + streamUrl: "https://youtu.be/" + id, + purchaseUrl: null, + artwork: { + small: item.snippet.thumbnails.medium.url, + large: item.snippet.thumbnails.high.url, + } + }; item.topicDetails.topicIds.forEach(function(topicId) { promises.push(freebase.get(topicId).then(function(topic) { - return (topic.property["/music/recording/song"] ? topic : (topic.property["/music/recording/tracks"] ? topic : false)); + if (topic.property["/type/object/type"].values.some(function(value) { + return value.text == "Musical Artist"; + })) { + match.artist = {name: topic.property["/type/object/name"].values[0].text}; + } else if (topic.property["/type/object/type"].values.some(function(value) { + return value.text == "Musical Recording"; + })) { + if (!match.name) { + match.album = {name: topic.property["/music/recording/releases"].values[0].text}; + match.name = topic.property["/type/object/name"].values[0].text; + match.type = "track"; + } + } else if (topic.property["/type/object/type"].values.some(function(value) { + return value.text == "Musical Album"; + })) { + match.name = topic.property["/type/object/name"].values[0].text; + match.type = "album"; + } }, function(err) { console.log(err) })); - }) - return Promise.all(promises).then(function(topics) { - for (var key in topics) { - var topic = topics[key]; - if (topic) { - return { - id: id, - service: "youtube", - type: "track", - name: topic.property['/music/recording/song'] ? topic.property['/music/recording/song'].values[0].text : topic.property["/music/recording/tracks"].values[0].text, - artist: {name: topic.property['/music/recording/artist'].values[0].text}, - album: {name: ""}, - streamUrl: "https://youtu.be/" + id, - purchaseUrl: null, - artwork: { - small: item.snippet.thumbnails.medium.url, - large: item.snippet.thumbnails.high.url, - } - } - } - } + }); + return Promise.all(promises).then(function() { + return match; + }, function(err) { + console.log(err) + return {service: "youtube"}; }); } else { return {service: "youtube"}; } - }, function(res) { + }, function(err) { + console.log(err) return {service: "youtube"}; }); }; @@ -112,5 +128,8 @@ module.exports.search = function(data) { } }; } + }, function(err) { + console.log(err) + return {service: "youtube"}; }); }; diff --git a/public/images/logo-128.png b/public/images/logo-128.png new file mode 100644 index 0000000..cce2744 Binary files /dev/null and b/public/images/logo-128.png differ diff --git a/public/images/youtube.png b/public/images/youtube.png new file mode 100644 index 0000000..e56c69f Binary files /dev/null and b/public/images/youtube.png differ diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index e424803..3ef0f51 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -171,6 +171,17 @@ h3 { opacity: 0.7; font-weight: bold; } +.youtube { + position: absolute; + font-weight: bold; + bottom: 65px; + left: 25px; + right: 25px; + padding: 10px; + opacity: 0.85; + background: #fff; + color: #FE4365; +} .loading-wrap { position: absolute; top: 0;left: 0; diff --git a/views/head.jsx b/views/head.jsx index 46d13ca..35b7f08 100644 --- a/views/head.jsx +++ b/views/head.jsx @@ -15,7 +15,7 @@ module.exports = React.createClass({ - Match Audio + {this.props.shares ? "Listen to " + this.props.shares[0].name + " by " + this.props.shares[0].artist.name + " on Match Audio": "Match Audio"} @@ -26,7 +26,7 @@ module.exports = React.createClass({ - + diff --git a/views/share.jsx b/views/share.jsx index 29ef812..3cfb856 100644 --- a/views/share.jsx +++ b/views/share.jsx @@ -44,7 +44,11 @@ var MusicItem = React.createClass({
{this.props.inc == 0 ? "Found matches using this link": ""}
-
+
+
+
0 ? "youtube" : ""}> + {this.props.item.service == "youtube" && this.props.inc > 0 ? this.props.item.name : ""} +
@@ -59,28 +63,6 @@ var MusicItem = React.createClass({ }); -var VideoItem = React.createClass({ - - render: function() { - if (this.props.item.id) { - return ( -
-
-
{this.props.inc == 0 ? "Found matches using this link": ""}
-
- -
-
More Youtube matches -
-
- ); - } else { - return (
); - } - } - -}); - module.exports = React.createClass({ mixins: [ Router.State ], @@ -202,11 +184,7 @@ module.exports = React.createClass({
{this.state.shares.map(function(item, i){ - if (item.service == "youtube") { - return (); - } else { - return (); - } + return (); }.bind(this))}