Jump to content

Initiate library scan via command line or URL?


kjp4756

Recommended Posts

kjp4756

I'm currently using plex in a jail on freenas 9.3.  Plex doesn't support auto updating the library on freebsd so I have came up with a work around.  From what I can tell, mediabrowser server on freebsd has the same issue; no library auto scan on freebsd.

 

I use a program called fswatch to monitor my media directory.  When there is a change detected in the filesystem, I use wget to hit a URL on my plex server to initiate the update.  Is there a similar thing I can do with mediabrowser?  The ideal way would be initiate a scan via a shell program.

 

Thanks

Link to comment
Share on other sites

Look at the API documentation.  There is a call to start a library scan but you will need to authorize it by creating a key in the server and then providing that in your url.

Link to comment
Share on other sites

kjp4756

Thanks I did eventually find it in the API documentation last night.  I didn't know about needing an API key.  

 

I do have a bit of a problem now.  I can't seem to find the api documentation link on the server admin page.  I found it yesterday but now I can't today.  Can someone refresh my memory on where to find the api documentation?  I went through every section and its nowhere to be found.

 

Thanks.

Link to comment
Share on other sites

kjp4756

I think I need to authenticate a user first.  I created a hidden user called scanmedia.  I gave the user admin access and a password.

 

I try to authenticate like this:

 

 

curl -X POST -d '{"Password":"Pass1Word"}' -H "Content-Type:application/json" http://localhost:8096/mediabrowser/Users/ffa46d82a7bc896bdef22b85d5ad14c7/Authenticate?api_key=986c63e561b9489f8d3042b57e898161

 

I get a response with "Invalid username or password".  

Link to comment
Share on other sites

kjp4756

Thanks.  I figured it was hashed some how.  MD5 didn't work.  Didn't think of sha1.  Going the authentication route is probably going to be over my head.  I'm trying to get this to work from a shell script.

 

I am able to initiate a library scan if I use the api key for my admin account's web dashboard.  That seems to work until I log out of the web ui.

 

UPDATE:

I am able to authenticate using an SHA1 hash of the password.  Once I authenticated I was issues a new api_key.  That's not what I want.  I want to be able to use the api key I manually generated to update the library.  There should be an option some where to grant certain rights to certain api keys.

Edited by kjp4756
Link to comment
Share on other sites

  • 7 months later...

Here is how I initiate a library scan using curl via  a bash script.  It's kind of messy but it works for me.  I use it with the file system monitor fswatch to initiate a scan.  I put everything in to variables so it's easier to set the configuration options.  I have a hidden emby user called scanmedia which this script uses.  Deviceid is a UUID generated with uuidgen.  The password is a blank password.  The API requires sha1 encoded passwords.  The value I have for password is the sha1 value of a blank password.

 

I also have an init script used to start and daemonize the script.  I can pose that if there is interest.  

 

Here is the main script.

 

 

#!/usr/local/bin/bash
 
PATH="$PATH:/usr/local/bin"
 
TriggeredDelay=180
MediaLocation="/media/Movies /media/TV"
 
client="scanmedia"
device="localhost"
deviceid="86B59261BCC841C3BB74A24C802E27FD"
userid="ffa46d82a7bc896bdef22b85d5ad14c7"
username="scanmedia"
password="da39a3ee5e6b4b0d3255bfef95601890afd80709"
 
while :; do
  fswatch --print0 --one-event --recursive $MediaLocation | while read -d '' event; do
    sleep $TriggeredDelay
 
    ApiKey="$(curl -s -H "Authorization: MediaBrowser Client=$client, Device=$device, DeviceId=$deviceid, Version=1.0.0.0, UserId=$userid" -d "username=$username" -d "password=$password" 'http://127.0.0.1:8096/users/authenticatebyname?format=json' | python -m json.tool | grep 'AccessToken' | sed 's/\"//g; s/AccessToken://g; s/\,//g; s/ //g')"
 
    curl -d 'StartScheduledTask' "http://localhost:8096/mediabrowser/ScheduledTasks/Running/2d67d886717cdade18d9640d4ebbb9cb?api_key=$ApiKey"
  done
done
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...