uTorrent - TheRenamer - AutoUpdate Library

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
frozenbubbl Offline
Junior Member
Posts: 14
Joined: Mar 2011
Reputation: 0
Post: #1
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.

  1. Change the definition section to meet your needs.
  2. 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.
  3. You need to set up utorrent to execute a script after downloading. The command is simple XBMCUpd.vbs %L
  4. 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.
  5. 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  = "recipient@me.com"
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&parameter=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
(This post was last modified: 2011-08-19 21:23 by frozenbubbl.)
find quote
Hybred Offline
Junior Member
Posts: 37
Joined: Apr 2011
Reputation: 0
Post: #2
I like to seed my files so Renaming them really isn't in the ballpark for me. However I would like to run that script when a torrent finishes to update my library. Any chance you could edit out the Renamer parts and just leave me with a refresh script? Smile

Also, I would assume a dry refresh wouldn't need labels... correct?
find quote
frozenbubbl Offline
Junior Member
Posts: 14
Joined: Mar 2011
Reputation: 0
Post: #3
Delete/Comment this part
Code:
    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
find quote
Hybred Offline
Junior Member
Posts: 37
Joined: Apr 2011
Reputation: 0
Post: #4
Thanks. Did you figure out how to stop the minimizing? (Because I did.)
(This post was last modified: 2011-08-30 20:44 by Hybred.)
find quote
frozenbubbl Offline
Junior Member
Posts: 14
Joined: Mar 2011
Reputation: 0
Post: #5
Out of curiosity, I wonder what you did to make this work. I might need this later Wink

In the meantime I switched over to EventGhost. Doesn't give me any benefit, that couldn't implemented into the vbscript actually.
find quote