Created
July 31, 2022 19:46
-
-
Save SubhrajitPrusty/8af5f326603d07d0da606f14ecb2e957 to your computer and use it in GitHub Desktop.
Set now-playing details from Kodi as Discord status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import requests | |
from dotenv import load_dotenv | |
from pypresence import Presence | |
load_dotenv() | |
client_id = os.getenv('DISCORD_BOT_ID') | |
RPC = Presence(client_id, pipe=0) | |
RPC.connect() | |
# Get details for now-playing | |
while True: | |
URL = "http://localhost:8080/jsonrpc" | |
payload = { | |
"jsonrpc": "2.0", | |
"method": "Player.GetItem", | |
"params": { | |
"properties": ["title", "thumbnail", "season", "episode", "showtitle"], | |
"playerid": 1 | |
}, | |
"id": "VideoGetItem" | |
} | |
response = requests.post(URL, json=payload) | |
response_json = response.json() | |
details = response_json.get('result', {}).get('item', {}) | |
print(details) | |
state_str = details.get('title', 'Not watching anything') | |
details_str = details.get('showtitle', 'IDLE') | |
ep_info = [details.get('episode', 0), details.get('season', 0)] | |
print(RPC.update(state=state_str, details=details_str, party_size=ep_info)) | |
time.sleep(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just go here