控制苹果电视的库
pyatv的Python项目详细描述
这是一个python库,用于控制和查询来自apple tv的信息。它是异步的 (python 3.4语法)并支持大多数常规apple远程应用程序执行的命令 以及一些附加的iTunes命令,比如改变媒体位置它实现了 旧的DAAP协议,不支持来自新mediaremote.framework的功能。支持 因为如果这个协议被完全反向工程的话,将来可能会添加这个。
麻省理工学院的许可证是用于这个图书馆的
功能
- 自动发现设备(zeroconf/bonjour)
- 推送更新
- 遥控器配对
- AirPlay流URL(包括TVOS 10.2+)
- 播放控制(播放、暂停、下一步、停止等)
- 导航控件(选择、菜单、顶部菜单、箭头键)
- 获取PNG格式的图片
- 当前正在播放(如标题、艺术家、专辑、总时间等)
- 更改媒体位置
- 洗牌并重复
要求
- Python=3.5.3
- 有关其他库,请参见文档
入门
安装
使用pip:
$ pip install pyatv
注意:您需要一些系统软件包,请在Debian或类似软件上运行:
$ sudo apt-get install build-essential libssl-dev libffi-dev python-dev
使用api
下面是一个使用自动发现和打印播放内容的简单示例:
importasynciofrompyatvimporthelpers@asyncio.coroutinedefprint_what_is_playing(atv):playing=yield fromatv.metadata.playing()print('Currently playing:')print(playing)helpers.auto_connect(print_what_is_playing)
其他更高级的例子可以在examples中找到。
使用cli应用程序
也可以使用reference cli应用程序:
# Automatically discover device (zeroconf) $ atvremote -a play $ atvremote -a next # Scanning for devices on network $ atvremote Found Apple TVs: - Apple TV at 10.0.10.22 (hsgid: 00000000-1234-5678-9012-345678901234) Note: You must use 'pair' with devices that have home sharing disabled # Manually specify device $ atvremote --address 10.0.10.22 --hsgid 00000000-1234-5678-9012- 345678901234 playing Media type: Music Play state: Playing Position: 0/397s (0.0%)# Passing multiple commands $ atvremote -a next next play playing stop # List all commands supported by a device $ atvremote -a commands Remote control commands: - down - Press key down - left - Press key left - menu - Press key menu - next - Press key next - pause - Press key play - play - Press key play - previous - Press key previous - right - Press key right - select - Press key select - set_position - Seek in the current playing media - set_repeat - Change repeat mode - set_shuffle - Change shuffle mode to on or off - stop - Press key stop - top_menu - Go to main menu (long press menu) - up - Press key up Metadata commands: - artwork - Return artwork for what is currently playing (or None) - artwork_url - Return artwork URL for what is currently playing - device_id - Return a unique identifier for current device - playing - Return what is currently playing Playing commands: - album - Album of the currently playing song - artist - Artist of the currently playing song - hash - Create a unique hashfor what is currently playing - media_type - Type of media is currently playing, e.g. video, music - play_state - Play state, e.g. playing or paused - position - Position in the playing media (seconds) - repeat - Repeat mode - shuffle - If shuffle is enabled or not - title - Title of the current media, e.g. movie or song name - total_time - Total play time in seconds AirPlay commands: - finish_authentication - End authentication process with PIN code - generate_credentials - Create new credentials for authentication - load_credentials - Load existing credentials - play_url - Play media from an URL on the device - start_authentication - Begin authentication proces (show PIN on screen) - verify_authenticated - Check if loaded credentials are verified Device commands: - artwork_save - Download artwork and save it to artwork.png - auth - Perform AirPlay device authentication - push_updates - Listen for push updates Global commands: - commands - Print a list with available commands - help - Print help text for a command - pair - Pair pyatv as a remote control with an Apple TV - scan - Scan for Apple TVs on the network
键入atvremote --help列出所有支持的命令。
缺少功能和改进
大部分核心功能现在已经到位,api也开始成熟。 足以很快被称为“稳定”。路线图上的东西列在下面。
计划任务
- 实现MediaRemoteTV协议
- 研究设备扫描的稳健性
- 扩展Airplay支持
- 轻松传输本地文件
次要任务
- 帮助命令获取命令(atvremote)的完整帮助文本done
- 为atvremote编写简单的烟雾测试
- 改进文档
- 更多示例认为已完成
- 更好的pydoc类和方法文档
- 文档中的手册/完成
- 添加到readthedocs.iodone
开发
派生此项目,克隆它并运行setup_dev_env.sh以设置虚拟 环境和安装开发所需的一切:
git clone https://github.com/postlund/pyatv.git cd pyatv ./setup_dev_env.sh source bin/activate
您可以使用python setup.py test运行测试。另外,确保 pylint、flake8和pydoc在提交之前通过。这是自动完成的 如果你只运行tox。
使用atvremote时,传递--debug以获得更好的日志记录。