FAQ  •  Register  •  Login

Using CURL to force library refresh

<<

phardwick

Serviio newbie

Posts: 18

Joined: Tue Dec 21, 2010 3:42 am

Post Tue Jan 25, 2011 6:02 pm

Using CURL to force library refresh

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

J038lack

Serviio newbie

Posts: 12

Joined: Mon Jul 19, 2010 4:05 am

Post Mon Mar 28, 2011 3:58 am

Re: Using CURL to force library refresh

This works perfectly as a post-processing script for SABnzdb+

Thanks
J03
<<

Xmantium

User avatar

DLNA master

Posts: 1418

Joined: Sat Jul 23, 2011 2:12 pm

Location: Manchester, UK

Post Wed Jul 27, 2011 11:00 pm

Re: Using CURL to force library refresh

I use sabnzbd too, please can you tell me how you made this script work on your sab?
Sony Bravia 2010 52NX803 - Sony PS3 - Xbox 360
Serviio running on QNAP NAS 639 Pro - 1.6 Intel Dual Core - 2GB RAM and QNAP NAS 121 - 2Ghz ARM Marvell - 1GB RAM
Console using ServiiDroid for Android, ServiiMetro and ServiiWP for Windows Phone and WebUI for iOS
<<

J038lack

Serviio newbie

Posts: 12

Joined: Mon Jul 19, 2010 4:05 am

Post Sat Aug 13, 2011 7:08 am

Re: Using CURL to force library refresh

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

Xmantium

User avatar

DLNA master

Posts: 1418

Joined: Sat Jul 23, 2011 2:12 pm

Location: Manchester, UK

Post Sat Aug 13, 2011 2:00 pm

Re: Using CURL to force library refresh

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
Sony Bravia 2010 52NX803 - Sony PS3 - Xbox 360
Serviio running on QNAP NAS 639 Pro - 1.6 Intel Dual Core - 2GB RAM and QNAP NAS 121 - 2Ghz ARM Marvell - 1GB RAM
Console using ServiiDroid for Android, ServiiMetro and ServiiWP for Windows Phone and WebUI for iOS
<<

J038lack

Serviio newbie

Posts: 12

Joined: Mon Jul 19, 2010 4:05 am

Post Sun Aug 14, 2011 4:50 am

Re: Using CURL to force library refresh

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

Xmantium

User avatar

DLNA master

Posts: 1418

Joined: Sat Jul 23, 2011 2:12 pm

Location: Manchester, UK

Post Sun Aug 14, 2011 2:02 pm

Re: Using CURL to force library refresh

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 :?
Sony Bravia 2010 52NX803 - Sony PS3 - Xbox 360
Serviio running on QNAP NAS 639 Pro - 1.6 Intel Dual Core - 2GB RAM and QNAP NAS 121 - 2Ghz ARM Marvell - 1GB RAM
Console using ServiiDroid for Android, ServiiMetro and ServiiWP for Windows Phone and WebUI for iOS
<<

J038lack

Serviio newbie

Posts: 12

Joined: Mon Jul 19, 2010 4:05 am

Post Sun Aug 14, 2011 6:15 pm

Re: Using CURL to force library refresh

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

Xmantium

User avatar

DLNA master

Posts: 1418

Joined: Sat Jul 23, 2011 2:12 pm

Location: Manchester, UK

Post Mon Aug 15, 2011 12:11 am

Re: Using CURL to force library refresh

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
Sony Bravia 2010 52NX803 - Sony PS3 - Xbox 360
Serviio running on QNAP NAS 639 Pro - 1.6 Intel Dual Core - 2GB RAM and QNAP NAS 121 - 2Ghz ARM Marvell - 1GB RAM
Console using ServiiDroid for Android, ServiiMetro and ServiiWP for Windows Phone and WebUI for iOS
<<

J038lack

Serviio newbie

Posts: 12

Joined: Mon Jul 19, 2010 4:05 am

Post Mon Aug 15, 2011 3:19 am

Re: Using CURL to force library refresh

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

Xmantium

User avatar

DLNA master

Posts: 1418

Joined: Sat Jul 23, 2011 2:12 pm

Location: Manchester, UK

Post Mon Aug 15, 2011 6:11 pm

Re: Using CURL to force library refresh

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...
Sony Bravia 2010 52NX803 - Sony PS3 - Xbox 360
Serviio running on QNAP NAS 639 Pro - 1.6 Intel Dual Core - 2GB RAM and QNAP NAS 121 - 2Ghz ARM Marvell - 1GB RAM
Console using ServiiDroid for Android, ServiiMetro and ServiiWP for Windows Phone and WebUI for iOS
<<

J038lack

Serviio newbie

Posts: 12

Joined: Mon Jul 19, 2010 4:05 am

Post Thu Aug 18, 2011 3:57 pm

Re: Using CURL to force library refresh

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

Xmantium

User avatar

DLNA master

Posts: 1418

Joined: Sat Jul 23, 2011 2:12 pm

Location: Manchester, UK

Post Thu Aug 18, 2011 5:46 pm

Re: Using CURL to force library refresh

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
Sony Bravia 2010 52NX803 - Sony PS3 - Xbox 360
Serviio running on QNAP NAS 639 Pro - 1.6 Intel Dual Core - 2GB RAM and QNAP NAS 121 - 2Ghz ARM Marvell - 1GB RAM
Console using ServiiDroid for Android, ServiiMetro and ServiiWP for Windows Phone and WebUI for iOS
<<

J038lack

Serviio newbie

Posts: 12

Joined: Mon Jul 19, 2010 4:05 am

Post Thu Aug 18, 2011 8:18 pm

Re: Using CURL to force library refresh

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

Xmantium

User avatar

DLNA master

Posts: 1418

Joined: Sat Jul 23, 2011 2:12 pm

Location: Manchester, UK

Post Mon Sep 26, 2011 9:00 pm

Re: Using CURL to force library refresh

When i updated to 0.6, the script no longer works! :?

Has the ports changed to update library!?
Sony Bravia 2010 52NX803 - Sony PS3 - Xbox 360
Serviio running on QNAP NAS 639 Pro - 1.6 Intel Dual Core - 2GB RAM and QNAP NAS 121 - 2Ghz ARM Marvell - 1GB RAM
Console using ServiiDroid for Android, ServiiMetro and ServiiWP for Windows Phone and WebUI for iOS
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 16802

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Mon Sep 26, 2011 10:03 pm

Re: Using CURL to force library refresh

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

Xmantium

User avatar

DLNA master

Posts: 1418

Joined: Sat Jul 23, 2011 2:12 pm

Location: Manchester, UK

Post Mon Sep 26, 2011 10:27 pm

Re: Using CURL to force library refresh

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
Sony Bravia 2010 52NX803 - Sony PS3 - Xbox 360
Serviio running on QNAP NAS 639 Pro - 1.6 Intel Dual Core - 2GB RAM and QNAP NAS 121 - 2Ghz ARM Marvell - 1GB RAM
Console using ServiiDroid for Android, ServiiMetro and ServiiWP for Windows Phone and WebUI for iOS
<<

Cerberus

User avatar

DLNA master

Posts: 4116

Joined: Sun Jan 02, 2011 5:20 pm

Location: Reading, UK

Post Mon Sep 26, 2011 10:44 pm

Re: Using CURL to force library refresh

check ip is still correct.
Phil Bennett
Beta Tester Group
Wiki | FAQ

Samsung LE40C750 LCD | Samsung BD-C5900 | Sony PS3 | Windows 7 |
HowTo: Provide supported formats of a device HowTo: Record a new ticket on Bitbucket
HowTo: Provide details of a video file that doesn't play HowTo: Turn on detailed logging
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 16802

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Mon Sep 26, 2011 10:50 pm

Re: Using CURL to force library refresh

does it get throught to the server, ie is the library updated?
<<

Xmantium

User avatar

DLNA master

Posts: 1418

Joined: Sat Jul 23, 2011 2:12 pm

Location: Manchester, UK

Post Tue Sep 27, 2011 6:22 am

Re: Using CURL to force library refresh

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
Sony Bravia 2010 52NX803 - Sony PS3 - Xbox 360
Serviio running on QNAP NAS 639 Pro - 1.6 Intel Dual Core - 2GB RAM and QNAP NAS 121 - 2Ghz ARM Marvell - 1GB RAM
Console using ServiiDroid for Android, ServiiMetro and ServiiWP for Windows Phone and WebUI for iOS
Next

Return to Third-party tools integration

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.