tl;dr,
ive found a solution.
the final command is:
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
[/size]
remember:
you will need to modify the IP, the "directory" parameter, and the XBMC username/pass in the above for this to work for your environment.
------------------------------------
so i found the problem ultimatley was not with the new API code, but using a variable within the header, as it was not processed.
also using 'curl $variable', even if the variable contained the proper arguments didnt work.
so the trick was to make curl's url dynamic, depending on the path to the show, but also, not contain any variables, since it would be passed along to xbmc in its raw form., so how to do this ?
here ive defined the shows relative path, by taking what sab tells me is the full job path.
show=$(echo "$1" | sed 's/\/home\/eric\/Media\/_Downloads\/_TV\///g')
if the shows full path is for example:
/home/eric/Media/_Downloads/_TV/American Dad/s05
we will end up with:
show == American Dad/s05
no this is the tricky part, as i originally was taking the $show variable, and adding it like so:
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
but as ive stated above, $shows will not be expanded; its passed along to xbmc as is, and of course xbmc has no clue what "$show" is, so in the xbmc log we have something like this:
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.
so how can we do this ?
were going to echo the proper json api call, and in place of "$show", were going to have "show".
it looks like this:
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"
but why are we echoing it ?
were going to pipe it to sed, so we can replace "show" with the contents of "$show", and we do it like so:
(note the double quoting; this is important because we want the contents of $show, not $show itself. ---> single quote + double quote
now we have a properly formatted api call to update your library, with the exact episode that was just downloaded. and it looks like this:
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
now we will pipe it to 'sh'.
the final command is:
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