Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '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
- '=================================================================================
- 'Notes Section: READ THIS!!!
- '
- 'If you have multiple instances of XBMC throughout your house, you can setup each of them below.
- 'This script is configured for two instances with shared libraries via MySQL, however it can be made to work with as many as you need.
- 'If you have multiple instances with individual databases (not shared via MySQL) you will need to uncomment relevant lines in the Implementation section.
- ' 111-113 for 2 instances, 111-116 for 3, 111-119 for 4, and 111-122 for 5.
- 'If you only have one xbmc instance, comment out lines 28, 91-93, and 135-137
- 'If you want more than five xbmc instances, add the variables in the Declaration section "Dim xbmcConnection6" "Dim xbmcConnection7" etc. and
- ' add the configs below in the Settings Section. You will also need to add lines to send notifications to each instance in the
- ' Implementation section. Ask for help on the Forum, if need be.
- 'You need to turn on the HTTP server in XBMC under Settings>Network and configure the username and password for this to work.
- ' In this script, the example username and password are both "xbmc"
- 'Also, please note that if your media is shared as a local share on your PC, you will need to comment out lines 84 and 85.
- '
- 'In uTorrent, Options > Preferences > Advanced > Run Program : Add the following
- 'When a Torrent Finishes: "C:\path\to\xbmc.vbs" -U "%N" "%D" "%L"
- 'When a Torrent Changes State: "C:\path\to\xbmc.vbs" -S "%M" "%N" "%L"
- '
- '=================================================================================
- 'Declaration section
- Dim objSvrHTTP
- Dim connectionString 'string to send to xbmc
- Dim xbmcConnection 'xbmc connection details, defined in Settings Section
- Dim xbmcConnection2
- 'Dim xbmcConnection3
- 'Dim xbmcConnection4
- 'Dim xbmcConnection5
- Dim message ' contains name of torrent when sending status message to xbmc
- Dim header ' contains status of torrent when sending status message to xbmc
- Dim myPath ' path of download in utorrent as provided via %D.
- Dim ignoreTorrent ' variable used to ignore torrents not containing BTN labels
- Dim label ' uTorrent label, %L
- Dim ulabel0 ' Labels in uTorrent you want reported to xbmc
- Dim ulabel1
- Dim ulabel2
- 'Dim ulabel3 ' uncomment if adding more labels
- 'Dim ulabel4
- 'Dim ulabel5
- Set objSvrHTTP = CreateObject("MSXML2.XMLHTTP")
- On Error Resume Next
- '=================================================================================
- 'Settings Section
- 'edit these lines to work with your setup
- xbmcConnection = "http://xbmc:xbmc@192.168.0.11:80/jsonrpc?request=" ' This connection is the one that will perform library updates.
- xbmcConnection2 = "http://xbmc:xbmc@192.168.0.10:80/jsonrpc?request="
- 'xbmcConnection3 = "http://xbmc:xbmc@192.168.0.2:8080/jsonrpc?request="
- 'xbmcConnection4 = "http://xbmc:xbmc@localhost:8080/jsonrpc?request="
- 'xbmcConnection5 = "http://xbmc:xbmc@192.168.0.5:8080/jsonrpc?request="
- 'examples
- 'xbmcConnection = "http://xbmc:xbmc@localhost:8080/jsonrpc?request="
- 'xbmcConnection = "http://xbmc:myownpass@192.168.1.101:80/jsonrpc?request="
- 'change values to the uTorrent labels you want this script to be used with.
- ulabel0 = "TV-Shows"
- 'ulabel1 = "label" ' uncomment if adding more labels
- 'ulabel2 = "label"
- 'ulabel3 = "label"
- 'ulabel4 = "label"
- 'ulabel5 = "label"
- '==================================================================================
- 'Implementation Section
- label = WScript.Arguments.Item(3)
- Select Case label
- Case ulabel0, ulabel1, ulabel2, ulabel3, ulabel4, ulabel5 'if utorrent label matches labels defined in settings, execute script. Otherwise do nothing.
- ignoreTorrent = "false"
- Case Else
- ignoreTorrent = "true"
- End Select
- 'check ignoreTorrent value and abort script if torrent is not a library item.
- if ignoreTorrent = "false" then
- '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
- connectionString = xbmcConnection2 & JSONstring
- objSvrHTTP.open "GET", connectionString, False
- objSvrHTTP.send
- 'uncomment the below sections (3 lines each) for each additional xbmc implementation.
- 'JSONstring = URLEncode(Replace("{''jsonrpc'':''2.0'',''method'':''GUI.ShowNotification'',''params'':{''title'':''uTorrent'',''message'':''Finished downloading " & WScript.Arguments.Item(1) & "''},''id'':1}","''",Chr(34)))
- 'connectionString = xbmcConnection3 & JSONstring
- 'objSvrHTTP.open "GET", connectionString, False
- 'objSvrHTTP.send
- 'connectionString = xbmcConnection4 & JSONstring
- 'objSvrHTTP.open "GET", connectionString, False
- 'objSvrHTTP.send
- 'connectionString = xbmcConnection5 & 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 you are using multiple XBMC WITHOUT MySQL, WHY?!?! Uncomment below (3 line sections) to enable each instance to update their individual libraries.
- 'connectionString = xbmcConnection2 & JSONstring
- 'objSvrHTTP.open "GET", connectionString, False
- 'objSvrHTTP.send
- 'connectionString = xbmcConnection3 & JSONstring
- 'objSvrHTTP.open "GET", connectionString4, False
- 'objSvrHTTP.send
- 'connectionString = xbmcConnection5 & JSONstring
- '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
- header = WScript.Arguments.Item(1)
- 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
- connectionString = xbmcConnection2 & JSONstring
- objSvrHTTP.open "GET", connectionString, False
- objSvrHTTP.send
- 'if you are using multiple XBMC installations, uncomment below (3 line sections) to enable each installation to recieve a notification
- 'connectionString3 = xbmcConnection & JSONstring
- 'objSvrHTTP.open "GET", connectionString, False
- 'objSvrHTTP.send
- 'connectionString4 = xbmcConnection & JSONstring
- 'objSvrHTTP.open "GET", connectionString, False
- 'objSvrHTTP.send
- 'connectionString5 = xbmcConnection & JSONstring
- 'objSvrHTTP.open "GET", connectionString, False
- 'objSvrHTTP.send
- end if
- end if
- elseif ignoreTorrent = "true" then
- WScript.Quit
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement