Skip to content

Instantly share code, notes, and snippets.

@SubhrajitPrusty
Created July 31, 2022 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SubhrajitPrusty/8af5f326603d07d0da606f14ecb2e957 to your computer and use it in GitHub Desktop.
Save SubhrajitPrusty/8af5f326603d07d0da606f14ecb2e957 to your computer and use it in GitHub Desktop.
Set now-playing details from Kodi as Discord status
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)
@SubhrajitPrusty
Copy link
Author

Just go here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment