mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2025-12-08 21:06:43 +03:00
27
main.py
27
main.py
@@ -6,14 +6,6 @@ from cache import AsyncTTL
|
|||||||
import json
|
import json
|
||||||
import atexit
|
import atexit
|
||||||
|
|
||||||
def exit_handler():
|
|
||||||
print("exiting...")
|
|
||||||
loop = asyncio.get_event_loop()
|
|
||||||
loop.stop()
|
|
||||||
atv.close()
|
|
||||||
|
|
||||||
atexit.register(exit_handler)
|
|
||||||
|
|
||||||
|
|
||||||
def listToTuple(function):
|
def listToTuple(function):
|
||||||
def wrapper(*args):
|
def wrapper(*args):
|
||||||
@@ -111,7 +103,7 @@ async def connect_atv(loop, identifier, airplay_credentials):
|
|||||||
atvs = await pyatv.scan(loop, identifier = identifier)
|
atvs = await pyatv.scan(loop, identifier = identifier)
|
||||||
|
|
||||||
if not atvs:
|
if not atvs:
|
||||||
print("No device found", file=sys.stderr)
|
print("No device found")
|
||||||
return
|
return
|
||||||
|
|
||||||
config = atvs[0]
|
config = atvs[0]
|
||||||
@@ -124,7 +116,6 @@ async def connect_atv(loop, identifier, airplay_credentials):
|
|||||||
async def loop_atv(event_loop, atv_config, apikey, categories):
|
async def loop_atv(event_loop, atv_config, apikey, categories):
|
||||||
identifier = atv_config["identifier"]
|
identifier = atv_config["identifier"]
|
||||||
airplay_credentials = atv_config["airplay_credentials"]
|
airplay_credentials = atv_config["airplay_credentials"]
|
||||||
global atv
|
|
||||||
atv = await connect_atv(event_loop, identifier, airplay_credentials)
|
atv = await connect_atv(event_loop, identifier, airplay_credentials)
|
||||||
|
|
||||||
|
|
||||||
@@ -132,7 +123,7 @@ async def loop_atv(event_loop, atv_config, apikey, categories):
|
|||||||
try:
|
try:
|
||||||
atv.push_updater.listener = listener
|
atv.push_updater.listener = listener
|
||||||
atv.push_updater.start()
|
atv.push_updater.start()
|
||||||
#print("Press ENTER to quit")
|
print("Push updater started")
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(1000)
|
await asyncio.sleep(1000)
|
||||||
#await event_loop.run_in_executor(None, sys.stdin.readline)
|
#await event_loop.run_in_executor(None, sys.stdin.readline)
|
||||||
@@ -142,10 +133,16 @@ async def loop_atv(event_loop, atv_config, apikey, categories):
|
|||||||
def load_config(config_file="config.json"):
|
def load_config(config_file="config.json"):
|
||||||
with open(config_file) as f:
|
with open(config_file) as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
return config["atvs"][0], config["apikey"], config["skip_categories"]
|
return config["atvs"], config["apikey"], config["skip_categories"]
|
||||||
|
|
||||||
|
def start_async():
|
||||||
|
loop = asyncio.get_event_loop_policy().get_event_loop()
|
||||||
|
asyncio.set_event_loop(loop)
|
||||||
|
atv_configs, apikey, categories = load_config()
|
||||||
|
for i in atv_configs:
|
||||||
|
loop.create_task(loop_atv(loop, i, apikey, categories))
|
||||||
|
loop.run_forever()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
atv_config, apikey, categories = load_config()
|
|
||||||
event_loop = asyncio.get_event_loop_policy().get_event_loop()
|
|
||||||
print("starting")
|
print("starting")
|
||||||
event_loop.run_until_complete(loop_atv(event_loop, atv_config, apikey, categories))
|
start_async()
|
||||||
|
|||||||
Reference in New Issue
Block a user