pyatv: a python client library for the AppleTV

Posted on
Wed Mar 24, 2021 3:14 am
Stoutjesdijk offline
User avatar
Posts: 135
Joined: Dec 21, 2014
Location: The Netherlands

pyatv: a python client library for the AppleTV

Hi all,

I came across pyatv (https://pyatv.dev), a python client library to read and control an Apple TV.
It is very simple to install with
Code: Select all
pip install pyatv

Second step is pairing, which is quite easy, too. After that you are in business, and you can start bossing your AppleTV around.

To play around with it, I currently have a very simple (very dirty!) python script combined with an Indigo variable and trigger. I put a new command into the variable, and it is sent to the appleTV. I need to figure out how to do this in a better way, and more importantly: how to receive events from the AppleTV. A simple plugin is probably enough but I have never written one.

Code: Select all
import subprocess

var = indigo.variables[352797377] # AppleTVCommand

command = "/Library/Frameworks/Python.framework/Versions/3.9/bin/atvremote --id C8:69:CD:4D:75:49 --mrp-credentials `cat /Users/media/.appleTVcredentials` " + var.value
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = proc.communicate()
indigo.server.log(u"command error: %s" % err)
indigo.server.log("Sent AppleTV command %s" % var.value)


Anyhow, thought I would share the find!

EDIT: corrected typo in title

Best regards,

Mark

Trying to tie it all together...
| Indigo | Plex | NAD M33 | Unifi | LG WebOS | Tado | Sonos | SolarEdge | HUE |

Posted on
Wed Mar 24, 2021 5:03 am
Stoutjesdijk offline
User avatar
Posts: 135
Joined: Dec 21, 2014
Location: The Netherlands

Re: pyatv: a python client library for the AppleTV

While working out a way to integrate pyatv better with indigo, I noticed that pyatv uses python3. Looks like a slight wrinkle.

Best regards,

Mark

Trying to tie it all together...
| Indigo | Plex | NAD M33 | Unifi | LG WebOS | Tado | Sonos | SolarEdge | HUE |

Posted on
Wed Mar 24, 2021 8:49 am
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: pyatv: a python client library for the AppleTV

Yep - but we will someday move to Python 3. In the meantime, you can continue to run it like you show above and at least have control. If anyone else is looking at this and doesn't have Python 3 preinstalled (macOS Mojave and earlier), you can run the Python 3 installer from python.org somewhat safely (it doesn't appear to interfere with your Indigo install - YMMV).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 24, 2021 10:26 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: pyatv: a python client library for the AppleTV

That looks like a nice candidate for a new plugin.
I might have a look at it.

Karl.


Sent from my iPhone using Tapatalk

Posted on
Thu Mar 25, 2021 6:55 am
Stoutjesdijk offline
User avatar
Posts: 135
Joined: Dec 21, 2014
Location: The Netherlands

Re: pyatv: a python client library for the AppleTV

That would be great . Let me know if I can help, although my Python knowledge is at this time very limited.
I am currently discussing with the author a way to get around the python version issue.

Best regards,

Mark

Trying to tie it all together...
| Indigo | Plex | NAD M33 | Unifi | LG WebOS | Tado | Sonos | SolarEdge | HUE |

Posted on
Thu Mar 25, 2021 7:00 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: pyatv: a python client library for the AppleTV

Calling another python from an indigo plugin and sending commands and receiving output is not the issue.
The challenge is to make sure that all the python 3 modules are installed.

The plugin should also work with older Mac OS that do not come with py3. And also the open ssl libs have to be there.

Karo.


Sent from my iPhone using Tapatalk

Posted on
Thu Mar 25, 2021 8:14 am
mundmc offline
User avatar
Posts: 1060
Joined: Sep 14, 2012

Re: pyatv: a python client library for the AppleTV

Great find!
Karl if you pluginize this you will continue to be my indigo hero.

Posted on
Thu Mar 25, 2021 9:34 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: pyatv: a python client library for the AppleTV

That’s my weekend challenge.


Sent from my iPhone using Tapatalk

Posted on
Thu Mar 25, 2021 10:15 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: pyatv: a python client library for the AppleTV

good news: got the command line version to work on my MAC pro 2012 w mac os 10.14.6

1. install x-code
xcode-select —install

2. install python3 (do not use home-brew)
go to https://www.python.org/downloads/release/python-392/
and download the 64 bit installer and install (all point and click)

3.and download /install pyatv
pip3 install pyatv

all together took 5 minutes

Rest will be plugin design : device.xml, actions, menus, reading and writing commands

Karl

Code: Select all
 python3 atvremote.py scan
Scan Results
========================================
       Name: Bedroom
   Model/SW: 4K tvOS 14.5
    Address: 192.168.1.xx
        MAC: 40:CB:C0:D0:xx:xx
 Deep Sleep: False
Identifiers:
 - 01F74624-B8BB-4EF9-9E9E-xx
 - 40:CB:C0:D0:xx:xx
Services:
 - Protocol: MRP, Port: 49153, Credentials: None
 - Protocol: AirPlay, Port: 7000, Credentials: None

       Name: Living Room
   Model/SW: 4K tvOS 14.3
    Address: 192.168.1.xx
        MAC: D0:D2:B0:88:xx:xx
 Deep Sleep: False
Identifiers:
 - 0721B1F4-4CE5-4EA7-86B7-xx
 - D0:D2:B0:88:7B:77
Services:
 - Protocol: MRP, Port: 49152, Credentials: None
 - Protocol: AirPlay, Port: 7000, Credentials: None


the files are in
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyatv for MAC OS 10.14
and
/System/Volumes/Data/Volumes/XXXX/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyatv for MAC OS 11.2

XXXX is your disk volume name
Last edited by kw123 on Thu Mar 25, 2021 11:23 am, edited 1 time in total.

Posted on
Thu Mar 25, 2021 10:25 am
Korey offline
User avatar
Posts: 813
Joined: Jun 04, 2008
Location: Henderson, NV

Re: pyatv: a python client library for the AppleTV

kw123 wrote:
That’s my weekend challenge.


Sent from my iPhone using Tapatalk



Yes!!

This will be a fantastic addition!!!

Go Karl GO!! :D :D

--
Korey

Posted on
Thu Mar 25, 2021 11:26 am
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: pyatv: a python client library for the AppleTV

This is pretty exciting!

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Thu Mar 25, 2021 11:34 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: pyatv: a python client library for the AppleTV

pressure is on

Posted on
Thu Mar 25, 2021 10:53 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: pyatv: a python client library for the AppleTV

here the first green shot:
Screen Shot 2021-03-25 at 23.50.48.png
Screen Shot 2021-03-25 at 23.50.48.png (66.37 KiB) Viewed 3301 times

can only read the apple TVs

and very simple read out properties, but it seems to work


Karl

Posted on
Sat Mar 27, 2021 12:25 pm
Stoutjesdijk offline
User avatar
Posts: 135
Joined: Dec 21, 2014
Location: The Netherlands

Re: pyatv: a python client library for the AppleTV

Amazing speed Karl. I'm trying to figure out how to do it all with Node-Red but you're beating me to it. I think I'll wait :-)

Best regards,

Mark

Trying to tie it all together...
| Indigo | Plex | NAD M33 | Unifi | LG WebOS | Tado | Sonos | SolarEdge | HUE |

Posted on
Sat Mar 27, 2021 12:29 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: pyatv: a python client library for the AppleTV

Some competition is always good.


Sent from my iPhone using Tapatalk

Who is online

Users browsing this forum: No registered users and 7 guests

cron