Hi all,
I am working on a YouTube plugin but I got stuck when I want to display any search results.
My plugin implements all required methods (search, handleBrowseUri, exxploseUri, …). The plugin itself is displayed in Browse and when I enter any string into the search field the plugins method is called too.
Here you can see a detailed log output
Here the object I am returning:
{
"navigation": {
"lists": [
{
"title": "Youtube Videos",
"icon": "fa fa-youtube",
"availableListViews": [
"list"
],
"items": [
{
"service": "youtube",
"type": "song",
"title": "asdfmovie10",
"artist": "",
"album": "",
"icon": "fa fa-youtube",
"uri": "foFKXS6Nyho"
},
{
"service": "youtube",
"type": "song",
"title": "asdfmovie 1-10 (Complete Collection)",
"artist": "",
"album": "",
"icon": "fa fa-youtube",
"uri": "furTlhb-990"
},
{
"service": "youtube",
"type": "song",
"title": "TomSka",
"artist": "",
"album": "",
"icon": "fa fa-youtube"
},
{
"service": "youtube",
"type": "song",
"title": "asdfmovie",
"artist": "",
"album": "",
"icon": "fa fa-youtube"
},
{
"service": "youtube",
"type": "song",
"title": "ASDF Movies 1,2,3,4,5,6,7,8,9,10 (complete collection)",
"artist": "",
"album": "",
"icon": "fa fa-youtube",
"uri": "WTUnwygoFsU"
}
]
}
],
"prev": "youtube"
}
}
Here the code of the search method:
ControllerYoutube.prototype.search = function (query) {
var self = this;
if (!query || !query.value || query.value.length === 0) {
return libQ.resolve([]);
}
var defer = libQ.defer();
self.youtube.search(query.value, 5, function (error, result) {
if (error) {
//self.commandRouter.pushConsoleMessage(new Error('Querying Youtube failed: ' + error + " - " + JSON.stringify(error)));
defer.reject(new Error(error));
}
else {
//see https://gist.github.com/paulomcnally/620b76a9afe81f56e8c9
if (!result.items || result.items.length === 0) {
console.log("no search result");
defer.resolve([]);
} else {
var items = [];
for (var i = 0; i < result.items.length; i++) {
var video = result.items[i];
items.push({
"service": "youtube",
"type": "song",
"title": video.snippet.title,
"artist": "",
"album": "",
"icon": "fa fa-youtube",
"uri": video.id.videoId
})
}
var result = {
"navigation": {
"lists": [{
"title": "Youtube Videos",
"icon": "fa fa-youtube",
"availableListViews": ["list"],
"items": items
}],
"prev": "youtube"
}
};
self.logger.debug(JSON.stringify(result));
defer.resolve(result);
}
}
});
return defer.promise;
};
Any idea why no results were displayed?
Thank you for your help.
Stefan