taiga icon indicating copy to clipboard operation
taiga copied to clipboard

Plex Media Player support

Open moyitpro opened this issue 9 years ago • 32 comments

I have had a working Plex Theater support by using the HTTP API since it uses the same JSON RPC APIs as Kodi. All you need to do is send a post request with the following JSON input to http://localhost:3005/jsonrpc (assuming that Plex Theater runs on the same machine as Taiga)

{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "season", "episode", "showtitle", "tvshowid", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 1 }, "id": "VideoGetItem"} 

which will output:

{"id":"VideoGetItem","jsonrpc":"2.0","result":{"item":{"episode":-1,"fanart":"image://plexserver%3a%2f%2f58f0fbe03917dc575e3606c5cd6bf0e3f8d930b8%2fphoto%2f%3a%2ftranscode%3fheight%3d2048%26url%3dhttp%253a%252f%252f127.0.0.1%253a32400%252flibrary%252fmetadata%252f1%252fart%252f1427826594%26width%3d2048/","file":"C:\\Users\\admin\\Videos\\[Chibiki] THE iDOLM@STER Cinderella Girls - 07 [720p][A6C9D7AE].mkv","id":15,"label":"The Idolm@ster Cinderella Girls 07","season":-1,"showtitle":"","streamdetails":{"audio":[],"subtitle":[],"video":[]},"thumbnail":"image://plexserver%3a%2f%2f58f0fbe03917dc575e3606c5cd6bf0e3f8d930b8%2fphoto%2f%3a%2ftranscode%3fheight%3d720%26url%3dhttp%253a%252f%252f127.0.0.1%253a32400%252flibrary%252fmetadata%252f1%252fthumb%252f1427826594%26width%3d720/","title":"","tvshowid":-1,"type":"unknown"}}}

All you need to do is get the filename from the JSON output and parse the file name, which shouldn't be too difficult.

moyitpro avatar May 05 '15 01:05 moyitpro

Since this is low-priority, we might as well wait for Plex Media Player to replace Plex Home Theater.

erengy avatar Jan 13 '16 02:01 erengy

Is there something that can be added media.xml for a temp solution until it is fully implemented into the application?

pascalo7 avatar Apr 20 '17 22:04 pascalo7

I've noticed that trackma (https://github.com/z411/trackma) is able to track anime watched through Plex. It seems to get the information through http://ip:port/status/sessions Would it be possible for taiga to use 'grandparentTitle' to recognize the series and 'index' to recognize the episode number? Sorry if this has been asked before.

NaruZosa avatar Jul 07 '17 07:07 NaruZosa

if it reads from http://IP:32400/web/index.html#!/status/playing how does it know what user to track? is there somewhere in a config file that allows you to set it to only read for one user? or is it a enter plex credentials thing?

pascalo7 avatar Jul 07 '17 21:07 pascalo7

Trackma asks for 'myPlex login' in setting, and in http://ip:port/status/sessions it has 'title="Username"', as I'm the only person that uses my Plex server currently, I can't confirm whether this is the client username or the server username, but I'd imagine it is the client username. If it isn't, I'm sure there is a way of reading which user is accessing a show, as under status in Plex it has "USERNAME started playing SERIES - EPISODE NAME on DEVICE"

NaruZosa avatar Jul 07 '17 22:07 NaruZosa

I have a working implementation with my detection library, but I haven't implemented it in my applications yet. This should give you a good idea of how it works.

https://github.com/Atelier-Shiori/DetectionKit/commit/41fe15372d84ac012c64a7f2f75ad7a850cab5e2

moyitpro avatar Jul 08 '17 00:07 moyitpro

Sorry for bothering you, but I was wondering if there's been any progress, as this hasn't been mentioned in several months. Thank you for everything you do!

NaruZosa avatar Jan 19 '18 03:01 NaruZosa

^ I'd also like to throw in my support for this to be possible. I only watch my anime through Plex now (hosted on my Synology NAS but I have another computer in the network that's on 24/7) and the ability to update my watched anime automatically on MAL would be really handy! Fingers crossed this can be done.

Oshinigami avatar Jan 19 '18 12:01 Oshinigami

Any new info on this? @erengy

robflop avatar May 04 '18 14:05 robflop

While it's not nearly as good as Taiga support for Plex, I came across this, which adds shows and updates watch count from Plex to MAL and won't lower your watch count if Plex says you've seen less than MAL says. https://github.com/RickDB/PlexMALSync

NaruZosa avatar May 05 '18 09:05 NaruZosa

Any updates on this one? Would really appreciate PLEX detection built in Taiga.

Botanistt avatar Jun 24 '18 13:06 Botanistt

Support for Plex Media Player doesn't even have to really be baked in, just support for plex.tv You can get information from the plex.tv api. Similar to this

KorewaKiyo avatar Jul 14 '18 19:07 KorewaKiyo

Throwing in my support for this!

Soitora avatar Jul 18 '18 23:07 Soitora

Would also love this - I just discovered Taiga, and figured I'd give it a try, since, while PMP wasn't on the supported player list, mpv was, which AFAIK is what PMP uses for core playback/rendering (Emby Theater too, although it has other options as well - only recently moved to Plex). But I guess using mpv as a playback engine doesn't provide the same output necessary for detection as using the full player itself :-/

purposelycryptic avatar Jul 26 '18 20:07 purposelycryptic

~~So, after doing some minor investigation, it would appear, as touched upon by earlier comments, that, when playing any media in Plex Media Player, all the necessary information is available by Plex Media Server at http://SERVER_IP:32400/web/index.html#!/status/playing, which, for most people will simply be `http://localhost:32400/web/index.html#!/status/playing.~~

AFTER FURTHER DIGGING, I found a far cleaner form of all the necessary data (and more) on what is currently playing in PMP is available in XML form here: http://SERVER_IP:32400/status/sessions/?X-Plex-Token=XXXXXXXXXXXXXXXX which for most users is simply: http://localhost:32400/status/sessions/?X-Plex-Token=XXXXXXXXXXXXXXXX

Where the X-Plex-Token is an authentication token that can be easily found using the instructions here.

Here is an example of the XML data returned:

<MediaContainer size="1">
<Video addedAt="1525740768" art="/library/metadata/59824/art/1526071754" chapterSource="media" contentRating="TV-14" duration="1420002" grandparentArt="/library/metadata/59824/art/1526071754" grandparentKey="/library/metadata/59824" grandparentRatingKey="59824" grandparentThumb="/library/metadata/59824/thumb/1526071754" grandparentTitle="Sword Art Online" guid="com.plexapp.agents.hama://anidb-8692/1/21?lang=en" index="21" key="/library/metadata/59846" lastViewedAt="1533929818" librarySectionID="1" librarySectionKey="/library/sections/1" librarySectionTitle="Anime" originallyAvailableAt="2012-11-25" parentIndex="1" parentKey="/library/metadata/59825" parentRatingKey="59825" parentThumb="/library/metadata/59825/thumb/1526071754" parentTitle="Season 1" rating="5.0" ratingKey="59846" sessionKey="64" skipParent="1" summary="Kirito and Leafa reach Arun, the capital of Alfheim, located directly beneath the world tree. However a sudden announcement of an emergency shutdown for server maintenance prompt the two to find a nearby inn and log out. The next day, Suguha accompanies Kirito to visit Asuna at the hospital. Meanwhile, in the World Tree, Asuna stumbles upon a room where experiments are being made with the brains of the other SAO players trapped in ALO. She then attempts to log out of the game by using the GM console inside the room, but is captured by two of Sugou's assistants. However, she manages to snatch a key card before being thrown back to her cell. Back in the real world, Suguha gets heartbroken upon seeing Kazuto tending to Asuna, and is comforted by Kirito after she logs back as Leafa on ALO, still unaware that both him and her brother are the same person. Later as the pair approach the World Tree, Yui suddenly detects Asuna's presence, prompting Kirito to fly ahead leaving Leafa behind. " thumb="/library/metadata/59846/thumb/1526071754" title="The Truth of Alfheim" titleSort="Truth of Alfheim" type="episode" updatedAt="1526071754" viewOffset="1120000" year="2012">
<Media aspectRatio="1.78" audioChannels="2" audioCodec="flac" bitrate="5544" container="mkv" duration="1420002" height="1080" id="71268" videoCodec="h264" videoFrameRate="24p" videoProfile="high 10" videoResolution="1080" width="1920" selected="1">
<Part container="mkv" duration="1420002" file="P:\Media\Anime\Sword Art Online [Coalgirls] [BD, 1080p]\Sword Art Online - 21v2 [Coalgirls] [BD, 1080p, FLAC] [A07A254A].mkv" id="71727" key="/library/parts/71727/1372602011/file.mkv" size="984018401" videoProfile="high 10" decision="directplay" selected="1">
<Stream bitDepth="10" bitrate="5544" chromaLocation="left" chromaSubsampling="4:2:0" codec="h264" default="1" displayTitle="[H264] (日本語)" frameRate="23.976" hasScalingMatrix="0" height="1080" id="198044" index="0" language="日本語" languageCode="jpn" level="51" profile="high 10" refFrames="15" scanType="progressive" streamType="1" title="[H264]" width="1920" location="direct"/>
<Stream audioChannelLayout="stereo" bitDepth="16" channels="2" codec="flac" default="1" displayTitle="[FLAC 2.0] (日本語)" id="198045" index="1" language="日本語" languageCode="jpn" samplingRate="48000" selected="1" streamType="2" title="[FLAC 2.0]" location="direct"/>
<Stream codec="ass" default="1" displayTitle="[ASS] (English)" id="198046" index="2" language="English" languageCode="eng" selected="1" streamType="3" title="[ASS]" decision="ignore"/>
</Part>
</Media>
<Director filter="director=16663" id="16663" tag="Kawakami Tetsuya"/>
<Director filter="director=16487" id="16487" tag="Itou Tomohiko"/>
<Director filter="director=16831" id="16831" tag="Adachi Shingo"/>
<Writer filter="writer=15816" id="15816" tag="Kawahara Reki"/>
<User id="1" thumb="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" title="purposelycryptic"/>
<Player address="127.0.0.1" device="Windows" machineIdentifier="XXXXXXXXXXXXXXXX" model="8.1" platform="Konvergo" platformVersion="XXXXXXXXXXXX" product="Plex Media Player" profile="Konvergo" remotePublicAddress="127.0.0.1" state="paused" title="XXXXXXXXXX" vendor="" version="XXXXXXX" local="0" userID="1"/>
<Session id="XXXXXXXXXXXXXXX" bandwidth="6979" location="lan"/>
</Video>
</MediaContainer>

All of the individual elements can also be directly pulled using the Plex API (Which is unofficially documented here).

But, looking over Taiga's (Or rather, Anisthesia's) code (And, admittedly, I haven't really touched C++ in over a decade), it looks like almost all of the data on media playing comes from either a function of the player process, the process' Window Title or, in the case of a webapp/streaming site, the browser Tab Title.

My understanding is far from perfect, but as far as I can tell, it doesn't appear that any of the existing methods can be readily adapted to read/monitor the XML data this way or use the API. But I could very well be wrong, or, if not, maybe this information may still prove to be of some use regardless. I do hope Taiga will eventually work with Plex Media Player, as it is a great app, but at present I can only use it in conjunction with trackma handling the scrobbling.

purposelycryptic avatar Aug 10 '18 21:08 purposelycryptic

@erengy - Sorry to be a bother, but as this feature request has been around for quite some time, and the last response was in 2016, I was hoping you might be able to give an update on where things currently stand in regard to PMP support.

I completely understand that you may have all sorts of other priorities, and am not trying to get you to change them, just any sort of information would really be great (Is it something you're working on? If yes, how is it coming, if no, do you think you will eventually? Is there a vague time-frame, i.e. "Next Week", or "Probably by 2087", or is it something just floating out there that will likely never get touched?).

Thanks in advance for your time and consideration.

purposelycryptic avatar Aug 18 '18 22:08 purposelycryptic

Again, if you have the server claimed by signing up and logging into plex.tv, the currently playing status can be grabbed from there, so you only have to sign in to your plex account through taiga. As opposed to grabbing token, grabbing ip, making sure the IP is always correct (not everyone uses static local IPs!)

KorewaKiyo avatar Aug 20 '18 11:08 KorewaKiyo

To clarify, this request concerns Anisthesia rather than Taiga itself. Taiga cannot support Plex Media Player until Anisthesia is able to detect it.

looking over Taiga's (Or rather, Anisthesia's) code (...) it doesn't appear that any of the existing methods can be readily adapted to read/monitor the XML data this way or use the API.

This is indeed the case. Anisthesia doesn't have the capabilities to communicate over HTTP, parse JSON/XML documents, etc. C++'s standard library doesn't come with those, embedding them into the library is a bad idea, and I'd rather avoid introducing third-party dependencies... I'll likely end up doing the latter, but that's not possible for the time being.

Is there a vague time-frame, i.e. "Next Week", or "Probably by 2087", or is it something just floating out there that will likely never get touched?

I'm afraid this feature is low-priority at the moment. A vague time-frame would be "probably not this year".

erengy avatar Aug 24 '18 12:08 erengy

That's a shame, but thank you for communicating in detail regarding the support and why it can't be done at the moment.

NaruZosa avatar Aug 24 '18 13:08 NaruZosa

@erengy - Sad to hear it, I really like Taiga's setup. Thanks for letting us know though, it is appreciated - guess I'll check back on Taiga sometime next year.

Edit: Whenever you do decide to look into it, this looks like a good place to start: https://github.com/jgaa/restc-cpp

Edit 2: Also, FYI, Plex also supports webhooks (either natively for Plex Pass holders, or through Tautulli); that might make for a simpler implementation than accessing the API directly.

purposelycryptic avatar Aug 24 '18 14:08 purposelycryptic

@erengy - So, I attempted to create a very basic kind of middleware that would put Plex's play data in a format and location Anisthesia could read, in the form of a self-hosted html page running a script that pulls the data on current Plex activity from the server and puts it in the page header as well as the page itself, but that is as far as I got (this was last October, then I shattered a finger and was forced to spend the rest of the year away from the keyboard).

I haven't had much of a chance to mess with it since (and have been sick with Pneumonia for the last several weeks - no luck lately), but finally got around to at least putting it up on GH today. There's not much to it, if it weren't for the CSS and graphic files, it would literally just be a short HTML file, so if you feel like taking a look, maybe have a better idea for what the output format should be like, you can find it here.

It isn't exactly pretty in its current state (I only had the logo complete before I had to stop), but it be pulling and displaying all the data needed, just not in the way it needs to be. I figured since Taiga can pick up on the Plex Web Interface Player's activity, putting the play activity of the server itself (regardless of whether it is playing to PMP locally, a Roku in the next room, or an Android TV box across the country) on a webpage would make it independent of any player changes, and open up Taiga to a lot of viewing platforms at once, rather than just the current Plex Media Player.

The test screenshots in the readme, for example, are showing play activity from my Android TV box in my bedroom.

purposelycryptic avatar Mar 13 '19 01:03 purposelycryptic

@erengy - So, I attempted to create a very basic kind of middleware that would put Plex's play data in a format and location Anisthesia could read, in the form of a self-hosted html page running a script that pulls the data on current Plex activity from the server and puts it in the page header as well as the page itself, but that is as far as I got (this was last October, then I shattered a finger and was forced to spend the rest of the year away from the keyboard).

I haven't had much of a chance to mess with it since (and have been sick with Pneumonia for the last several weeks - no luck lately), but finally got around to at least putting it up on GH today. There's not much to it, if it weren't for the CSS and graphic files, it would literally just be a short HTML file, so if you feel like taking a look, maybe have a better idea for what the output format should be like, you can find it here.

It isn't exactly pretty in its current state (I only had the logo complete before I had to stop), but it be pulling and displaying all the data needed, just not in the way it needs to be. I figured since Taiga can pick up on the Plex Web Interface Player's activity, putting the play activity of the server itself (regardless of whether it is playing to PMP locally, a Roku in the next room, or an Android TV box across the country) on a webpage would make it independent of any player changes, and open up Taiga to a lot of viewing platforms at once, rather than just the current Plex Media Player.

The test screenshots in the readme, for example, are showing play activity from my Android TV box in my bedroom.

Looks promising, I'll look into if I can improve the output format

Soitora avatar Mar 16 '19 14:03 Soitora

Hachidori has Plex Media Player support. Site | GitHub Hachidori is only for OS X. Don't know if checking their source code would help for Windows tho. Plus in the end Anisthesia is what has to add support for it to be as smooth as the rest.

jacobmix avatar May 13 '19 21:05 jacobmix

Trackma has Plex Media Server support. It's a little wonky with recognition of some types but it's way better than having nothing at all.

Soitora avatar May 13 '19 23:05 Soitora

@jacobmix The detection code is not in the main app, but in a library/framework.

(Plex detection are on Lines 348-472) https://github.com/Atelier-Shiori/DetectionKit/blob/master/DetectionKit/Detection.m

(Plex Auth) https://github.com/Atelier-Shiori/DetectionKit/blob/master/DetectionKit/PlexAuth.m

moyitpro avatar May 14 '19 22:05 moyitpro

Shame that this issue is ongoing for 4 years. Taiga looked really promising too. Guess I'm not going to be using this software since I exclusively watch anime through Plex app on Windows. I do not use the web application since I want hardware decoding. But AniList is user friendly enough, i'm fine keeping things updated myself.

rcdailey avatar Oct 06 '19 01:10 rcdailey

Maybe just add something like: https://github.com/Phineas05/discord-rich-presence-plex But with a user-friendly gui? I'm no code master. But i think enough people have cracked the code for Taiga to be able to have a sound foundation for adding Plex application support.

jacobmix avatar Nov 04 '19 03:11 jacobmix

Are there any updates on this?

SleepingPanda avatar Jul 03 '21 13:07 SleepingPanda

any updates?

StaringLongingly avatar Jul 09 '22 13:07 StaringLongingly

updates for this would be nice ngl, plex desktop app sync would be nice

Omuricee avatar Jul 25 '22 21:07 Omuricee