42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
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
|