2011-08-19, 21:20
Hi,
I wrote a small script today, that calls TheRenamer after downloading Movies or Series, and tells your XBMC to update library. It has a built in function to send you a mail. But to be honest, i didn't check it if it works due to missing mail server that lets me sending emails without smtp-auth first.
One drawback has the script though:
Once uTorrent runs the script, XBMC is minimized for 3-4 seconds. Any thoughts to get rid of that?
I wrote a small script today, that calls TheRenamer after downloading Movies or Series, and tells your XBMC to update library. It has a built in function to send you a mail. But to be honest, i didn't check it if it works due to missing mail server that lets me sending emails without smtp-auth first.
- Change the definition section to meet your needs.
- Set uTorrent to append label to path. (this is that therenamer knows where to pick up either movies or series). This up to you how you set it up.
- You need to set up utorrent to execute a script after downloading. The command is simple XBMCUpd.vbs %L
- Every torrent you add, you need to give labels. Preconfigured is Movies and Series, but you can change it, as you can see in the script.
- it will create a log file to in the same directory
One drawback has the script though:
Once uTorrent runs the script, XBMC is minimized for 3-4 seconds. Any thoughts to get rid of that?
Code:
'Runs XBMC & Renamer update job
'Created by frozenbubble
'Email: frozenbubble
'Version: 1.0
On Error resume next
Dim argLabel, StartTime
'============Definitions========================
Const Logfile = "postprocessing.log"
Const Mail = False
Const MailRecipient = "[email protected]"
Const MailSender = "prock@local"
Const MailServer = "mail.server.com"
Const FetchSeries = "-fetch"
Const FetchMovies = "-fetchmovie"
Const PathToTheRenamer = "C:\Program Files (x86)\theRenamer\theRenamer.exe"
Const LabelSeries = "Series"
Const LabelMovies = "Movies"
Const XBMCHost = "192.168.1.50"
Const XBMCUser = "xbmc"
Const XBMCPassword = "xbmc"
Const XBMCPort = "80"
'============End of Definitions========================
'==============Main====================
StartTime = Date() & " " & Time() & ":"
createLog(StartTime)
'Check on passed on arguments
If WScript.Arguments.Count = 1 Then
argLabel = WScript.Arguments.Item(0)
createLog("Argument passed on: " & argLabel)
Renamer(argLabel)
Else
createLog("Usage: XBMCUpd.vbs Label")
createLog("Configure uTorrent to pass on Labels")
createLog("to do postprocessing on your downloads:")
createLog("wscript XBMCUpd.vbs %L")
Wscript.Quit
End If
'Run core function
Renamer
'==============End Main================
Sub Renamer(strLabel)
Dim WshShell, oExec
Dim ExeStatement
Dim objSvrHTTP
Dim conUpdString
'Putting together the right ExeStatement
If strLabel = LabelSeries Then
createLog("Executing Series")
ExeStatement = """" & PathToTheRenamer & """" & " " & FetchSeries
ElseIf strLabel = LabelMovies Then
createLog("Executing Movies")
ExeStatement = """" & PathToTheRenamer & """" & " " & FetchMovies
Else
createLog("No valid argument passed on")
Wscript.Quit
End If
'Run ExeStatement
'wscript.echo ExeStatement
createLog("Execute TheRenamer")
Set WshShell = CreateObject("WScript.Shell")
'WshShell.Run "%comspec% /c " & ExeStatement
WshShell.Run(ExeStatement)
'http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.85).aspx
WScript.Sleep 30000
'Run XBMCUpd
Set objSvrHTTP = CreateObject("MSXML2.XMLHTTP")
If strLabel = LabelMovies Then conNotString = "http://" & XBMCUser & ":" & XBMCPassword & "@" & XBMCHost & ":" & XBMCPort & "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Update,New movie added,4000))"
If strLabel = LabelSeries Then conNotString = "http://" & XBMCUser & ":" & XBMCPassword & "@" & XBMCHost & ":" & XBMCPort & "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Update,New episode added,4000))"
'wscript.echo conNotString
'wscript.echo "send Notification"
objSvrHTTP.open "GET", conNotString
objSvrHTTP.send
WScript.Sleep 7000
createLog("Sent Notification")
'Wscript.echo "send update command to xbmc"
conUpdString = "http://" & XBMCUser & ":" & XBMCPassword & "@" & XBMCHost & ":" & XBMCPort & "/xbmcCmds/xbmcHttp?command=ExecBuiltIn¶meter=XBMC.UpdateLibrary(video)"
'wscript.echo conUpdString
objSvrHTTP.open "GET", conUpdString
objSvrHTTP.send
'wscript.echo "finished sending http strings"
createLog("Sent Update command")
'Send email
If Mail = True Then
sendEmail(strLabel)
createLog("Sent Mail")
End If
End Sub
Sub createLog(strName)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
'if logfile does not exist create one
If (fso.FileExists(Logfile)) <> True Then
'WScript.Echo "Logfile created"
Set MyFile = fso.CreateTextFile(Logfile, False)
MyFile.Close
End If
Set f = fso.OpenTextFile(Logfile, ForAppending)
f.Write strName & VbCrLf
f.Close
End Sub
Sub sendEmail(strUpdateType)
Dim EmailBody
'========================= Make changes here ======================
EmailBody = strUpdateType & " downloaded and passed on to TheRenamer." & VbCrLf
EmailBody = "Script started: " & StartTime & VbCrLf
'========================= No more changes (see function sendEmail)
Set objEmail = CreateObject("CDO.Message")
objEmail.From = MailSender
objEmail.To = MailRecipient
objEmail.Subject = "Download complete, files added to library"
objEmail.Textbody = EmailBody
'objEmail.AddAttachment "C:\Scripts\Output.txt"
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailServer
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
createLog("Email sent")
End Sub