2014-07-02, 01:13
Anyone have this working on Gotham 13.1? I had it working without Labels after some tinkering with the code on Frodo 12.3 but I lost my code due a HDD dying on me.
I don't know whether the web API has changed since Gotham or whether my new adapted code is completely wrong.
EDIT: My problem was with uTorrent 3.4.2 rather than XBMC and when I changed it and changed the code using the above fix from ragedogg69.
[/quote]
I don't know whether the web API has changed since Gotham or whether my new adapted code is completely wrong.
EDIT: My problem was with uTorrent 3.4.2 rather than XBMC and when I changed it and changed the code using the above fix from ragedogg69.
PHP Code:
'xbmc.vbs
'Script for updating xbmc library upon torrent completion, and showing notification on download.
'Largly stolen and adapted from http://forum.xbmc.org/showthread.php?t=87472
'
'In uTorrent, Options > Preferences > Advanced > Run Program : Add the following
'When a Torrent Finishes: "C:\path\to\xbmc.vbs" -U "%N" "%D"
'When a Torrent Changes State: "C:\path\to\xbmc.vbs" -S "%M" "%N"
'
'===============================================================================?==
'Declaration section
Dim objSvrHTTP
Dim connectionString 'string to send to xbmc
Dim xbmcConnection 'xbmc connection details, defined in Settings Section
Dim message ' contains name of torrent when sending status message to xbmc
Dim myPath ' path of download in utorrent as provided via %D.
Set objSvrHTTP = CreateObject("MSXML2.XMLHTTP")
On Error Resume Next
'===============================================================================?==
'Settings Section
'edit these lines to work with your setup
xbmcConnection = "http://xbmc:[email protected]:80/jsonrpc?request=" ' This connection is the one that will perform library updates.
'===============================================================================?===
'Implementation Section
'if the first argument is -U (for update) then it performs the update procedure and sends a notification to xbmc.
if WScript.Arguments.Item(0) = "-U" then
'Send a command to xbmc to display a notification when a torrent finishes
myPath = WScript.Arguments.Item(2)
if Left(myPath,2) = "\\" then
myPath = Replace(myPath,"\\","smb://") 'This line makes network paths friendly for xbmc
myPath = Replace(myPath,"\","/") 'This line also makes network paths friendly for xbmc
ElseIf Mid(myPath,2,2) = ":\" then
myPath = Replace(myPath,"\","\\")
End If
JSONstring = URLEncode(Replace("{''jsonrpc'':''2.0'',''method'':''GUI.ShowNotification'',''params'':{''title'':''uTorrent'',''message'':''Finished downloading " & WScript.Arguments.Item(1) & "''},''id'':1}","''",Chr(34)))
connectionString = xbmcConnection & JSONstring
objSvrHTTP.open "GET", connectionString, False
objSvrHTTP.send
'Send a command to xbmc that tells it to update the supplied directory
JSONstring = URLEncode(Replace("{''jsonrpc'':''2.0'',''method'':''VideoLibrary.Scan'',''id'':1}","''",Chr(34)))
connectionString = xbmcConnection & JSONstring
WScript.Sleep 1000 * 10
objSvrHTTP.open "GET", connectionString, False
objSvrHTTP.send
'if the first argument is -S (for status) then it performs the status procedure and in this case only when the status is "Downloading".
'That way I get a notification in xbmc when a new torrent is added
elseif WScript.Arguments.Item(0) = "-S" then
'check if the status is Downloading
if WScript.Arguments.Item(1) = "Downloading" then
message = WScript.Arguments.Item(2)
JSONstring = URLEncode(Replace("{''jsonrpc'':''2.0'',''method'':''GUI.ShowNotification'',''params'':{''title'':''uTorrent'',''message'':''Downloading: " & message & "''},''id'':1}","''",Chr(34)))
connectionString = xbmcConnection & JSONstring
objSvrHTTP.open "GET", connectionString, False
objSvrHTTP.send
end if
end If
Function URLEncode(ByVal str)
Dim strTemp, strChar
Dim intPos, intASCII
strTemp = ""
strChar = ""
For intPos = 1 To Len(str)
intASCII = Asc(Mid(str, intPos, 1))
If intASCII = 32 Then
strTemp = strTemp & "+"
ElseIf ((intASCII < 123) And (intASCII > 96)) Then
strTemp = strTemp & Chr(intASCII)
ElseIf ((intASCII < 91) And (intASCII > 64)) Then
strTemp = strTemp & Chr(intASCII)
ElseIf ((intASCII < 58) And (intASCII > 47)) Then
strTemp = strTemp & Chr(intASCII)
Else
strChar = Trim(Hex(intASCII))
If intASCII < 16 Then
strTemp = strTemp & "%0" & strChar
Else
strTemp = strTemp & "%" & strChar
End If
End If
Next
URLEncode = strTemp
End Function