Jump to content

Trigger a library rescan via cmd line


darkassassin07

Recommended Posts

darkassassin07

Is it possible to trigger a rescan for a specific library or even the whole emby db from windows 7 cmd line?

 

My setup atm is a script (.bat) that triggers on system wake retrieving images from a RaspPI through ftp and drops them in the root of one of my libraries 'camera'.

 

The point here is to have the server wake, grab remote files, then refresh the 'camera' library before it is served to the client that woke the comp (via emby)

 

File transfer only takes 10sec max.

Emby user connecting to asleep server ~30-60sec (from open app to home screen)

 

The files are making it to the filesystem before the user has made it to home, but embys filesystem monitoring isnt fast enough to detect and add them befor the client looks for them (unless the client idles for another 10-30sec, what im trying to avoid)

Edited by darkassassin07
Link to comment
Share on other sites

Happy2Play

But in theory depending on your libraries that could be to much scanning.

 

Is your script for a specific time?  You can set a trigger for aroung that same time.

Link to comment
Share on other sites

darkassassin07

That event triggers the whole library scan and isnt reliably immediately after the file transfer.

 

If I can trigger from cmd line or similar I can have it run at the end of the original script consistently triggering it immediately after the file transfer.

 

 

My script triggers on sys wake. (task scheduler: Microsoft-

Windows-Power-Troubleshooter event ID 1)

Link to comment
Share on other sites

Happy2Play

As far as I know there are no commandline options.  You would have to use the api, I believe.

Link to comment
Share on other sites

darkassassin07

So how would I go about triggering individual library scans through the api/curl?

 

I took a look at some of the api info a little while ago, but im quite lost there. Im not familiar with using apis in general :/

 

Im not even sure where to look really

Link to comment
Share on other sites

mastrmind11

So how would I go about triggering individual library scans through the api/curl?

 

I took a look at some of the api info a little while ago, but im quite lost there. Im not familiar with using apis in general :/

 

Im not even sure where to look really

Find a curl binary for Windows and use this command:

curl --data '' http://localhost:8096/Emby/Library/Refresh?api_key=XXXX

where the api_key is one you set up under Expert - Advanced - Security

 

edit: This refreshes all libraries.  Let me check the api doc for a specific library.

 

edit2:  Ok,  I think I figured out the command.  You'll have to open Developer Tools in Chrome and do a rescan on your library of choice.  From the request that gets posted (you'll see it in the developer tools window), grab the Item id.  It'll be after Items/ and before /Refresh in the POST.  Once you have that, you can run this command:

curl --data '' "http://localhost:8096/emby/Items/XXXX/Refresh?Recursive=true&api_key=YYYY"

Replace XXXX with the Item id of your library, and YYYY w/ the API Key you created above.  Dont forget the quotes around the URL or the & symbol will break the request.

 

There might be a more elegant way to get the library id, but this is just a quick and dirty.  Hope it helps.

Edited by mastrmind11
Link to comment
Share on other sites

darkassassin07

Thanks for the help @@mastrmind11

 

 

The first command triggers a full library scan as expected, no problems with that at all,

 

however the second command I have run into a wierd bug with it:

I add new media to the 'camera' libraries folder (file system monitoring is disabled in emby) and trigger that cmd, the scan initiates fine and finds the new media, however the new media when viewed through emby has no thumbnail and doesn't display at all when opened in the viewer, giving a black screen.  Manually re-scanning the individual library or the whole db does not fix this, the media must be removed and re-added

59bc6d80e15ca_chrome_20170915_171627.png

 

 

 I ended up copying the parameters from the url displayed in chromes developer tools to make this:

C:\curl\curl.exe --data '' "http://localhost:8096/emby/Items/XXXX/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&ReplaceAllMetadata=false&api_key=YYYY"

this seems to function properly, the script now works perfectly:

 

The server is asleep and there are images buffered on the external ftp server: When a user connects and wakes the server the new images have downloaded and been added to embys db before the user has made it to his home screen.

Edited by darkassassin07
Link to comment
Share on other sites

mastrmind11

Thanks for the help @@mastrmind11

 

 

The first command triggers a full library scan as expected, no problems with that at all,

 

however the second command I have run into a wierd bug with it:

I add new media to the 'camera' libraries folder (file system monitoring is disabled in emby) and trigger that cmd, the scan initiates fine and finds the new media, however the new media when viewed through emby has no thumbnail and doesn't display at all when opened in the viewer, giving a black screen.  Manually re-scanning the individual library or the whole db does not fix this, the media must be removed and re-added

59bc6d80e15ca_chrome_20170915_171627.png

 

 

 I ended up copying the parameters from the url displayed in chromes developer tools to make this:

C:\curl\curl.exe --data '' "http://localhost:8096/emby/Items/XXXX/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&ReplaceAllMetadata=false&api_key=YYYY"

this seems to function properly, the script now works perfectly:

 

The server is asleep and there are images buffered on the external ftp server: When a user connects and wakes the server the new images have downloaded and been added to embys db before the user has made it to his home screen.

Glad you got it working.  Cheers

Link to comment
Share on other sites

  • 6 years later...

Sorry for bumping an old thread, but can you add not only the library, but also a special path in the curl command? I use serveral paths for my series but only one is updated frequently.  No need to rescan the archive folders more then once a week.

Link to comment
Share on other sites

18 minutes ago, b3nZol said:

Sorry for bumping an old thread, but can you add not only the library, but also a special path in the curl command? I use serveral paths for my series but only one is updated frequently.  No need to rescan the archive folders more then once a week.

HI, yes you can use the emby server api to scan specific folders.

Link to comment
Share on other sites

Can you give an example please? API has "no parameters"  for Library/Refresh. The upper example from mastrmind11 with a sample path would be great 🙂

Link to comment
Share on other sites

adminExitium

Check out the /Library/Media/Updated API endpoint for informing Emby of any changes in a particular path so it can scan them.

Link to comment
Share on other sites

  • 2 weeks later...
On 10/2/2023 at 1:52 AM, b3nZol said:

Sorry i am not familiar with API at all, maybe you can just give an example?

 

Link to comment
Share on other sites

Thanks, but i do not want do use API, just a simple curl command.

Quote

C:\curl\curl.exe --data '' "http://localhost:8096/emby/Items/XXXX/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&ReplaceAllMetadata=false&api_key=YYYY"

I just want to add a "PATH=/mnt/bla/blubb" in here, is that possible?

Link to comment
Share on other sites

On 10/16/2023 at 7:38 PM, b3nZol said:

Thanks, but i do not want do use API, just a simple curl command.

I just want to add a "PATH=/mnt/bla/blubb" in here, is that possible?

It's possible for the future, but as of right now there is no such feature.

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...