Page 1 of 2

Using CURL to force library refresh

PostPosted: Tue Jan 25, 2011 6:02 pm
by phardwick
Quick tip:

I use this to force a library refresh (I'm running on linux):

curl -X POST "http://localhost:23423/rest/action" -H "Content-Type: text/xml" -d "<action><name>forceLibraryRefresh</name></action>"

I plan on putting this into a daily cron job and disabling the auto library refresh.

Re: Using CURL to force library refresh

PostPosted: Mon Mar 28, 2011 3:58 am
by J038lack
This works perfectly as a post-processing script for SABnzdb+

Thanks
J03

Re: Using CURL to force library refresh

PostPosted: Wed Jul 27, 2011 11:00 pm
by Xmantium
I use sabnzbd too, please can you tell me how you made this script work on your sab?

Re: Using CURL to force library refresh

PostPosted: Sat Aug 13, 2011 7:08 am
by J038lack
Xmantium wrote:I use sabnzbd too, please can you tell me how you made this script work on your sab?


Hey Xmantium,

You first install Curl
In windows just copy curl.exe to your system32 dir

Then create a batch file with the above line in it. (A text file saved as a .bat)
Then save in your script folder.
Then go to your category settings and change your (movie/tv/music/picture) category of choice script setting to the new batch file you just created.

I also took this one step further because I didn't like the CMD windowing opening all the time and converted the .bat file to a .exe to lose the black box. I used Bat_To_Exe_Converter.

works great
Hope this helps
J03

Re: Using CURL to force library refresh

PostPosted: Sat Aug 13, 2011 2:00 pm
by Xmantium
I will try this out, this suits the windows version
I've noticed your a very active member in the sabnzbd forum.
Is there a python script that can do the same curl script? I mainly use Serviio on Linux

Re: Using CURL to force library refresh

PostPosted: Sun Aug 14, 2011 4:50 am
by J038lack
Xmantium wrote:I will try this out, this suits the windows version
I've noticed your a very active member in the sabnzbd forum.
Is there a python script that can do the same curl script? I mainly use Serviio on Linux


Hey Xmantium,

Here is a python script that will do the same -

  Code:
import httplib

connection =  httplib.HTTPConnection("localhost",23423)
body_content = '<action><name>forceLibraryRefresh</name></action>'
connection.request('POST', '/rest/action', body_content)
result = connection.getresponse()
#print result.status


I have tested this on python 2.6 windows version, but I don't see anything that would cause any problems in Linux.
If you have a bound IP address change the connection line.

connection = httplib.HTTPConnection('1.2.3.4:23423')


Glad to help
J03

Re: Using CURL to force library refresh

PostPosted: Sun Aug 14, 2011 2:02 pm
by Xmantium
Thanks for this, i copied the code in a text file and renamed it ServiioRefresh.py

Im running my NAS on fixed IP, so my .py has the following script:
  Code:
import httplib

connection =  httplib.HTTPConnection("192.168.1.6",23423)
body_content = '<action><name>forceLibraryRefresh</name></action>'
connection.request('POST', '/rest/action', body_content)
result = connection.getresponse()
#print result.status


It says "Cannot run script /share/MD0_DATA/.qpkg/SickBeard/autoProcessTV/ServiioRefresh.py"
Am i doing something wrong :?

Re: Using CURL to force library refresh

PostPosted: Sun Aug 14, 2011 6:15 pm
by J038lack
Xmantium wrote:Thanks for this, i copied the code in a text file and renamed it ServiioRefresh.py

Im running my NAS on fixed IP, so my .py has the following script:
  Code:
import httplib

connection =  httplib.HTTPConnection("192.168.1.6",23423)
body_content = '<action><name>forceLibraryRefresh</name></action>'
connection.request('POST', '/rest/action', body_content)
result = connection.getresponse()
#print result.status


It says "Cannot run script /share/MD0_DATA/.qpkg/SickBeard/autoProcessTV/ServiioRefresh.py"
Am i doing something wrong :?


Hey Xmantium,
Have you tryed leaving the connection line localhost

connection = httplib.HTTPConnection("localhost",23423)

Im doing some further testing on bound IP address but try localhost.

Also try running the script by itself to test.
To confirm working open your Serviio console and check if your library status changes.

Tell me how it goes.
J03

Re: Using CURL to force library refresh

PostPosted: Mon Aug 15, 2011 12:11 am
by Xmantium
I get the same error still...
i did change the line to - connection = httplib.HTTPConnection('192.168.1.6:23423')

I ran the script by Terminal Putty in WinSCP - # python ServiioRefresh.py
I get no messages...

Then i changed to - connection = httplib.HTTPConnection("localhost",23423)
Still the same message in sab, but putty terminal says
  Code:
[/share/MD0_DATA/Qdownload/sabnzbd/script] # python ServiioRefresh.py
Traceback (most recent call last):
  File "ServiioRefresh.py", line 5, in <module>
    connection.request('POST', '/rest/action', body_content)
  File "/opt/lib/python2.6/httplib.py", line 914, in request
    self._send_request(method, url, body, headers)
  File "/opt/lib/python2.6/httplib.py", line 951, in _send_request
    self.endheaders()
  File "/opt/lib/python2.6/httplib.py", line 908, in endheaders
    self._send_output()
  File "/opt/lib/python2.6/httplib.py", line 780, in _send_output
    self.send(msg)
  File "/opt/lib/python2.6/httplib.py", line 739, in send
    self.connect()
  File "/opt/lib/python2.6/httplib.py", line 720, in connect
    self.timeout)
  File "/opt/lib/python2.6/socket.py", line 561, in create_connection
    raise error, msg
socket.error: [Errno 111] Connection refused

Re: Using CURL to force library refresh

PostPosted: Mon Aug 15, 2011 3:19 am
by J038lack
First setup is getting stuck and will never return results. Wrong IP address

Second setup is an address that doesn't have an REST interface or Serviio running.

Which machine has Serviio running on it ? IP ? PC or NAS?
which machine has Sabnzbd+ running on it ? IP? PC or NAS?

a couple other things you can try is 127.0.0.1 instead of localhost
and also try removing the Port # ("localhost") instead of ("localhost",23423)

These two tips will only work if the Script is run on the same machine that is running Serviio.
If your using Putty then you can remove the # beside the print command in your script and it should return 200 if everything is OK

I will try and setup Serviio with a bound IP address and run the script from another PC on the local network.

You've almost got it
J03

Re: Using CURL to force library refresh

PostPosted: Mon Aug 15, 2011 6:11 pm
by Xmantium
Ive tried all variation using putty to run the python code, the only one that returns 200 is connection = httplib.HTTPConnection('192.168.1.6:23423')
It does refresh my Serviio Library - Hurray!!
[/share/Qdownload/sabnzbd/script] # python ServiioRefresh.py
200

My sabnzbd and serviio is on the same IP on the same NAS server - 192.168.1.6

BUT! - Its not running with sabnzb, sab keeps saying the same error message
Exit(-1) Cannot run script /share/Qdownload/sabnzbd/script/ServiioRefresh.py

Ive check the permission rights of the file, read and execute is enabled, dont know why sab wont run my script...

Re: Using CURL to force library refresh

PostPosted: Thu Aug 18, 2011 3:57 pm
by J038lack
So Here is your problem when you run putty you tell it to run python ServiioRefresh.py. Which tells it to use Python to run the script.
To correct the script so you dont need to tell it what to run it with is to add a line to the top of the script stating the path to where python is

Example.

  Code:
#!/usr/local/bin/python
import httplib
connection = httplib.HTTPConnection('192.168.1.6:23423')
body_content = '<action><name>forceLibraryRefresh</name></action>'
connection.request('POST', '/rest/action', body_content)
result = connection.getresponse()
#print result.status


#!/usr/local/bin/python
With the above line you are specifying the location to the python executable in your machine, that rest of the script needs to be interpreted with.The above line is pointing to python that is located at /usr/local/bin/python this maybe different on your machine find the python executable and use that path.

I think after adding this line you should be able to run the script in putty without the python in front of it. Just type - ServiioRefresh.py

Hope this works
J03

Re: Using CURL to force library refresh

PostPosted: Thu Aug 18, 2011 5:46 pm
by Xmantium
J03 you are a star!! 8-)
Im such an idiot not realising this before, for my NAS linux its #!/usr/bin/env python after checking other .py scripts used by my sab

It works perfect and updates my library, just one little thing i want to change,
Iv added on an extra line print "Updated Serviio Library" but for some reason sab says
Updated Serviio Library (More)
It adds extra break line, is there a better way to printline without the link (more) doesnt appear

Re: Using CURL to force library refresh

PostPosted: Thu Aug 18, 2011 8:18 pm
by J038lack
Xmantium,

Just a little IF else statement will take care of your output,
As I explained earlier the 200 result is the OK command from the REST interface and we can use that to decide if the Update was successful or failed. try the code below.
As for the line break - you can put a , on the end of the print command. take a look below
but this will not stop the (more) link that is created by sabnzbd. It is a log link and it can only be disable by running a output free script or disable logging (which I'm pretty sure can not be done).

  Code:
#!/usr/bin/env python
import httplib
connection = httplib.HTTPConnection('192.168.1.6:23423')
body_content = '<action><name>forceLibraryRefresh</name></action>'
connection.request('POST', '/rest/action', body_content)
result = connection.getresponse()
if result.status == 200:
    print "Updated Serviio Library",
else :
    print "Update Failed",


J03

Re: Using CURL to force library refresh

PostPosted: Mon Sep 26, 2011 9:00 pm
by Xmantium
When i updated to 0.6, the script no longer works! :?

Has the ports changed to update library!?

Re: Using CURL to force library refresh

PostPosted: Mon Sep 26, 2011 10:03 pm
by zip
no, nothing changed. just make sure the REST API still binds to the IP you're expecting (that changed, it now binds automatically to the public IP of the server)

Re: Using CURL to force library refresh

PostPosted: Mon Sep 26, 2011 10:27 pm
by Xmantium
Im a noob to REST, how do i do this to get the script working again?

It should return "200" when the library have been updated, it doesnt return anything now

Re: Using CURL to force library refresh

PostPosted: Mon Sep 26, 2011 10:44 pm
by Cerberus
check ip is still correct.

Re: Using CURL to force library refresh

PostPosted: Mon Sep 26, 2011 10:50 pm
by zip
does it get throught to the server, ie is the library updated?

Re: Using CURL to force library refresh

PostPosted: Tue Sep 27, 2011 6:22 am
by Xmantium
my sabnzbd and serviio are on the same NAS and all same fixed IP - 192.168.1.6
The script is exactly the same as J03Black's last post.

the script is in python, its designed to run after a media file is downloaded in sabnzbd so I don't have to press force refresh to watch media file straight away, the library does not get updated