Hi-fidelity Kodi
Integrate the world’s most popular streaming site into Kodi and see how the Pi fares at high resolutions.
Since the Pi 4 has more graphical horsepower than its predecessors, it’s capable of playing ‘movie’ 4K resolution (4,096x2,160 as opposed to ‘TV’ 4K which is 3,840x2,160) and 10-bit (HEVC) content. It might not yet be capable of driving two 4K displays at 60Hz, but it can certainly drive one. You need to enable that feature by hand, as it will make the SoC run a little warmer than usual. You’ll need to enable SSH access and log in to your Kodi box to do this, remembering that Kodi has only one account, namely root. So the incantation will look like
ssh root@192.168.x.x . Remember you can always find Kodi’s IP address from the status panel.
Once you’re in you’d usually run raspi-config to enable this, but LibreELEC doesn’t include this program. Instead you’ll have to remount the /flash partition in read-write mode and edit config.txt manually:
$ mount -o remount,rw /flash
$ nano config.txt
Now add the line hdmi_enable_4kp60=1 , exit Nano, and restart.
If you don’t get any joy make sure you’re using the HDMI0 port – the one nearest the USB-C port used for power. HDMI1 can only manage 4Kp30 tops. If you have a gaming monitor, or other display that supports high refresh rates, then you should check out the official documentation at www.raspberrypi.com/ documentation/computers/config_txt.html. That will tell you how to set HDMI timings through the /boot/ config.txt file. For 4K HEVC content you’ll need to adjust the graphics/system memory split. Anecdotal evidence suggests the GPU will need at least 340MB here, which again requires manual config.txt intervention.
You might not have any 4K content, and you won’t be streaming that resolution through Netflix running on Kodi (or indeed any platform other than an official tool). But there’s plenty on YouTube if you look around.
Bzzzt. And we have just run into our first problem. We have no way of viewing YouTube content on Kodi. Let’s try and fix that. Navigate to Settings>Add-ons>Install from repository>Kodi Add-on repository> Video Add-ons and then select the YouTube add-on. Don’t worry – we won’t be touching any unofficial add-ons here, this one’s safe to install, so hit Install. You’ll be prompted to run the setup wizard, which enables you to choose your language and region. Skip this step if you don’t care about locale settings, or don’t want to share this information with Google (a stand that will be nullified when we hand over our API key later).
Tap into YouTube content
Now in the video Add-ons section there’s an icon for YouTube, but it doesn’t work. YouTube doesn’t like its content being watched through unofficial applications, and it’s not entirely supportive of it being watched on its own website without being logged into a Google account. The way around this is to register a new project with the Google Developers site, grant this project access to the YouTube Data API and then connect the
YouTube Add-on to this project. Effectively you’re pretending that the add-on is your own project (which the developers of said add-on are fine with, that’s why the instructions tell you to do it).
Open a browser (on your PC) and navigate to https:// console.developers.google.com/apis/library and log in with your Google Account. Click Create Project and give it a meaningful name: “KodiTube” for example. Oh, and don’t try and do this with a corporate Google account, you’d need permission from your organisation to add projects this way and you’ll get an error message if you don’t have it. Once the project is set up, select Enable APIs and Services. Type the first few letters of YouTube and select YouTube Data API v3. Click through and enable the API, then click Create Credentials. Select the YouTube Data API and then Public Data. Click Next and you’ll see your API key. Don’t worry about losing this because it’s always available from this dashboard.
Get configuring
We’re not done with it yet though. Click Done and then click Configure Consent Screen. Select the External user type and choose Create. Give your app a name (use the same as the Project Name if in doubt) and set the support email to your own (don’t worry, none of this will be public or seen by the Kodi add-on developers). Also set the developer email at the bottom (everything in between can be left blank), then click Save And Continue. We don’t need Scopes or Test users just yet, so click through these screens until you’re presented with a summary of your app registration.
Click Credentials on the left, then Create Credentials at the top (again). This time choose Oauth client ID, select Desktop App for the Application Type and come up with a name for your client. Again, the name doesn’t really matter so let’s go with Kodi-auth . You’ll be given a Client ID and Client Secret. Again, don’t worry about losing them, they’ll still be here when you come back.
Instead, worry about how you’re going to enter these lengthy and misreading-prone strings into Kodi. Fortunately, we don’t need to enter these manually (although you can if you want). A less-frustrating approach is to right-click the YouTube add-on and select Settings. In the API section check the box next to Enable API configuration page. Return to the browser and the Google developer page (or navigate back to that tab if you didn’t close it), then open a new tab pointing at http://192.168.x.x:50152/api, replacing 192.168.x.x with your Kodi device’s IP address. Go to the Credentials section in the Google Tab and copy the API key, then paste it in the first box in the KodiTube API page. Repeat for the Client ID and Client Secret (from the OAuth section) and click Save. Then return to the YouTube Addon’s settings page and disable the API page. There, awkward transcription exercise circumvented.
By this point, you should be able to use the Add-on to search videos. We’re not quite done yet though, because we won’t be able to sign in (and see YouTube subscriptions and recommendations) until we’ve added our user as a test user. Go back to the Developer Dashboard and in the Oauth consent screen section scroll down to Test users and add your Google account. In theory you can add up to 99 friends and save them some of the bother of this setup (they’ll still need to set up API keys), but let’s focus on number one first.
Now return to Kodi and open the YouTube Add-on. Click Sign in, and you’ll be told you have to sign in to not one but two apps. Scribble down the first one-time code, then go to google.com/device (on another device) and enter the code. You’ll see a warning about Google not having verified this app, which you can safely ignore by clicking Continue. Then comes another warning that the add-on wants to access your Google account, this too you can safely Allow. Now you should see a new onetime code, so once again visit google.com/device and once again agree to the terms. Finally, you can now
VISIONARY PI DEVICE “The Pi 4 might not yet be capable of driving two 4K displays at 60Hz, but it can certainly drive one.”
browse YouTube. At least it worked for us anyway – the add-on page suggests that if it doesn’t work for you then you should try turning on the Allow Insecure Apps setting in your Google Account.
But why support the Google monoculture? Consider getting your entertainment from decentralised or otherwise FOSS-friendly services such as PeerTube. Installing that is markedly easier than installing YouTube. Check out the wiki at https://framagit.org/StCyr/plugin. video.peertube/-/wikis/home.