🎉 Project init
This commit is contained in:
parent
25aed8ce0f
commit
7056e232d7
4 changed files with 112 additions and 2 deletions
31
jellyfin_wol.py
Executable file
31
jellyfin_wol.py
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/python3
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
from urllib.parse import parse_qs
|
||||
from wakeonlan import send_magic_packet
|
||||
import os
|
||||
|
||||
|
||||
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
raw_data = self.rfile.read(content_length).decode('utf-8')
|
||||
post_data = parse_qs(raw_data)
|
||||
|
||||
# Check if the payload indicates a user login event
|
||||
if 'NotificationType' in post_data and 'AuthenticationSuccess' in post_data['NotificationType']:
|
||||
print("User login detected! Waking up NAS.")
|
||||
send_magic_packet('1c:1b:0d:99:5c:48')
|
||||
|
||||
# Send a 200 OK response
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(b'{"status": "success"}')
|
||||
|
||||
|
||||
# Configure and start the HTTP server
|
||||
if __name__ == '__main__':
|
||||
host = os.getenv('LISTEN_ADDRESS', '0.0.0.0')
|
||||
port = int(os.getenv('LISTEN_PORT', 8092))
|
||||
httpd = HTTPServer((host, port), SimpleHTTPRequestHandler)
|
||||
print(f"Listening on {host}:{port}...")
|
||||
httpd.serve_forever()
|
Loading…
Add table
Add a link
Reference in a new issue