Jellyfin Forum
Migrating from Plex: How to rewrite this Plex Playlist API Script for Jellyfin - Printable Version

+- Jellyfin Forum (https://forum.jellyfin.org)
+-- Forum: Support (https://forum.jellyfin.org/f-support)
+--- Forum: General Questions (https://forum.jellyfin.org/f-general-questions)
+--- Thread: Migrating from Plex: How to rewrite this Plex Playlist API Script for Jellyfin (/t-migrating-from-plex-how-to-rewrite-this-plex-playlist-api-script-for-jellyfin)



Migrating from Plex: How to rewrite this Plex Playlist API Script for Jellyfin - Exaskryz - 2024-01-09

A few months back on reddit when I was learning about Plex, I had some great help with a script.


https://www.reddit.com/r/PleX/comments/17a5ozb/plex_api_help_how_to_add_to_existing_playlist_or/k5av8kl/

That script that is really get came from a user named SwiftPanda16, finding the script here: https://gist.github.com/JonnyWong16/725edf03749a8e16f5e7e3ae776b544b

I have dozens of TV series I have already watched. Putting all the TV series in a playlist and using a shuffle function is okay, but I don't much like having say the order of items be

ShowA Season 12 Episode 1 > ShowA Season 6 Episode 6 > ShowB Season 4 Ep 11 > ShowA Season 2 Ep 14

I'd like the idea of being able to turn on the playlist and it plays episodes in order, but interlaced between series. So I'd have this ordering instead:

ShowA S1E1 > ShowA S1E2 > ShowB S1E1 > ShowA S1E3

Where if a good multi-episode plotline is developing, I'm not jumping around and interrupted and can follow that in the series, even if a different series plays between those episodes.

Kind of recreating broadcast television, with my own channel.

I'm very new to Jellyfin and will be willing to explore the API in the coming days or weeks depending on my free time to recreate that script for Plex (or even research just making the playlist in Plex and somehow importing it to Jellyfin), but I figured I'd not recreate the wheel if someone knew if this type of functionality already existed. Even better if JF has that in its native playlist functionality, something I haven't touched on yet.


RE: Migrating from Plex: How to rewrite this Plex Playlist API Script for Jellyfin - mcarlton00 - 2024-01-09

You could do this through the api and playlists, however I suspect you might be better served by using ErsatzTV for this instead: https://ersatztv.org/docs/intro


RE: Migrating from Plex: How to rewrite this Plex Playlist API Script for Jellyfin - Exaskryz - 2024-01-09

That does seem kind of cool. I'd be interested in keeping to just one service entirely, plex or jellyfin or ersatztv, but if ersatz handles tv, movies, music all the same as jellyfin, I can go there.

It's not that I'd have it on all the time, that's for sure. Generally the family watches one show over the course of weeks or the occasional movie, but I figured if I just wanted to throw something on the in background, I'd second-purpose the plex or jellyfin for it. For all that it matters, I could do the very same thing in VLC, something I did do a decade and a half ago as I fumbled around with such an idea.

Is there any well documented api for jellyfin in python wrappers?

I am way off base trying to using stuff like jellyfin_api_client because it tells me

Code:
File "/home/linuxpc/Documents/SwiftPandaJELLYFINPlaylist.py", line 37, in main
    tvshows = client.library.section(Library)
AttributeError: 'AuthenticatedClient' object has no attribute 'library'

I kind of understand the original code, because at least that plex api wrapper was pretty nicely documented and I could generally figure out what I needed to import, but I really have the wrong idea on how to use jellyfin api. I may just try to reteach myself terminal/command line api stuff and figure it out in a bash script as I previously did, but as Panda's code was much more efficient and shorter than mine, I really wanted to try to emulate that.


RE: Migrating from Plex: How to rewrite this Plex Playlist API Script for Jellyfin - tmsrxzar - 2024-01-09

(2024-01-09, 08:35 PM)Exaskryz Wrote: That does seem kind of cool. I'd be interested in keeping to just one service entirely, plex or jellyfin or ersatztv, but if ersatz handles tv, movies, music all the same as jellyfin, I can go there.

i think you completely missed what it is, ersatz doesn't do what plex or jellyfin does, it creates a virtual tv channel using your media
that tv channel is then imported into either plex or jellyfin as a psuedo live tv source

https://ersatztv.org/docs/user-guide/configure-clients
https://ersatztv.org/docs/user-guide/configure-clients#jellyfin

it does not replace either plex or jellyfin


RE: Migrating from Plex: How to rewrite this Plex Playlist API Script for Jellyfin - mcarlton00 - 2024-01-09

I will be completely honest with you: the jellyfin-apiclient-python kinda sucks. I maintain 3 python clients and have several scripts I use to interact with my server, and I avoid it where ever possible. It was originally pulled out of the source code of jellyfin-kodi, and there was a whole lot of "not good" about that code. You've already discovered that getting started with it is kinda clunky. Eventually I would like to make a proper one based on the openapi spec published by the server, but refactoring all of my stuff to use it just hasn't been worth the time yet.

If you want to use the apiclient as is, your best options are likely going to be to look through the jellyfin-kodi and jellyfin-mpv-shim repos to figure out how it's being used there. And be warned it's not going to be a concise as the plex python library.

If you want to venture into the unknown a bit, you can generate your own api client using the jellyfin openapi spec found here: https://api.jellyfin.org/openapi/jellyfin-openapi-stable.json

I personally find it easier to just write my own api calls using the requests library.

* This is a snippet I put together ages ago: https://gist.github.com/mcarlton00/f7bd7218828ed465ce0f309cebf9a247
* Here are all the api calls made in the mopidy client: https://github.com/jellyfin/mopidy-jellyfin/blob/master/mopidy_jellyfin/remote.py
* Possibly the most relevant for you, this pulls all songs marked "favorite" from the server and pushes them into a playlist: https://gist.github.com/mcarlton00/c08a6046d67e6c85643162da826e1ac1