add jellyfin part

This commit is contained in:
2025-12-09 19:57:22 +01:00
parent 46c47fc6e7
commit 81a3981d18
6 changed files with 57 additions and 13 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.env
__pycache__/
.venv

41
jellyfin.py Normal file
View File

@@ -0,0 +1,41 @@
from jellyfin_apiclient_python import JellyfinClient
from getmac import get_mac_address
import os
def get_client():
server_address = os.getenv('JELLYFIN_ADDRESS')
username = os.getenv('JELLYFIN_USER')
password = os.getenv('JELLYFIN_PASSWORD')
host_mac = get_mac_address(hostname="localhost")
client = JellyfinClient()
client.config.app('jellydisc', '0.0.1', os.uname().nodename, host_mac)
client.config.data['auth.ssl'] = True
client.auth.connect_to_address(server_address)
client.auth.login(server_address, username, password)
return client
def get_active_media(client):
server_address = os.getenv('JELLYFIN_ADDRESS')
sessions = client.jellyfin.get_sessions()
active_media = []
for session in sessions:
media = session.get('NowPlayingItem')
if not media:
continue
media_id = media.get('Id')
image = f"{server_address}/Items/{media_id}/Images/Primary?maxWidth=300&maxHeight=300"
media_info = {
'artist': media.get('AlbumArtist', 'Unknown Artist'),
'title': media.get('Name', 'Unknown Title'),
'image': image,
}
active_media.append(media_info)
return active_media

View File

@@ -1 +0,0 @@
console.log("Hello, TypeScript with .mts extension!");

9
main.py Normal file
View File

@@ -0,0 +1,9 @@
from dotenv import load_dotenv
from jellyfin import get_client, get_active_media
load_dotenv()
client = get_client()
media_list = get_active_media(client)
print(media_list)

View File

@@ -1,12 +0,0 @@
{
"name": "jellydisc",
"version": "1.0.0",
"description": "Discord Presence for Jellyfin",
"scripts": {
"start": "node --experimental-strip-types main.mts"
},
"keywords": [],
"author": "Zvonimir Rudinski <zvonimir@zvonimir.xyz>",
"license": "ISC",
"packageManager": "pnpm@10.13.1"
}

4
requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
jellyfin-apiclient-python==1.11.0
python-dotenv==1.2.1
getmac==0.9.5
pypresence==4.6.1