与acestream引擎和http api交互
acestream的Python项目详细描述
python acestream
与acestream引擎和http api交互的python接口。
安装
pip install acestream
用法
importosimporttimeimportsubprocessfromacestream.serverimportServerfromacestream.engineimportEnginefromacestream.streamimportStream# Create an engine instanceengine=Engine('acestreamengine',client_console=True)# Connect to a remote serverserver=Server(host='streams.com',port=6880)# If the remote server is not available, connect to a local serverifnotserver.available:server=Server(host='127.0.0.1',port=6878)# Start engine if the local server is not availableifnotserver.available:engine.start()# Wait for engine to startwhilenotengine.running:time.sleep(1)# Start a stream using an acestream channel IDstream=Stream(server,id='ff36fce40a7d2042e327eaf9f215a1e9cb622b56')stream.start()# Open a media player to play the streamplayer=subprocess.Popen(['mpv',stream.playback_url],preexec_fn=os.setsid)# Wait for player to close and stop the streamplayer.communicate()stream.stop()# Stop acestream engineengine.stop()
搜索
importosimporttimeimportrandomimportsubprocessfromacestream.serverimportServerfromacestream.engineimportEnginefromacestream.searchimportSearch# Create an engine instanceengine=Engine('acestreamengine',client_console=True)# Connect to a local serverserver=Server(host='127.0.0.1',port=6878)# Start engine if the local server is not availableifnotserver.available:engine.start(stdout=subprocess.PIPE,stderr=subprocess.PIPE)# Wait for engine to startwhilenotengine.running:time.sleep(1)# Start a search for the sport categorysearch=Search(server,category='sport')search.get(page=1)# Iterate and print search resultsforresultinsearch.results:print(result.name.ljust(40),str(result.bitrate).ljust(10),result.infohash)# Start a random stream from the search resultsstream=random.choice(search.results).streamstream.start()# Open a media player to play the streamplayer=subprocess.Popen(['mpv',stream.playback_url],preexec_fn=os.setsid)# Wait for player to close and stop the streamplayer.communicate()stream.stop()# Stop acestream engineengine.stop()
贡献
github上的https://github.com/jonian/python-acestream欢迎错误报告和请求拉取。
许可证
python acestream在GPLv3