允许通过beefweb插件控制Python中的Foobar2000和DeaDBeeF媒体播放器。
pyfoobeef的Python项目详细描述
允许通过beefweb插件API控制Foobar2000和DeaDBeeF媒体播放器。在
- 异步和同步客户端
- 带有回调的异步事件侦听器
- 对于Python 3.6及更高版本
- 麻省理工学院执照
安装
为您的媒体播放器安装并配置beefweb插件。在
在运行:
pip install pyfoobeef
在
示例
同步客户端:
^{pr2}$异步客户机采用非常类似的格式:
importpyfoobeefimportasyncioasyncdefexample():player=pyfoobeef.AsyncClient("localhost",8880)# Add a new playlist.new_playlist=awaitplayer.add_playlist(title="My New Playlist")awaitplayer.set_current_playlist(new_playlist)# Add items to the playlist. Note that paths including drive letters# are case sensitive even on Windows due to limitations of the beefweb# plugin (so r"c:\Music" would not work here).awaitplayer.add_playlist_items(new_playlist,items=[r"C:\Music"])# sort items by lengthawaitplayer.sort_playlist_items(new_playlist,by="%length_seconds%")# Get information about the first 10 items in a playlist.items=awaitplayer.get_playlist_items(new_playlist,column_map=["%artist%","%title%","%length%"],offset=0,count=10,)foriteminitems:print(item)# Play a specific item.awaitplayer.play_specific(new_playlist,4)asyncio.run(example())
当接收到某些事件时,异步事件侦听器可以自动执行回调,或者可以根据EventListener对象的属性确定媒体播放器的状态:
importpyfoobeefimportasynciodefprint_active_item(state):print("From player state callback. Active item is:")print(state.active_item)defprint_playlists(playlists):print("From playlists callback. Current playlists:")forplaylistinplaylists:print(playlist)asyncdefexample():listener=pyfoobeef.EventListener(base_url="localhost",port=8880,active_item_column_map={"%artist%":"artist","%title%":"title","%length%":"length",},)# Add callbacks for player events.listener.add_callback("player_state",print_active_item)listener.add_callback("playlists",print_playlists)# Start listening for events from the player.awaitlistener.connect(reconnect_time=1)awaitasyncio.sleep(10)# The last received information about the player state and playlists# can be accessed from the listener object itself.print("From the last player state object saved to listener."" Active item is:")print(listener.player_state.active_item)print("Estimated playback position: ",listener.player_state.estimated_position_mmss())forplaylistinlistener.playlists:print(playlist)awaitasyncio.sleep(10)# The listener should always be disconnected when done.awaitlistener.disconnect()asyncio.run(example())
- 项目
标签: