Code: Select all
wget: server returned error: HTTP/1.1 415 Unsupported Media TypeCode: Select all
wget: server returned error: HTTP/1.1 415 Unsupported Media Typebumping an old thread here.. the above works great for me in frodo but i'm wondering how hard it would be to modify it to only update a newly downloaded item and not the entire library?CapnBry wrote:You can do this without using python classes with just wget:If you want to see the response, use -O- and add "id": "anything" to the end of the JSON POST data. Tested on Eden 11.0 Beta 1. Also note that my XBMC HTTP server is on port 8000, modify if necessary.Code: Select all
wget -q -O/dev/null --header='Content-Type: application/json' --post-data='{"jsonrpc": "2.0", "method": "VideoLibrary.Scan"}' http://localhost:8000/jsonrpc
Code: Select all
#!/usr/bin/python2.7
import jsonrpclib, thread, time
def xbmcscan():
server = jsonrpclib.Server('http://xbmc:8080/jsonrpc')
if server.VideoLibrary.Scan() == 'OK':
print "Update command sent"
thread.interrupt_main()
else:
print "Update command failed"
try:
thread.start_new_thread(xbmcscan, ())
time.sleep(3)
thread.exit()
except KeyboardInterrupt:
quit()
except SystemExit:
print "Xbmc HTTP API hung up"
quit()
drawde wrote:bumping an old thread here.. the above works great for me in frodo but i'm wondering how hard it would be to modify it to only update a newly downloaded item and not the entire library?CapnBry wrote:You can do this without using python classes with just wget:If you want to see the response, use -O- and add "id": "anything" to the end of the JSON POST data. Tested on Eden 11.0 Beta 1. Also note that my XBMC HTTP server is on port 8000, modify if necessary.Code: Select all
wget -q -O/dev/null --header='Content-Type: application/json' --post-data='{"jsonrpc": "2.0", "method": "VideoLibrary.Scan"}' http://localhost:8000/jsonrpc
Code: Select all
curl -s -H "Content-Type: application/json" -u xbmc:xbmc -X POST -d '{"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "params":{"directory":"nfs://192.168.2.104/export/_TV/*/"}, "id": "scan"}' http://192.168.2.33:8090/jsonrpc
Ashex wrote:Take a look at this function in the sickbeard xbmc notify script. The methods you need are described in there.
Code: Select all
settings = {
'hostname': '127.0.0.1',
'port': '1234',
'username': '',
'password': ''
}
http_address = 'http://%s:%s/jsonrpc' % (settings['hostname'], settings['port'])
username = settings['username']
password = settings['password']
try:
import json
except ImportError:
import simplejson as json
import urllib2, base64
class XBMCJSON:
def __init__(self, server):
self.server = server
self.version = '2.0'
def __call__(self, **kwargs):
method = '.'.join(map(str, self.n))
self.n = []
return XBMCJSON.__dict__['Request'](self, method, kwargs)
def __getattr__(self,name):
if not self.__dict__.has_key('n'):
self.n=[]
self.n.append(name)
return self
def Request(self, method, kwargs):
data = [{}]
data[0]['method'] = method
data[0]['params'] = kwargs
data[0]['jsonrpc'] = self.version
data[0]['id'] = 1
data = json.JSONEncoder().encode(data)
content_length = len(data)
content = {
'Content-Type': 'application/json',
'Content-Length': content_length,
}
request = urllib2.Request(self.server, data, content)
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
f = urllib2.urlopen(request)
response = f.read()
f.close()
response = json.JSONDecoder().decode(response)
try:
return response[0]['result']
except:
return response[0]['error']
xbmc = XBMCJSON(http_address)
xbmc.VideoLibrary.Scan()Code: Select all
echo "curl -s -H \"Content-Type: application/json\" -u xbmc:xbmc -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Scan\", \"params\":{\"directory\":\"nfs://192.168.2.104/export/_TV/show/\"}, \"id\": \"scan\"}' http://192.168.2.33:8090/jsonrpc" | sed 's_show_'"$show"'_g' | sh
Code: Select all
18:17:49 T:2889874240 DEBUG: JSONRPC: Incoming request: {"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "params":{"directory":"nfs://192.168.2.104/export/_TV/$show/"}, "id": "scan"}
18:17:49 T:2889874240 DEBUG: JSONRPC: Calling videolibrary.scan
18:17:49 T:2603612992 NOTICE: Thread CVideoInfoScanner start, auto delete: false
18:17:49 T:2603612992 NOTICE: VideoInfoScanner: Starting scan ..
18:17:49 T:2603612992 DEBUG: CAnnouncementManager - Announcement: OnScanStarted from xbmc
18:17:49 T:2603612992 DEBUG: GOT ANNOUNCEMENT, type: 16, from xbmc, message OnScanStarted
18:17:49 T:2603612992 DEBUG: SECTION:LoadDLL(libnfs.so.1)
18:17:49 T:2603612992 DEBUG: Loading: libnfs.so.1
18:17:49 T:2603612992 DEBUG: NFS: Context for 192.168.2.104/export/_TV not open - get a new context.
18:17:49 T:2603612992 DEBUG: NFS: Connected to server 192.168.2.104 and export /export/_TV
18:17:49 T:2603612992 DEBUG: NFS: chunks: r/w 1048576/32768
18:17:49 T:2603612992 WARNING: Process directory 'nfs://192.168.2.104/export/_TV/$show/' does not exist - skipping scan.
Code: Select all
echo "curl -s -H \"Content-Type: application/json\" -u xbmc:xbmc -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Scan\", \"params\":{\"directory\":\"nfs://192.168.2.104/export/_TV/show/\"}, \"id\": \"scan\"}' http://192.168.2.33:8090/jsonrpc"
Code: Select all
sed 's_show_'"$show"'_g'
Code: Select all
curl -s -H "Content-Type: application/json" -u xbmc:xbmc -X POST -d '{"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "params":{"directory":"nfs://192.168.2.104/export/_TV/American Dad/s05"}, "id": "scan"}' http://192.168.2.33:8090/jsonrpc
Code: Select all
echo "curl -s -H \"Content-Type: application/json\" -u xbmc:xbmc -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Scan\", \"params\":{\"directory\":\"nfs://192.168.2.104/export/_TV/show/\"}, \"id\": \"scan\"}' http://192.168.2.33:8090/jsonrpc" | sed 's_show_'"$show"'_g' | sh