Author Topic: Script to create NFO from mymovies.xml  (Read 5112 times)

Offline hanks

  • Newbie
  • Posts: 10
  • Helpful Contribution Status: +0/-0
Script to create NFO from mymovies.xml
« on: February 01, 2011, 03:21:06 pm »
Hi Folks.

This is just a quick script to create the NFO for software like ThumbGen.

I use MetaBrowser to generate my XML as well as download the folder.jpg and backgrounds, I share my movies between an HTPC running MediaBrowser and my Mede8er so I always have an mymovies.xml file which contains the required IMDB number so I just point this script to my movies folders and let it rip to create the NFO files for me to use with ThumbGen.

Script is a bit dirty, I took some of it from a guy in this forum (thank you, I just don't remember your name but if you read this please comment) and I added some UI (Browse for folder, progress etc.).

Hope it works for some of you, I use it all the time. Copy and paste into notepad and save it as <Pick a name>.vbs as with any code you find on the WWW read it first and make sure you understand it before you run it! It's clean but I don't want anyone blaming me for screwed-up folders!  8)

Note: If you have a large number of sub-folders it can take a long time to enumerate at first so just wait a min and the folder count UI should pop-up.

Code: [Select]
DIM strStartFolder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Browse", 1, "Computer")

Set objExplorer = WScript.CreateObject("InternetExplorer.Application","IE_")
objExplorer.Navigate "about:blank"
' size of window
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=400
objExplorer.Height = 100
objExplorer.Left = 0
objExplorer.Top = 0
' window visible and starting message
objExplorer.Visible = 1
objExplorer.Document.Body.scroll = "no"

If objFolder Is Nothing Then
    Wscript.Quit
End If

strStartFolder = objFolder.self.path
Set FSO = CreateObject("Scripting.FileSystemObject")

Const ForReading   = 1
Const ForWriting   = 2
Const ForAppending = 8

createNFO FSO.GetFolder(strStartFolder), strStartFolder
MsgBox "Done", vbOKOnly

sub createNFO (Folder, strStart)
Set objFSO = CreateObject("Scripting.FileSystemObject")
'MsgBox Folder.SUbFolders.Count, vbOKOnly
Count = Folder.SUbFolders.Count
For Each Subfolder in Folder.SubFolders
GetIMDB Subfolder.Path, strStart
createNFO Subfolder, strStart
objExplorer.Document.Body.InnerHTML = "Folders Left: " & Count
Count = Count -1
Next
End Sub

sub GetIMDB (Folder , strStart)
Dim xmlDoc, objNodeList, strIMDB, strTitle, strSET
' strSET = ""
' strSET = Mid(folder,len(strStart&"\")+1, (InStrRev(folder,"\") - len(strStart&"\") )  )
' if len(strSET) > 0  then strSET = left(strSET, len(strSET)-1)
' strSET = trim(strSET)


Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.load(Folder & "\mymovies.xml")
Set objNodeList = xmlDoc.getElementsByTagName("IMDB")
If objNodeList.length > 0 then
For each x in objNodeList
strIMDB = x.Text
Next
End If
Set objNodeList = nothing


Set objNodeList = xmlDoc.getElementsByTagName("LocalTitle")
If objNodeList.length > 0 then
For each x in objNodeList
strTitle= x.Text
Next
End If


if (len(strTitle) > 0 ) and (len(strIMDB) > 0 ) then
CreateTheFile Folder, strTitle, strIMDB, strSET
end if
end sub


sub CreateTheFile (strFolder, strTitle, strIMDB, strSET)
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
DIM objFile
Set objFile = objFSO.CreateTextFile(strFolder & "\movie.NFO")
set objFile = nothing
DIM objTextFile
Set objTextFile = objFSO.OpenTextFile (strFolder & "\movie.NFO", ForAppending, True)
objTextFile.WriteLine(strIMDB)
objTextFile.Close
end sub

Edit: Forgot to add... Windows only! Sorry Linux and MacOS folks.

Cheers,

Hank
« Last Edit: February 01, 2011, 05:08:17 pm by hanks »