[PLUGIN] YouTube for Volumio

Hi,

Maybe I missed it, but I’m wondering if this plugin has an “AutoPlay” feature that plays the “Up Next” video if there are no further tracks in the playlist (like YouTube in the browser)?

Thanks for the good work :slight_smile:

Hello,

This may come a bit late but I have made some changes to the YouTube plugin to allow specifying your own API credentials in the plugin settings.

The API key used by the official YouTube plugin is broken as of this writing, so you cannot access YouTube without first granting Volumio to your YouTube account. However, even after granting such access, sometimes the plugin fails with Quota Exceeded errors. This is because the quotas associated with the API credentials used by the official YouTube plugin have exceeded due to too many requests (the credentials are shared by all users of the plugin). It is therefore ideal to instruct the plugin to use your own API credentials, which would mean all quotas are reserved only for you (whether or not you grant access to your YouTube account). The attached plugin caters for this.

Before using the plugin, you need to create the credentials in your Google Developer Console as follows:

  1. Go to your Google Developer Console

  2. Create a Project (click ‘Select a Project’, then ‘New Project’).

  3. On the left menu, choose Library, then enter “YouTube Data API v3” in the search box. In the search results, click on the API and enable it.

  4. Then choose Credentials on the left menu. This is the place where you will create your API credentials.

  5. Click ‘Create Credentials’, choose ‘API Key’. An API Key will be created and you can optionally choose to restrict it to the YouTube Data API v3.

  6. Then click ‘Create Credentials’ again and choose ‘OAuth client ID’.

  7. You will be asked to configure the consent screen, so let’s do that. On the configuration page:

    • Set Application name (e.g. volumio-youtube-your-username). This name will be shown during the process where you grant Volumio access to your YouTube account
  • Click ‘Add scope’, then check the box for ‘YouTube Data API v3 …/auth/youtube.readonly’

  • Click Save.

  1. You will be brought back to the Create OAuth Client ID page. Choose ‘Other’ for Application type and provide a name (e.g. volumio-youtube-client). Click Create.
  2. Done! You have just created the API credentials needed for YouTube access. On the Credentials page, you will see the API key and Client ID. The Client Secret can be obtained by clicking the Edit icon corresponding to the Client ID.

To install the plugin:

  1. If you have the official YouTube plugin installed, you should uninstall it first, followed by a Volumio restart. To restart Volumio, you can enter the following in the console:
volumio@volumio:~$ volumio vrestart
  1. Download the attached zip file and place it in your Volumio home directory (/home/volumio)
  2. In Volumio console, enter the following:
volumio@volumio:~$ cd /home/volumio
volumio@volumio:~$ mkdir volumio_youtube_install
volumio@volumio:~$ cd volumio_youtube_install
volumio@volumio:~/volumio_youtube_install$ miniunzip ../<name of zip file downloaded>
volumio@volumio:~/volumio_youtube_install$ volumio plugin install
  1. You can delete the volumio_youtube_install directory after installation is complete
volumio@volumio:~/volumio_youtube_install$ cd ..
volumio@volumio:~$ rm -rf volumio_youtube_install

Using the API credentials with our plugin:

  1. Open Volumio web interface in your browser, go to Plugins->Installed Plugins and enable the YouTube plugin. Then click Settings.

  2. The default is to use the credentials provided by the official YouTube plugin. To change that:

    • Under API Settings, turn off the ‘Default’ switch.
  • In the corresponding fields that appear, enter the API key, Client ID and Client secret you created in your Google Developer Console.

  • Click Save.

  1. A dialog will appear reminding you to use new Code for granting Volumio access to your YouTube account.
  2. Note the change in the Code shown under Account Access. You may have to wait up to 10 seconds to see the change.
  3. Use the new Code for granting access to your YouTube account. The process is the same as with the official YouTube plugin. Note that you might get a “This app isn’t verified” warning in the process. This is normal since you haven’t gone through the Google verification step after creating the OAuth Client ID, but it is nonetheless safe to proceed by clicking ‘Advanced’ and 'Go to '.
  4. If you change the API settings again, you will need to grant / regrant access with new Code.

Please feel free to test it and point out any issues or suggestions. If this works well then maybe this can be merged into the official plugin… :unamused:
youtube-api-20191110.zip (5.7 MB)

Great! Thanks patrickkfkan!
I followed your instructions and the plugin works perfectly!

Just an issue: when clicking on a subscripted channel an error appears that, looking in the log, is an HTML page showing “413. That’s an error. Your client issued a request that was too large.” (I omitted all the html tags)

Is it something that can be solved? Or there is a limit on the request’s length?
Thanks

Hello MrSeamus,

Could you try replacing the index.js file in your YouTube plugin directory with the one in the attached zip and see if it works?

After unzipping the attachment:

> cp index.js /data/plugins/music_service/youtube/
> volumio vrestart

What’s updated:

  • When you click on a channel (in your Subscriptions or search results), the official plugin actually fetches all Channel Sections first and then the playlists in each section. Sometimes that fails with some channels (e.g. https://www.youtube.com/channel/UCXUsPf-G8qGEKCy-Yw30CGw). The updated plugin now fetches the playlists directly off a channel, as opposed to going through each channel section.
  • ‘Back’ navigation has been improved. With the original plugin, clicking Back will always bring you back to the first page. Now, you can go back to the previous page - e.g. search for something -> click on a channel in search results -> click on a playlist in the selected channel -> play a song in the playlist -> Click ‘Back’ arrow to return to channel playlists -> Click ‘Back’ to return to search results. Note that searching will reset the ‘back’ history.

If you still get Error 413, could you please provide the channel ID so I can have a look at it? You can find the channel ID in the YouTube URL of the browser (e.g. youtube.com/channel/UCXUsPf-G8qGEKCy-Yw30CGw)

I’ll repackage the plugin with the updated index.js when I’m not feeling too lazy :neutral_face: . Also, for those who are interested, here’s my git (although I don’t really use it properly, so don’t expect master always == stable :wink: ): https://github.com/patrickkfkan/volumio-plugins

EDIT 15/11/2019: I found a bug in the attached index.js which causes items to load wrongly when you set Results Limit > 50. I have just posted another update (https://forum.volumio.org/youtube-for-volumio-t6608-170.html#p68909) - please use that instead.
youtube-index.js-20191113.zip (8.14 KB)

Hi patrickkfkan,

Do i guess right i will have to edit auth.json and replace the credentials with the values just created ?
I think so - will try

Best Regards
Josef

Hi Josef,

No, you do not. Once you have created the credentials, you just have to enter them in the Plugin settings in the web browser.

youtube-plugin-api.jpg

Hi,

For some reason i do not get this shown - it still looks like before.
I had the stock plugin installed before… uninstalled it, rebooted and installed your version.

I will do an install from scratch.

Best Regards
Josef

oh silly me - now i checked it
the default button has to be switched off to get the required input fields

Registered to say thanks for your work on the plugin. Got everything set up and I’m playing a livestream right now.

Another update:

  • Added caching: this should further reduce your quota usage because previously, going back and forth a playlist will fire a Youtube request which eats up your quota. In the plugin settings, you can change TTL (expiry time) of your cache as well as the number of cache entries (to limit the size and hence memory consumed by the cache).
  • Added pagination: “Next Page” will appear when a list does not contain all the results. This applies to all types of resources - playlists, videos, subscriptions…as well as search results. When you are on the next page, clicking the ‘Back’ navigation button will bring you back to the previous page.

Because of the pagination feature, the Results Limit setting has been changed to “Items Per Page”, since it’s no longer restricted to Search Results. Please also note that with the original plugin, all of “My Playlists” are fetched. With the new plugin, the playlists are now shown within the “Items Per Page” limit, and you can navigate to the next page if there are more to be shown.

Testers welcome. I am unable to test it thoroughly because I have exhausted my own quota (for today :laughing: )

EDIT 16/11/2019: Adding playlist is broken in this version. Please use the one in my next post.
youtube-20191115.zip (5.74 MB)

It seems I break things while updating the plugin with new things :confused: My update yesterday broke adding playlist (queuing / saving / playing it).

Here’s the fixed version, with a couple of minor UI changes like higher quality album art shown on playback.

If anyone can help with the existing translations I could incorporate them as well, otherwise I’ll leave this for the time being (but please report any bugs you find).
youtube-20191116.zip (5.74 MB)

Hi patrickkfkan,

Thank you very much - will try tomorrow.

Best Regards
Josef

Hi Patrickkfkan,

I was running latest official volumio and youtube plugin versions.
I am like most others that ran prior versions of the youtube plugin without issue until sometime in May when only partial length of selection played.
I have a youtube account but never log into it except to initially install the plugin and rare occasion to resolve re-authorize issues with google. twice volumio sw upgrades required that afterwards.

Tonight in hope of resolving the 2/3 song playback issue I downloaded your latest 20191116.zip.
I followed you original installation instructions from page 17 using the new zip.

All of your instructions were excellent including the creation of my new API key and cert.

one thing of note was at the 100% done piece of the plugin install it asks and waits for reply to ?
do you want to enable plugin now ?
I answered no and waited 5 minutes then ^C to break and complete.

I saw no indication that the plugin did not fully install so I went ahead and enabled the plugin with
my new account credentials.

I added the key and authorized on my google account security. All that worked perfect.
I changed my items per page to 25 and changed no other settings.

using the volumio gui browse, “youtube” now shows me the youtube categories but unfortunately nothing is working
when I type strings into the search box. its acts like it searched and found no matching items.
Prior to upgrade anything ever typed into search produced enormous amount of hits so something is either wrong or
your plugin is designed to work differently with searching… Maybe more specific to user/youtube tailored experience?

If I click on any category it searches and correctly errors out with no results which makes perfect sense since
I have never participated in any of those activities.

Even though the outcome did not work out for me I appreciate all the effort you made to improve the interface and
your taking the time to document and share it with everyone.

Thanks

Hello,

  1. Did you uninstall the original plugin first?
  2. Did you install my plugin in the console, inside the youtube directory of the unzipped file you downloaded (as per my instructions)?
  3. Did you restart Volumio so that new plugin takes effect? The old plugin leaves a lot of traces and functions that keep executing until you restart Volumio.
  4. What version of Volumio are you using? I’m using 2.657 and it doesn’t ask me anything or confirmation to enable the plugin - it just installs straight away and you would enable the plugin in the web browser.
  5. Any log you could provide when you try to search for something? If the Youtube API search fails it should throw some errors in the log. You can view log in the console as follows:
sudo journalctl -f

Also, I have not tried to solve the 2/3 playback issue. Seems it has something to do with the ytdl-core node module which is strictly speaking not part of the YouTube plugin. If I have the time I’ll see what I can do about it, but I can’t guarantee anything since I’m not really knowledgeable about streaming stuff…

Best regards,
Patrick

Hi Patrick,

I just have tested your new version 20191116 and it is working perfect for me.
Thank you for your work :smiley:

@lously: Since Volumio v2.668 you can choose toactivate a plugin right after installation from the plugin store. It seems this isn’t fully implemented or documented how this is working if installing from command line (ssh).

Best Regards
Josef

Patrick and Josef - thanks for your replies.
I am running volumio v2.668

Patrick’s suggestion and instructions on how to review the log led me to finding root cause of problem.
Searches from my id were being rejected because the api was not enabled. My bad…

I went back into my project, enabled the api, got new credentials and updated the plugin with new key.
Youtube searches are back to normal with lots and lots of hits THANK YOU !!!

In the past I also experienced temporary issues with authentication or quota errors using youtube plugin.
I hope Patrick’s code will eventually be added to the “official release” base.

Just throwing this question out there…Does anyone know what exactly the per account quota limit is ?

I still have the 2/3 playback issue sometimes, but I am confidant that someday one of the gang of amazingly smart and
talented contributors to this project will identify or develop a resolution for that.

Have a great day everyone…
v/r
Lou

In your Google developer console, type ‘quota’ in the search box, then select ‘All Quotas’. The daily quota is 10,000.

wow 10,000 daily

I guess I am in no danger of abusing it. I normally only do about 5 searches in a day

Impressive that you were able to hit the limit

Thanks for the reply

Lou

Hi, for some reason when i go to the youtube plugin settings i just get a blank screen. I tried restarting, reïnstalling the plugin, reflashing volumio and reïnstalling the plugin… A bit strange because it all used to work fine. Can anyone help or point me in the right direction ? Thanks

Hi Griff,

Are you using the plugin I posted? If so, could you by any chance be using a language other than English?

Patrick