Stop inlining Youtube videos for now

This commit is contained in:
Jonathan Cremin 2015-01-13 01:06:37 +00:00
parent c6681ae436
commit 1965a8787d
10 changed files with 66 additions and 58 deletions

View file

@ -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"};
});
};