[SOLVED]Problems displaying search results

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

I have found one issue myself:

"prev": "youtube"

must be

"prev": { "uri": "youtube" }

Well but the issue is not solved by this change.

I have tried to return all mentioned results here (volumio.github.io/docs/Plugin_S … ex.js.html) but without success.

I think the search is triggered correctly and the result I return seem to be okay too.

Any further hints? :frowning:

Thanks.

Sorry, but I don’t get what your problem is… Let me know

Hi Stefan!

I’ve actually been developing a Youtube plugin for Volumio myself in the last couple days, you can find it here if you want to give it a look https://github.com/crisp00/PiYoutube.

I haven’t implemented search but you could add that feature to mine instead if you like!
Otherwise, it would help if you could provide more code, any chance we can get your whole plugin? Maybe a github repo?

Best of luck,
Cris

Dear Stefan and Cris,
I think it will be a great opportunity to develop an highly integrated plugin! Cris is very skilled and I’m sure the result will be outstanding! I am willing to help for anything needed

Hello together,

I am sorry. I think the title of this thread is quite misleading. It should me “Search results are not displayed”.

But let me try to explain it with more details:
When I am using the search I query YouTube for videos, playlists,… The results should be displayed but they aren’t. As described in my first post I can see in the log that my search function is called and that it returns a valid navigation object. But it seems the returned value is ignored by volumio.

I know now that my navigation object is 100% correct because the same code works when browsing though playlists.

Maybe I have misunderstood the usage of the search function?

I am running volumio 2.129.

You are using a different approach than me to stream the videos. :slight_smile:
It looks much easier than mine.

You can take a look on my code too if you like (ignore the read me :laughing:):
https://github.com/sla89/volumio-plugins/tree/youtube/plugins/music_service/youtube

Currently I am using youtube-node for authentication and to query for videos, playlists and so on.

When I started developing I thought the best and easiest way to stream the video is to use youtube-dl (I am installing it when the plugin is installed: https://github.com/sla89/volumio-plugins/blob/youtube/plugins/music_service/youtube/install.sh). But it seems your approach is much easier.

As you can see in my code work is still ongoing and I didnt refactored my code yet - so please forgive the chaos.

When you browse youtube (click on Browse in the web interface and select YouTube) I return a static list that supports list and grid view: https://github.com/sla89/volumio-plugins/blob/youtube/plugins/music_service/youtube/index.js#L96-L156

And you can browse a playlist (in the static list the second item is a playlist). These data are fetched and generated (no static code here).

The next steps are:

  • playback a video and playlist
  • fix the search
  • paging
  • authentication
  • Maybe allow to configure some default key words that can be used to query for videos and playlists when not logged in.
  • adding videos and playlists to your favorites (I could not figure out why adding a video to a playlist or marking it as a favorite does not work yet)

I am not sure about how to handle the paging efficiently. The YouTube API returns max. 50 items in one response. If there are more than 50 items the API response contains a page token. It can be used to query for further items. I think it is not a good idea to collect the whole search result because that can be more than 100.000 items… There must be a limit I think. But I will take care about that problem later.

First I want to fixed the issue with the search result and playback videos and playlists. When this is done I think everybody can use the plugin.

FYI: the API key used in my repo is not the final yet. It is a simple developer key.

As you can see i am already working on an highly integrated plugin. :slight_smile:
Any help or cooperation with Cris or anybody else is welcome. :slight_smile:

Stefan

Hello,

I really liked the solution of Cris and adapted my code. I am now using ytdl-node in my plugin too. I am so happy that you have showed me this plugin Cris - thank you very much. :slight_smile:

Now I can

  • playback videos too
  • queue videos from a playlist but not the whole playlist (not implemented yet)
  • show all videos of a playlist (implemented paging)
  • show a list of trend videos when not logged in

Next I will implement:

  • queuing whole playlist
  • authentication + showing user suggested videos instead of trend
  • adding videos and playlists to your favorites (I could not figure out why adding a video to a playlist or marking it as a favorite does not work yet)
  • fix the search (maybe anybody can give me a hint why this does not work -> it is still the topic of this thread)

Stefan

This is getting really interesting!!! Well done!
Could you share us your code so maybe me and Cris can give an helping hand?

Thank you. :slight_smile: Yes, of course. My code is open source!
I have forked the volumio-plugins repository and created a new branch called youtube: github.com/sla89/volumio-plugins/tree/youtube

But as I have said I had no time to refactor the code yet. I have to extract some code into methods and so on. :slight_smile:

Maybe we get back to the original topic. Tis would help to improve the plugin either. :slight_smile:

When you enter a search string the result is not displayed. Do you have any idea?
My method returns the object mentioned in my first post.

Thanks,
Stefan

Hey Stefan,

I’m glad to know my code helped you!
I see you have done some serious stuff on the UI so I have a bit of a proposal for you.
What do you think we cooperate on the plugin, I’ll make the YouTube logic and you can keep working on the UI making it better?

If you like I can invite you to my repository, and we can work together, you work on the UI (you can start from your existing code) and I’ll make the playlist adding part, which I’m working on right now, I’ve got it almost done!

Let me know!
Cris

Oh and about your problem,
I haven’t had the time to try your plugin, here are some questions that could help though:

  • Are you sure that your method is being called by volumio when a search query is sent?
  • Are you sure your object is getting through to volumio?
  • Have you followed the path your object takes in the volumio environment after you return it?
  • Have you looked at how other plugins do it and how yours differs?

I’ll give it a look as soon as I get the chance tho.
Best of luck!

Cris

Hello together,

if somebody else runs into this problem, I have found the solution.

The object I was returning had the wrong structure.

I have returned:

{ "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": { "uri": "youtube" } } }
See: jsoneditoronline.org/?id=28a … 172fd876e2

It must be:

{ "title": "Youtube Videos", "icon": "fa fa-youtube", "availableListViews": [ "list", "grid" ], "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" } ] } ], }
See: jsoneditoronline.org/?id=5d0 … 398a4e1d97

So this can be marked as done.

Offtopc: I write you a message Cris.

Thanks for your help :slight_smile:

Stefan