Update main to support docker and fix docker image url

This commit is contained in:
dmunozv04
2022-02-21 23:44:25 +01:00
parent 939084751a
commit 8edccc2dc3
2 changed files with 18 additions and 5 deletions

19
main.py
View File

@@ -4,6 +4,15 @@ import pyatv
import aiohttp import aiohttp
from cache import AsyncTTL from cache import AsyncTTL
import json import json
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):
@@ -28,6 +37,7 @@ class MyPushListener(pyatv.interface.PushListener):
self.app = atv.metadata.app self.app = atv.metadata.app
self.web_session = aiohttp.ClientSession() self.web_session = aiohttp.ClientSession()
self.categories = categories self.categories = categories
self.atv = atv
def playstatus_update(self, updater, playstatus): def playstatus_update(self, updater, playstatus):
@@ -36,12 +46,12 @@ class MyPushListener(pyatv.interface.PushListener):
except: except:
pass pass
self.task = asyncio.create_task(process_playstatus(playstatus, self.apikey, self.rc, self.app, self.web_session, self.categories)) self.task = asyncio.create_task(process_playstatus(playstatus, self.apikey, self.rc, self.app, self.web_session, self.categories))
def playstatus_error(self, updater, exception): def playstatus_error(self, updater, exception):
print(exception) print(exception)
print("stopped") print("stopped")
# Error in exception # Error in exception
async def process_playstatus(playstatus, apikey, rc, app, web_session, categories): async def process_playstatus(playstatus, apikey, rc, app, web_session, categories):
if playstatus.device_state == playstatus.device_state.Playing and app.identifier == "com.google.ios.youtube": if playstatus.device_state == playstatus.device_state.Playing and app.identifier == "com.google.ios.youtube":
vid_id = await get_vid_id(playstatus.title, playstatus.artist, apikey, web_session) vid_id = await get_vid_id(playstatus.title, playstatus.artist, apikey, web_session)
@@ -113,6 +123,7 @@ 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)
@@ -120,8 +131,10 @@ 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("Press ENTER to quit")
await event_loop.run_in_executor(None, sys.stdin.readline) while True:
await asyncio.sleep(1000)
#await event_loop.run_in_executor(None, sys.stdin.readline)
except: except:
atv.close() atv.close()

View File

@@ -19,13 +19,13 @@ Get [YouTube api key](https://developers.google.com/youtube/registering_an_appl
Edit config.json.template and save it as config.json (this is the /PATH_TO_YOUR_CONFIG.json file) Edit config.json.template and save it as config.json (this is the /PATH_TO_YOUR_CONFIG.json file)
## Run ## Run
```sh ```sh
docker pull ghcr.io/dmunozv04/iSponsorBlockTV/isponsorblocktv docker pull ghcr.io/dmunozv04/isponsorblocktv
docker run -d \ docker run -d \
--name iSponsorBlockTV \ --name iSponsorBlockTV \
--restart=unless-stopped \ --restart=unless-stopped \
--network=host \ --network=host \
-v /PATH_TO_YOUR_CONFIG.json:/app/config.json \ -v /PATH_TO_YOUR_CONFIG.json:/app/config.json \
ghcr.io/dmunozv04/iSponsorBlockTV/isponsorblocktv ghcr.io/dmunozv04/isponsorblocktv
``` ```
### From source ### From source