Ape / samsungctl

Remote control Samsung televisions via a TCP/IP connection
MIT License
713 stars 189 forks source link

Launch app on tv #75

Open Mcgurk125 opened 6 years ago

Mcgurk125 commented 6 years ago

Apologies, if this is not worth creating a new issue for... its more of a question.

The Samsung Smart View application - Link - has the ability to launch apps on the TV (Netflix, Plex etc.) - I was wondering if it was possible to replicate these calls?

Ape commented 6 years ago

Not currently supported, but I am accepting patches if you are able to reverse engineer the protocol.

freman commented 6 years ago

So after a day of hacking up some controls for our tvs (we have a wall of them)

{"method":"ms.remote.control","params":{"Cmd":"Move","Position":{"x":-1000,"y":1000,"Time":"1518675746190"},"TypeOfRemote":"ProcessMouseDevice"}}

Send in rapid succession after getting a json blob on the websocket saying that mouse mode is enabled (don't have the actual message handy, sorry)

{"method":"ms.channel.emit","params":{"event": "ed.apps.launch", "to":"host", "data":{"appId": "org.tizen.browser", "action_type": "NATIVE_LAUNCH"}}}

Launch an app, nfi how to change parameters or give it a url, we just set our home page to various dashboards (actually I wrote a tool that redirects the tv to the dashboard based on ip because typing on these tvs suck)

There's .a DEEP_LINK action type, but that seems to be for webapps, which has slightly different arguments.

{"method":"ms.channel.emit","params":{"event": "ed.installedApp.get", "to":"host"}}

List installed apps.

the last two are probably only supported on tvs that have "EDEN_available":"true" in their isSupport list

Mcgurk125 commented 6 years ago

Awesome work, do you http post this to web service, do you know which port?

freman commented 6 years ago

Just sent up the same websocket the button presses are sent

Mcgurk125 commented 6 years ago

Quick question, I tried this last night replacing the key with json you gave, however it just sends an array of commands rather than a block. Any chance you can share your tool or just bash cmd used? Many thanks

freman commented 6 years ago

My code is written in Go, but here's a sample in javascript that should start the browser.

NB, the tv will prompt for permission so you'll need to grant that and run the code twice

ws = new WebSocket('ws://10.10.1.21:8001/api/v2/channels/samsung.remote.control');
ws.onopen = function() {ws.send('{"method":"ms.channel.emit","params":{"event": "ed.apps.launch", "to":"host", "data":{"appId": "org.tizen.browser", "action_type": "NATIVE_LAUNCH"}}}')};
ws.onmessage = function(e) {console.log(e)}
Mcgurk125 commented 6 years ago

Much appreciated!

freman commented 6 years ago

and launching a url...

{"method":"ms.channel.emit","params":{"event": "ed.apps.launch", "to":"host", "data":{"appId":"org.tizen.browser","action_type":"NATIVE_LAUNCH","metaTag":"http:\/\/hackaday.com"}}}
freman commented 6 years ago

If you need to send text, base64 encode your string

{"method":"ms.remote.control","params":{"Cmd":"$BASE64ENCODEDSTRING$","TypeOfRemote":"SendInputString","DataOfCmd":"base64"}}

You must connect via wss on port 8002 if you want to send passwords, otherwise you have to post to a https url

edit: Here's some code

https://gist.github.com/freman/8d98742de09d476c4d3d9e5d55f9db63

marius1968 commented 6 years ago

It is possible to obtain the channel list ?

kristenmills commented 6 years ago

@freman This is awesome! Quick question, any chance you figured out how to determine which app is currently open?

mr-romeijn commented 6 years ago

@freman

Thanks for this awesome find. I've tried executing the javascript you posted but sadly it's not doing anything. I'm getting a response though but the browser is not opening on my tv. Is the app-id for the browser generic on all tv models? Also how would i go about retrieving a list of installed apps, i want to open netflix for example.

maartenpeels commented 6 years ago

I'm having some trouble launching Netflix. When I list all apps a big JSON list is returned among which: {'appId': '11101200001', 'app_type': 2, 'icon': '/opt/share/webappservice/apps_icon/FirstScreen/11101200001/250x250.png', 'is_lock': 0, 'name': 'Netflix'}

But when I send the following JSON over the websocket:

payload = json.dumps({
    "method": "ms.channel.emit",
    "params": {
            "event": "ed.apps.launch",
            "to": "host",
            "data": {
                "appId": "11101200001",
                "action_type": "NATIVE_LAUNCH"
                }
        }
    })

I get an error:ERROR:websocket:close status: 31522, but with org.tizen.browser as appId it works. Would really appreciate it if someone can help me with this.

kristenmills commented 6 years ago

@maartenpeels For netflix and pretty much everything i've tried that wasn't the browser, you should use "action_type": "DEEP_LINK" instead of "action_type": "NATIVE_LAUNCH". Though a quick way to check that, anything with "app_type": 2 uses DEEP_LINK and I believe "app_type": 4 is NATIVE_LAUNCH.

freman commented 6 years ago

@marius1968 sorry not that I've looked for.

@kristenmills not that I've found, i'd also like to figure out how to see the current open tab in the browser, if you always assume the browser is empty it'll start a new tab (overloading our graphing service), if you always assume it'll work eventually it'll start up and open the 'featured' screen not the 'home' screen despite telling the damn thing to always go to the 'home' screen several times.

@nickyromeijn {"method":"ms.channel.emit","params":{"event": "ed.installedApp.get", "to":"host"}}

@maartenpeels it appears @kristenmills is correct, we only use it to open a web app and see our charts... somewhat unreliably but still easier than doing it by hand every day.

marius1968 commented 6 years ago

@maartenpeels, @nickyromeijn, @kristenmills It's easier to use the dial protocol for the applications listed in dial registry (include Netflix, Youtube).

So, to identify if a particular application is installed you can use the call : curl -X GET -i 'yourIP:8001/ws/apps/Netflix' and and you will receive the answer : Netflixrunning6.0.003 OR Netflixstopped6.0.003

To launch the desired application you can use : curl -X POST -i 'http://yourIP:8001/ws/apps/Netflix' with response http://yourIP:8001/ws/apps/Netflix/run

@freman How on earth did you managed to identify this logs? The Samsung API documentation does not exist and I'm trying for 3 months (without success) for Samsung Tizen to get channel list and subscription to a channel/volume change event. Can you can give us a hint in this direction?

freman commented 6 years ago

@marius1968 because I couldn't even get the app to work, mostly decompiling their app. Once I did manage to get the app working, tcpdump

MyCodeRocks commented 6 years ago

@freman you have no idea the brilliance of this. I have been researching this for over two months right now. Even got into some thread that the guys are trying to reverse engineering the encryption DLL as that was the, thinking as to why no one knows how to communicate with the TV. I have been testing some the codes and this works really well.

Got the Ws app taking to the TV accepted it as a authorised app, can navigate call apps, open browser etc.

Question: once accepting the connection on the TV, and you disconnect for example. When you reconnect my TV is far so didn't see the next time I connected if it asked again for allow? Once you allow the app do I have to. Do this again or will the same ws://ip:8001....app=basecode64 always work?

MyCodeRocks commented 6 years ago

Another Q anyone figure out where "/opt/share/webappservice/apps_icon/FirstScreen/11101200001/250x250.png" or any of the icons actually reside? Would be awesome in an app to show these.

alexandre-leites commented 5 years ago

Anyone has able to get if some non-standard app is running?

I can get running status with http://X:8080/ws/apps/Netflix but I can't get if Deezer (3201608010191) or Spotify (3201606009684) is running.

Maybe there is a way using ws?

marius1968 commented 5 years ago

@xalexslx only applications listed in Dial Registry ... for Spotify try com.spotify.Spotify

pegatron89 commented 5 years ago

@marius1968 - Plex is listed in the DIAL registry as Plex - But i cant get it to load on my TV using the WS method above. YouTube works as does Netflix... Just not Plex unfortunately.

alexandre-leites commented 5 years ago

@marius1968 @pegatron89 Same as you. Tried both (Plex, Spotify, Deezer, Twitch) and it didn't worked, just Netflix and YouTube.

If there is a way to get app status via ws it will be good because we can just pass the AppId.

pegatron89 commented 5 years ago

@xalexslx a quick google and the App ID for plex is: 111199000681

https://forums.plex.tv/t/home-automation-start-plex-whats-your-appid/38276

Do you know how to pass the appID? I tried 192.168.0.62:8001/ws/apps/111199000681 on the off chance but this did not work.

DerGute commented 5 years ago

Hello! At first thanks for this great possibility. For my understanding i have a question: What do you mean with DIAL Registry?

I tried to start Amazon with a curl Post. Netflix and youtube work great but Amazon doesnt. I got the Applicationname "Amazon Video" . It seems thtat curl cannot handle Applicationnames with a whitespace in it. I have to use the ApplicationID, but with ApplicationID i cant launch Amazon Video.

Any suggestions?

Best regards

pegatron89 commented 5 years ago

@DerGute Try one of the following instead of amazon video; com.amazon.mp3 Amazon primeLive com.amazon

There are more within the registry (see website below) I am at work at the moment so cant confirm if these work.

http://www.dial-multiscreen.org/dial-registry/namespace-database

alexandre-leites commented 5 years ago

I have tried several ids from DIAL Registry with installed apps on my Samsung TV. None of them worked except for YouTube and Netflix. It seems that Samsung doesn't follow the rules?

Also, I got all app ids using the following command from the websocket

{"method":"ms.channel.emit","params":{"event": "ed.installedApp.get", "to":"host"}}

And I can launch them with

{"method":"ms.channel.emit","params":{"event": "ed.apps.launch", "to":"host", "data":{"appId":"org.tizen.browser","action_type":"NATIVE_LAUNCH","metaTag":"http:\/\/hackaday.com"}}}

But I cant get current status of any running app except for YouTube and Netflix.

alexandre-leites commented 5 years ago

Hi,

I downloaded the whole DIAL registry and ran against my Samsung TV using Postman runner. Unfortunately only Netflix, YouTube and Pandora was found using the DIAL ids.

Here are the list of my TV currently installed apps:

zoelechat commented 5 years ago

Here is, raw, a bunch of (3rd party) app_tizen_id's (to be completed if I find anymore). If some are not explicit enough, don't ask me which app they are: I don't know!

Ahw07WXIjx.Dailymotion
tisT7SVUug.tunein
cexr1qp97S.Deezer
xqqJ00GGlC.okidoki
4ovn894vo9.Facebook
vbUQClczfR.Wuakitv
QizQxC7CUf.PlayMovies
QBA3qXl8rv.Kick
DJ8grEH6Hu.arte
JtPoChZbf4.Vimeo
hIWwRyZjcD.GameFlyStreaming
sHi2hDJGmf.nolim
guMmq95nKK.CanalPlusLauncher
RN1MCdNq8t.Netflix / org.tizen.netflix-app
evKhCgZelL.AmazonIgnitionLauncher2 / org.tizen.ignition
9Ur5IzDKqV.TizenYouTube
gDhibXvFya.HBOGO
EmCpcvhukH.ElevenSports
ASUvdWVqRb.FilmBoxLive
rJeHak5zRg.Spotify
ABor2M9vjb.acc   (AccuWeather)
EkzyZtmneG.My5
yFo6bAK50v.Dennexpres
gdEZI5lLXr.Europa2FHD
bm9PqdAwjv.TvSme
dH3Ztod7bU.IDNES
wsFJCxteqc.OnetVodEden
rZyaXW5csM.TubaFM
4bjaTLNMia.curzon
RVvpJ8SIU6.ocs
bstjKvX6LM.molotov
RffagId0eC.SfrSport
phm0eEdRZ4.ExtraTweetIM2
VAarU8iUtx.samsungTizen   (Vevo)
g0ScrkpO1l.SmartIPTV
kIciSQlYEM.plex
...
alexandre-leites commented 5 years ago

None of them worked with dial api.

chocorem commented 5 years ago

I get this to work by using DEEP_LINK to start the application

example ws.onopen = function() {ws.send('{"method":"ms.channel.emit","params":{"event": "ed.apps.launch", "to":"host", "data":{"appId":"bstjKvX6LM.molotov","action_type":"DEEP_LINK"}}}')}; to start molotov

I have on my TV Plex and MyCanal I would like to start but I do not know how to get the app_tizen_id's as @zoelechat described in his mail !

zoelechat commented 5 years ago

None of them worked with dial api.

They're precisely not meant to be launched through dial API but natively. DEEP_LINK? I personnally use NATIVE_LAUNCH.

I do not know how to get the app_tizen_id's

If it was so easy I wouldn't see any interest in publishing a list ;) MyCanal is in list (CanalPlusLauncher). Plex, well I can check, have to install it, will add...

chocorem commented 5 years ago

@zoelechat That is what is weird ... canalplus is not working, may be this is because it is canalplusVOD .....

On the 2016 TV, there is now a native application installed named MyCanal used to connect to their programs. that is what I'm trying to get !

chocorem commented 5 years ago

@zoelechat I rebooted the TV and now canal is working ! So all good , I will try to implement this in my Jeedom domotic now !

zoelechat commented 5 years ago

On the 2016 TV, there is now a native application installed named MyCanal used to connect to their programs. that is what I'm trying to get !

mmmh that CanalPlusLauncher icon says MyCanal indeed, I've got 2016 TV too but can't find anything else related in store... OK saw you latest post :) Here's Plex: kIciSQlYEM.plex

chocorem commented 5 years ago

Plex is also working ! thanks

chocorem commented 5 years ago

anybody knows how to send these commands via PHP ?

vitalets commented 5 years ago

Hi all! There is another way to launch/install/close app on Samsung TV - by using SmartView api:

# launch youtube
curl -X POST http://TV_IP:8001/api/v2/applications/111299001912

# get status
curl -X GET http://TV_IP:8001/api/v2/applications/111299001912

# close
curl -X DELETE http://TV_IP:8001/api/v2/applications/111299001912

# open installation page in Samsung store
curl -X PUT http://TV_IP:8001/api/v2/applications/111299001912

For dealing with another app just change the id 111299001912.

Mcgurk125 commented 5 years ago

Awesome, would be great if we could get parameters working. I'd love to be able to do something on launch based on the application you're using.

On Mon, 23 Jul 2018, 18:15 Vitaliy Potapov, notifications@github.com wrote:

Hi all! There is another way to launch/install/close app on Samsung TV - by using SmartView api:

launch youtube

curl -X POST http://TV_IP:8001/api/v2/applications/111299001912

get status

curl -X GET http://TV_IP:8001/api/v2/applications/111299001912

close

curl -X DELETE http://TV_IP:8001/api/v2/applications/111299001912

open installation page in Samsung store

curl -X PUT http://TV_IP:8001/api/v2/applications/111299001912

For dealing with another app just change the id 111299001912.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Ape/samsungctl/issues/75#issuecomment-407133548, or mute the thread https://github.com/notifications/unsubscribe-auth/AfA5u1Qn30QKM-9iMDNGw7kEJbSVulpbks5uJgS4gaJpZM4RkLdr .

vitalets commented 5 years ago

and launching a url...

btw @freman how did you managed to find metaTag field in https://github.com/Ape/samsungctl/issues/75#issuecomment-375164834? I don't see it even in native samsung android app..

WolfganP commented 5 years ago

@vitalets did you find any way to list the installed apps using the api/v2 interface?

alexandre-leites commented 5 years ago

@vitalets

Awesome, they followed RESTful principles on the v2 API. I'll test when I get home.

@WolfganP Have you tried curl -X GET http://TV_IP:8001/api/v2/applications ? Maybe it will work.

WolfganP commented 5 years ago

@xalexslx No, curl -X GET http://TV_IP:8001/api/v2/applications doesn't work


{
  "status": 404,
  "message": "Not Found",
  "code": 404
}
alexandre-leites commented 5 years ago

I got how to start the web browser with google url using the REST API. However I cannot use it with other urls for some reason...

curl -X POST \
  http://X:8001/api/v2/webapplication/ \
  -H 'Content-Type: application/json' \
  -d '{"url": "http://www.google.com"}'
Mcgurk125 commented 5 years ago

What other URL are you trying to open? I wonder if it needs to be encoded first

On Tue, 24 Jul 2018, 01:17 Alexandre Leites, notifications@github.com wrote:

I got how to start the web browser with google url using the REST API. However I cannot use it with other urls for some reason...

curl -X POST \ http://X:8001/api/v2/webapplication/ \ -H 'Content-Type: application/json' \ -d '{"url": "http://www.google.com"}'

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Ape/samsungctl/issues/75#issuecomment-407239648, or mute the thread https://github.com/notifications/unsubscribe-auth/AfA5u3Rw57YSjFAEYfYRVmhMCjRlrhfZks5uJmeIgaJpZM4RkLdr .

alexandre-leites commented 5 years ago

@Mcgurk125 facebook, yahoo, etc, nothing weird.

vitalets commented 5 years ago

@vitalets did you find any way to list the installed apps using the api/v2 interface?

AFAIK it is impossible via api/v2. You can check all endpoints on the server side in Tizen sources. The only way I know to get installed apps is using WebSocket to samsung.remote.control channel with message ed.installedApp.get mentioned here. But combination of these two methods should be enough for everything.

I got how to start the web browser with google url using the REST API. However I cannot use it with other urls for some reason... curl -X POST \ http://X:8001/api/v2/webapplication/ \ -H 'Content-Type: application/json' \ -d '{"url": "http://www.google.com"}'

This endpoint is for launching Samsung Cloud apps. The url must be approved by Samsung team to get opened this way. google.com is approved. Have a look on the docs about this feature.

marius1968 commented 5 years ago

@vitalets It's possible to get the program list using api/v2 ? Thx

vitalets commented 5 years ago

@vitalets It's possible to get the program list using api/v2 ? Thx

If you mean channels list - no. Api/v2 is designed for managing your own tv app, nothing more.

But you can retrieve channel list inside tv app (tizen.tvchannel.getChannelList) and communicate with your app via api/v2.

marius1968 commented 5 years ago

@vitalets Thanks, I knew that. But I'm looking for a way to get access without installing an application on Smart TV. Do you think that's possible?