I’m writing a script to interact with PMS. My first task is to go thru the list of libraries that I want to inspect - eg pms --list - and get the library id for use later in the script.
when I run pms --list, I get a list like:
$./Plex\ Media\ Scanner --list
11: Audio Books
1: Movies
4: Music
3: Other Videos
10: Photos
6: Stage
5: TV Shows
But if I pipe that to grep Movies I get nothing. After a bit of digging, I find that only the first entry makes it thru my pipe grep command. Same result with sed and cat, only the first entry comes thru ala:
$./Plex\ Media\ Scanner --list | cat
11: Audio Books
$
Piping to a hexdump, it seems to end a new line - 0a - just like a text file would. (speaking of test files, redirecting to a file has the same problem, on entry and then nothing.
Any idea why PMS cannot handle this and is my only option to go direct to the sqllite3 db?
I don’t have an answer for why Plex Media Scanner doesn’t play nice with grep and other tools, but you’re probably better off using the web API instead of Plex Media Scanner (which seems to be regularly deprecating things like scanning/refreshing items in favor of the web api).
Sticking to the commandline, you could combine curl and jq to something like the following to get the id of the library titled “Movies” (replacing {your_token} with your auth token):
Thanks @ChuckPa and @DTR after looking at both options, it looks like direct to db is the better option - the web api has fairly different json schemas for different library formats (music and tv libs have different data returned than movies).
I was planning to us this to loop thru different library and build a snapshot of content history that I could track over time… It looks like just pull the file column from the media_parts table gets everything in one shot, which doesn’t really mess me up from my original idea that assumed I’d handle one library at a time.
I fiddled that that a year or so ago, never felt like I got it to do anything useful. Maybe I should look again, my goal back then was to get a consolidated view of the use of 2 different plex servers.
for this job, I’m just being a bash nerd - I was thinking to send myself a daily diff report, maybe an alert if something goes missing - which I’m sure has happened and I just don’t know why.