uTorrent update XBMC on completion
#1
I took the script from http://forum.xbmc.org/showthread.php?tid=87472
and modified it to work a little differently.

Main difference being you can have the script only activate via specific labels, as well as the ability to notify multiple XBMC instances when a torrent starts or finishes downloading. It is currently set up for up to 5 instances of XBMC, sharing library via MySQL, and does library updates from one connection.

I included the necessary code for controlling several separate XBMC libraries as well, for those who aren't sharing via MySQL. You'll only need to uncomment some code. Crude instructions are included in the notes section beginning at line 5.

You need to download the VBS file: http://dl.dropbox.com/u/33669449/xbmc.vbs

Read the brief comments section at the top for instructions on how to set it up for your needs. Edit the settings section to match your needs.

I have commented it fairly thoroughly (or so I believe) and it should be easy enough for anyone with minor VBScript experience to edit to their liking.

Finally, in uTorrent, Options > Preferences > Advanced > Run Program add the following lines.

Torrent Finishes:
Code:
"C:\path\to\xbmc.vbs" -U "%N" "%D" "%L"

Changes State:
Code:
"C:\path\to\xbmc.vbs" -S "%M" "%N" "%L"

Quotations around path to vbs are required if you have spaces in the folder path.

Should be set! Feel free to recommend any changes, or help me optimize the code.
Reply
#2
Im trying my best to try this lol. Can I just ask - If I'm only using one instance of XBMC - should I comment out line 51 too? Im hoping Im following this ok.

Thank You.
Reply
#3
Rolica, try this: https://dl.dropbox.com/u/33669449/Rolica/xbmc.vbs

Make sure you set the proper user:[email protected] in the xbmcConnection variable.
You also NEED to set the ulabel0 variable to the label the torrent is under in uTorrent, or else it wont work. Alternatively, you could remove or comment out any ulabel variables, as well as the select case label section (except the ignoreTorrent = "true" part) but this would cause ANY torrents you download to try and be added to your video library.
Reply
#4
oh wow - thank you so much for this. OK, Im off to read through it. I really appreciate your time. (i may be back later tho hehe) Smile
Reply
#5
No problem
Reply
#6
I updated to Frodo, and the previous script I had stopped working. So I downloaded yours, and I followed the directions in the READ THIS section of the script, and commented out the extra lines for multiple instances. I then also changed line 75 to read:

ignoreTorrent = "false"

instead of "true", as this seemed like the simplest way to make it work for ALL labels. When I test run this script from the command prompt with all the correct command line inputs, it gives me the correct notification in XBMC, saying the file has completed download, so I think this indicates it is connecting correctly with the xbmc server, and attempting to run the update script.

However, it just doesn't update the library! Which, of course, is the important part! Any ideas?
Reply
#7
(2013-03-06, 19:01)moeman Wrote: I updated to Frodo, and the previous script I had stopped working. So I downloaded yours, and I followed the directions in the READ THIS section of the script, and commented out the extra lines for multiple instances. I then also changed line 75 to read:

ignoreTorrent = "false"

instead of "true", as this seemed like the simplest way to make it work for ALL labels. When I test run this script from the command prompt with all the correct command line inputs, it gives me the correct notification in XBMC, saying the file has completed download, so I think this indicates it is connecting correctly with the xbmc server, and attempting to run the update script.

However, it just doesn't update the library! Which, of course, is the important part! Any ideas?

Sorry, I'm not at home to test this, but I've removed the entire label system from the code below. Just edit the connection and see if this works. Remember to make sure the relevent directory where utorrent is downloading is a valid share within XBMC and you can play the files from it. Otherwise, it will fail on updating the library. If that doesn't work, please pastebin your xbmc.log file and we'll try and figure it out.

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]:8080/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
    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'',''params'':{''directory'':''"& myPath &"/''},''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
Reply
#8
Thanks for the reply. I don't think the label system was the problem, but I went ahead and used this current script you put together. It now does not do anything when I run the script. Here are the last 2 lines (the apparently relevant ones) from the log:

Code:
16:46:54 T:2252   ERROR: JSONRPC: Failed to parse '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":'?'uTorrent","message":"Finished downloading Conan.2013.03.05.Colin.Farrell.HDTV.x264-BAJSKORV.mp4"},"id":1}'
16:47:04 T:2144   ERROR: JSONRPC: Failed to parse '{"jsonrpc":"2.0","method":"VideoLibrary.Scan","params":{"directory":?"m:\TV\Conan/"},"id":1}'

So, I don't actually know how to solve that issue, but its clear where the problem is. Also, the files are correctly found and added to the library and playable if I restart XBMC.
Reply
#9
(2013-03-06, 23:37)moeman Wrote: Thanks for the reply. I don't think the label system was the problem, but I went ahead and used this current script you put together. It now does not do anything when I run the script. Here are the last 2 lines (the apparently relevant ones) from the log:

Code:
16:46:54 T:2252   ERROR: JSONRPC: Failed to parse '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":'?'uTorrent","message":"Finished downloading Conan.2013.03.05.Colin.Farrell.HDTV.x264-BAJSKORV.mp4"},"id":1}'
16:47:04 T:2144   ERROR: JSONRPC: Failed to parse '{"jsonrpc":"2.0","method":"VideoLibrary.Scan","params":{"directory":?"m:\TV\Conan/"},"id":1}'

So, I don't actually know how to solve that issue, but its clear where the problem is. Also, the files are correctly found and added to the library and playable if I restart XBMC.

Alright, it seems the forum code function is messing with the script. Download this one: https://dl.dropbox.com/u/33669449/moeman/xbmc.vbs
and give it a shot.
It looks like the reason it wasn't adding the file to the library was because of: "directory":?"m:\TV\Conan/" I've changed that trailing / to a \ for you. Fire it up again and give it another test. Perhaps with a more traditionally (read: non daily) episode. Something with a SxxExx instead of a 2013.03.05.

If you'd like to do some personal debugging, vbsedit (http://www.vbsedit.com/) is a free download that will allow you to input the arguments and run the script. A well placed MsgBox will give you lots of information.
Reply
#10
OK, got the script working again, so it does do the notification in XBMC, but I am still getting an error logged in XBMC on parsing the request for the library update. It looks like the path is correct now, but I am not sure what XBMC syntax for making a library update request is suppose to look like. Were is Frodo documentation on webserver requests? Thanks so much for your help.

The error log now shows:
Code:
19:28:32 T:376   ERROR: JSONRPC: Failed to parse '{"jsonrpc":"2.0","method":"VideoLibrary.Scan","params":{"directory":"m:\TV\Golden Boy\"},"id":1}'
Reply
#11
@moeman, when accessing the files in xbmc, is your entire M:\ drive added as a share? If so, is it added as M:\ or is it added as a network share? (//computername/share)
Reply
#12
I hunted around a bit, and I don't really know VBS or Scheme, or whatever this jsonrpc stuff is in, but as best I can tell, that string that "failed to parse" should be correct. And I assume it works on your end, so it seems like it must be something specific with my setup, but I don't know what. the M: drive is a local drive (although it is also shared), and like I said before, the files will be added to the library if I reboot XBMC. (eventually, but it takes a while to add them).
Reply
#13
Thats probably because you have scan library on boot enabled. In XBMC, how did you add the m:\tv\ directory? Goto Video > Files > and press 'c' on your source. Choose Edit Source. How is it added there? Can you upload your xbmc.log somewhere and send me the link? PM is fine.
Reply
#14
Yes, its definitely set to scan on boot. I just wanted to indicate that the files themselves don't seem to be the problem... They do get added to the library, just not when using this method to try to add them.

The TV source is added as M:\TV\ , so it seem like XBMC should allow access to it via the webserver.

http://dl.dropbox.com/u/23842686/xbmc.log
Reply
#15
Alright, figured it out. It should work now. https://dl.dropbox.com/u/33669449/moeman/xbmc.vbs

I haven't ever used the script with local files (to the script or XBMC) and the problem related to that. All my media is on a server tucked in a closet and shared via SMB to 3 XBMC machines with shared libraries.

The issue: When accepting the directory from utorrent (via the %D option) the directory was coming through as drive:\path\to\folder. When passing this to the jsonrpc, the \ must be escaped with another backslash, meaning the path should look like drive:\\path\\to\\directory.

I added a few lines to check for a path similar to x:\path\to\etc and replace all "\" with "\\". This has also been integrated with the original script, so that one should work too. (Though I'm too tired to test it.)

Let me know how it goes!
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
uTorrent update XBMC on completion00