Plex API filepath current playback

Hi,

after going through some docs and the help page … but i cant find any hint howto figure this out … the standard

/status/sessions?X-Plex-Token=…

doesnt give any path in return to work with …

may a hint to a decent docor if its even possible with plex ?

thanks ahead

For each item in /status/session’s MediaContainer, it should be available from the Media’s Part via the file attribute:

<MediaContainer size="1">
	<Track addedAt="1705692456" duration="182887" ratingKey="489471" [...]>
		<Media audioChannels="2" audioCodec="flac" bitrate="849" container="flac" [...]>
			<Part container="flac" duration="182887" file="/path/to/file.flac" [...]>
				<Stream [...]/>
				<Stream [...]/>
			</Part>
		</Media>
		[...]
		<User id="1" [...]/>
		<Player [...]/>
	</Track>
</MediaContainer>

Depending on exactly what you’re looking to do, it could be easier to use one of the unofficial wrappers around Plex’s web API, e.g. Python-PlexAPI:

from plexapi.server import PlexServer

server = PlexServer('http://host:port', 'plexToken')
for session in server.sessions():
    print(session.media[0].parts[0].file)

thanks for the hint, i prefered to avoid python as way too massive for such a small task … but looks like a simple curl wont do it.

i ll take a look but i guess i drop plex support here rather as way too much effort for such a simple task, would be just “nice to have” to get a side by side function with the “other” mediaservers for a plugin im writing to fetch simple playbacked item path like this sample

wget -q -O - "http://192.168.1.73:8096/emby/Sessions?api_key=1234567890" | jq '.[] | {NowPlayingItem: .NowPlayingItem.Path} | select(.NowPlayingItem!=null)'

which will simply return the path :wink:

thanks anyway

Something like this should work from the command line:

curl -s -H "Accept: application/json" https://host:port/status/sessions?X-Plex-Token={token} | jq '.MediaContainer.Metadata[]?.Media[].Part[].file'

Edit: It looks like the file might only be included for music tracks. You’d have to grab the key/ratingKey for video items, then grab the file path from /library/metadata/{ratingKey}:

curl -s -H "Accept: application/json" http://host:port/status/sessions?X-Plex-Token=token | \
jq '.MediaContainer.Metadata[]?.key' | \
xargs -I{} sh -c 'curl -s -H "Accept: application/json" http://host:port{}?X-Plex-Token=token | \
jq .MediaContainer.Metadata[].Media[].Part[].file'
1 Like

man, thanks alot !!! works like expected.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.