Skip to content

Instantly share code, notes, and snippets.

@Ircama
Last active April 28, 2024 23:48
Show Gist options
  • Star 93 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Ircama/1f29c2d2def75da6604756a3c91a8ab4 to your computer and use it in GitHub Desktop.
Save Ircama/1f29c2d2def75da6604756a3c91a8ab4 to your computer and use it in GitHub Desktop.
Replacing Netflix and Amazon keys of the webOS LG TV LG Magic Remote with other apps

Replacing Netflix and Amazon keys of the webOS LG TV LG Magic Remote with other apps

This procedure allows substituting one or both Netflix and Amazon keys of the Magic Remote Control Unit with other apps or TV control menus of the webOS LG TV.

Netflix and Amazon keys can be found just over the Red-Green-Yellow-Blue color buttons of such remote.

Assumption for this procedure is that you accept to uninstall the apps related to the keys to be substituted. Example: if you want to replace the Netflix key, you need to uninstall Netflix (possibly, you are not using Netflix if you do not need such key).

To uninstall Netflix or Amazon Prime, press the Home key of the Magic Remote, select the "LG Content Store" app, press "APP" at the top of the screen, press "My Apps", press the "Remove" button at the top-right corner and select the apps you want to remove.

Also, you need to setup your LG TV in developer mode. If the service you need to start is a webOS App that you already can recompile, simply change its "id" in appinfo.json. Otherwise, you have to install specific webOS apps that launch the features that you need to activate by pressing the keys. The following steps help to setup the environment, develop the launcher apps, compile and install them on the TV.

Follow the instructions in App Testing page to:

Follow Deploying a Web App page to get acquainted with the CLI usage.

At the end of the previous steps, open the "webOS TV CLI" app on your PC. The following procedure is tested with Windows 10. The apps are tested on webOS TV release 4.1.4, API 4.1.0.

To connect to your TV, you might want to get your passphrase; this can be done through the "Developer mode" app on the TV or with the following command:

ares-setup-device -listfull | findstr "passphrase"

Notice that the passphrase is case sensitive.

With the following command, check the configured name of your TV device (deviceinfo: prisoner@...):

ares-setup-device -list

this is the same as:

ares-device-info --device-list

The output should be:

name      deviceinfo                   connection  profile
--------  ---------------------------  ----------  -------
oled      prisoner@<ip address>:9922   ssh         tv
emulator  developer@<ip address>:6622  ssh         tv

We suppose that the label used to reach your TV is "oled".

Check proper connection by retrieving the system information of your TV:

ares-device-info --device oled

You need to have developer mode active to connect (run the "Developer Mode" app and check that Dev Mode Status is ON). Also check your IP address. If it needs to be changed, run ares-setup-device and modify your TV configuration (oled).

First you need to discover the App ID of the applications you need to connect to the keys. Run the app you want to start. The following command allows to discover most of the appIds running on your TV.

ares-novacom --device oled --run "ps -ef|sed -n '/sed -n/d;/appId/{s/.*appId.:\([^,]*\).*/\1/;p;}'"

After discovering the ID, use the command ares-launch --device oled <appid> to test launching the app from your PC.

Here are some app ID that you can check:

ares-launch --device oled com.webos.app.livetv
ares-launch --device oled com.webos.app.hdmi1
ares-launch --device oled com.palm.app.settings
ares-launch --device oled com.webos.app.browser
ares-launch --device oled com.webos.app.photovideo
ares-launch --device oled com.webos.app.discovery
ares-launch --device oled com.webos.app.connectionwizard
ares-launch --device oled com.webos.app.miracast
ares-launch --device oled com.webos.app.notificationcenter
ares-launch --device oled com.webos.app.tvuserguide
ares-launch --device oled com.webos.app.scheduler
ares-launch --device oled com.webos.app.channelsetting
ares-launch --device oled spotify-beehive
ares-launch --device oled amazon
ares-launch --device oled netflix

Notice that the last two ones, amazon and netflix, should not be installed.

There are configuration files like this one in webOS, that are references for the OS action of WebOS.Key_webOS_Netflix and WebOS.Key_webOS_Amazon keys, that by default run appId = "netflix" and appId = "amazon" respectively. Check this for instance:

ares-novacom --device oled --run "cat /usr/lib/qt5/qml/KeyFilters/appLaunch.js"|clip

The previous command copies the file to the clipboard. Paste it to an editor (e.g., Notepad++) to inspect the file. All OS files are readonly and cannot be changed. Anyway, if amazon and netflix apps are not installed, the related appIds can be resused by app launchers.

Let us consider you want to substitute netflix with youtube, so that when pressing the netflix key, youtube is launched.

Test launching Youtube from your PC:

ares-launch --device oled youtube.leanback.v4

You can discover "youtube.leanback.v4" appId with the previously described method.

Now we need to create the launcher app. Read Build Your First App for webOS TV to understand how to create an app using the CLI.

Change directory to your local development path (let us consider Downloads for instance):

cd %HOMEPATH%\Downloads

Use ares-generate to create the basic Web App template for webOS TV. Let us call it "launcher". We need to set the custom property id to the name of the key. netflix in our case. Title should be set to a description name related to the launched app:

ares-generate -t basic -p "id=netflix" -p "title=YouTube App Launcher with the Netflix key" -p "vendor=open source" -p "transparent=true" launcher

The previous command creates the launcher directory, including a working source.

Edit appinfo.json in the launcher directory and remove the double quotes from the true value of transparent parameter, so that it is set as follows:

  "transparent": true

Other App Metadata can be optionally set, but are not strictly necessary.

Replace the index.html file in the launcher directory with the following:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=1920, user-scalable=no">
	<script src="webOSTVjs-1.2.0/webOSTV.js" charset="utf-8"></script>
	<script src="webOSTVjs-1.2.0/webOSTV-dev.js" charset="utf-8"></script>
	<script type="text/javascript">
    (function() {
        // Launching app without parameter
        var request = webOS.service.request("luna://com.webos.applicationManager", {
            method: "launch",
            parameters: { "id": "youtube.leanback.v4" },
            onSuccess(response) {
              window.close();
            },
            onFailure(error) {
              window.close();
            },
        });
    })();
	</script>
</head>
<body>
</body>
</html>

We use the webOS.service.request LS2 API to call a webOS Service from the Web App, including the appropriate URI (e.g., luna://com.webos.applicationManager), method (launch), parameters ({ "id": "<appId>" }) and setting up callbacks to close the application.

The id parameter in the javascript shall be assigned to the feature or the app to launch; in our case, YouTube is youtube.leanback.v4:

            parameters: { "id": "youtube.leanback.v4" },

Create a package with the name of the original ID (in our case, netflix):

ares-package launcher

The local directory will include a file named with the original ID of the application, followed by the version and "_all.ipk" (netflix_0.0.1_all.ipk in our case).

Install the created app to the TV:

ares-install --device oled netflix_0.0.1_all.ipk

Done.

Note. Connecting your TV via SSH is not needed. In case you have SSH installed and you want to test it, use the following command:

ssh -i %HOMEPATH%\.ssh\oled_webos prisoner@<ip address> -p 9922 "/bin/bash -i"

Custom installed applications are stored in folder /media/developer/apps/usr/palm/applications/. Files can be edited online.

Notice that luna-send is protected and luna-send-pub should be used instead:

# Get TV data:
luna-send-pub -n 1 -f luna://com.palm.systemservice/osInfo/query '{ "subscribe": false }'
cat /var/run/nyx/device_info.json
cat /var/run/nyx/os_info.json

# Start YouTube application
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{ "id": "youtube.leanback.v4" }'

# Run Netflix application
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "netflix", "params":{}}'

# Welcome popup 
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.mystarter", "params": {}}'

# Configuration menu:
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"picture"}}'
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"sound"}}'
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"channel"}}'
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"network"}}'
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"general"}}'
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.palm.app.settings", "params": {"target":"accessibility"}}'

# Show TV User Guide:
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.tvuserguide"}'

# Switch to TV
luna-send-pub -n 1 "luna://com.webos.applicationManager/launch" '{ "id": "com.webos.app.livetv" }'

# Toggle TV/Radio
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.livetv", "params": {"id":"tvKey"}}'

# Subtitle menu
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.tvhotkey", "params": {"activateType":"subtitle"}}'

# Multi-sound menu
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.tvhotkey", "params": {"activateType":"multi-sound-setting"}}'

# Audio-description
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.tvhotkey", "params": {"activateType":"audio-description"}}'

# Channel menu
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.livemenu", "params": {"activateType":"channels"}}'

# Virtual keyboard Search
luna-send-pub -n 1 -f "luna://com.webos.applicationManager/launch" '{"id": "com.webos.app.voice", "params": {"activateType":"mrcu", "launchMode":"vkb"}}'

# listing launch points is not allowed:
luna-send-pub -n 1 "luna://com.palm.applicationManager/listLaunchPoints" "{}"

# Also, closing an application or getting app info is denied:
luna-send-pub -n 1 -f "luna://com.webos.service.applicationmanager/closeByAppId" '{"id":"youtube.leanback.v4"}'
luna-send-pub -n 1 -f "luna://com.webos.service.applicationmanager/getAppInfo" '{"id":"youtube.leanback.v4"}'
luna-send-pub -n 1 -f "luna://com.webos.service.applicationmanager/getForegroundAppInfo" '{}'
@bricktror
Copy link

Hi all,
Was lookin into trying this and did some research to solve the preload issue.

Could it be solved by wrapping the app launch in a listener for the weboslaunched event (https://webostv.developer.lge.com/develop/app-developer-guide/web-app-lifecycle/)?

E.g.
document.addEventListener('webOSLaunch', function(){webOS.service.request(...); })

@triumfas
Copy link

triumfas commented Jun 16, 2022

Can anyone share Tidal App ID/ App name so I could start ir when remapping? Another option could help - how to make HTTP Post request upon opening the app (I could use it with webhook and home assistant)?
Thanks

@Maschine2501
Copy link

Maschine2501 commented Nov 26, 2022

Google

This would interesst me too....

I tried remapping the rakutenTV Button with the sideloaded crunchyroll app, but the tv blanked after hitting the Rakuten Button...
After some testing I found out that my TV (65C2) had a newer Java Version, 1.2.4, not 1.2.0 as in the instructions.
This is the example that worked for me:

script src="webOSTVjs-1.2.4/webOSTV.js" charset="utf-8"></script
script src="webOSTVjs-1.2.4/webOSTV-dev.js" charset="utf-8"></script

@andrewfraley
Copy link

Greetings, I've built what I think is an easier and persistent solution to solve this, but it does require a rooted TV. You don't have to mess with creating a custom app, this is just a Python script that is run on boot that watches for button presses on the remote. You can use this to make any button launch any app, and it also provides built in functionality to adjust the energy management and oled backlight settings via button presses (for example I use the yellow button to cycle energy savings modes and the blue button to toggle eye comfort mode).

https://github.com/andrewfraley/magic_mapper

@maatthc
Copy link

maatthc commented Apr 27, 2023

Just a fyi, for those with a rooted tv, you can control the Netflix "preloading" by editing /var/preferences/webos-preload-manager-conf.json and changing "netflix":true to "netflix":false... tested on webOS TV 7.3.0

@sdellava
Copy link

sdellava commented Sep 8, 2023

Super cool!!

I found this page looking for a way to remap a remote key. I guess the remote is missing one importa key: the "quit" command. It is used in almost all menù of the setopbox but it is missing as fisical key. So my question is: is it possible to remap, i.e., the red key to the "quit" code?

@5moufl
Copy link

5moufl commented Oct 21, 2023

Super cool!!

I found this page looking for a way to remap a remote key. I guess the remote is missing one importa key: the "quit" command. It is used in almost all menù of the setopbox but it is missing as fisical key. So my question is: is it possible to remap, i.e., the red key to the "quit" code?

Long-pressing the back key seems to do the trick for me.

@sdellava
Copy link

Long-pressing the back key seems to do the trick for me.

WOW ... IT WORKS !! Years looking for that function and it was always under my thumb !!!!

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment