Jump to content


Photo

Music Video Nfo Creator


  • Please log in to reply
6 replies to this topic

#1 craigey

craigey

    X-S Member

  • Members
  • Pip
  • 90 posts

Posted 19 December 2007 - 05:59 PM

Hi all,

I was having a few issues with my music videos. XBMC only picked up about 80 of them. I had another 200 (or so) that I would need to create nfo files for so that XBMC could add them to the library.

Anyway to make my life easier I did it via a vbscript. Just thought I'd share it with you all. (I make no apologies for the sloppy coding. It works, so who cares)!

CODE


'*  This script creates an XBMC Music Video Nfo file based on the artist & trackname. *
'*  The videos must be in the format artist - trackname for this to work.            *
'*  Mpg, Avi, Wmv, Swf, M2v & Flv files will be picked up.  If there is a format     *
'*  I've missed, line 34 can be edited to add the additional extension. Just add     *
'*  or lcase(exten) = ".xxx" before the word then.                          *
'*  The script is currently unble to handle any 4 letter extensions such as .mpeg    *
'*                                               *
'*  (C)Craigey2007 - 19-12-2007.  Use at your own risk.   V1.6                       *


i = 0
f = 0
g = 0
log_name = "music_video_nfo_creator.log"

Set sa = CreateObject("Shell.Application")
set oF = sa.BrowseForFolder(0, "Source Folder:", ssfWINDOWS)
if (not oF is nothing) then
set fi = oF.Items.Item
else
wscript.quit
end if

Set filesys = CreateObject("Scripting.fileSystemObject")
Set sourceFolder = filesys.GetFolder(fi.Path)     ' The folder containing your Music Videos

set mvidslist = sourceFolder.files
startTime = Timer

For Each mvids in mvidslist
    trackName = mvids.name
exten = right(mvids,4)
if lcase(exten) = ".avi" or lcase(exten) = ".wmv" or lcase(exten) = ".mpg" or lcase(exten) = ".swf" or lcase(exten) = ".m2v" or lcase(exten) = "flv" then
i=i+1
  str1=trackname

fullfilename = WScript.ScriptFullName
currentFolder = Left(filename, InstrRev(filename, "\"))

Set FSOd = CreateObject("Scripting.FileSystemObject")
Set logFile = FSOd.OpenTextFile(currentfolder+log_name, 8, True)

on error resume next
    seperator = InstrRev(str1,"-") 'count left to the first occurance of "-"
    if (seperator >= 1) then                'if the seperator exists split into artist and song
        artist = Left(str1,seperator)              'seperate artist
        songLength= (Len(str1)- seperator)          'work out chr length of song
        song = right(str1,songLength)              'seperate song
        strArtist = artist
        strSong = song
        strSong = Replace(strSong,exten,"")
        strArtist = trim(strArtist)
        strSong = trim(strSong)
        noArtist = Len(strArtist)    'if it can't find an artist name, replace with 'Unknown'
                
    if noArtist = "0" then
        strArtist = "Unknown"
    end if
     noSong = Len(strSong)            'if it can't find a song name, replace with 'Unknown'
        if noSong = "0" then                            
            strSong = "Unknown"
        end if
    else                    'leave alone
    strArtist = "Unknown"
    end if    

str1 = replace(str1,exten,"")
destfil = sourceFolder+"\"+str1+".nfo"



if filesys.FileExists(destFil) then
g=g+1
logFile.Writeline "INFO:**********************Duplicate Below*************************"
else
f=f+1
Set fsonfo = CreateObject("Scripting.FileSystemObject")
Set nfoFile = FSOnfo.OpenTextFile(destfil, 8, True)
nfoFile.Writeline "<musicvideo>"
nfoFile.Writeline "<title>"&strSong&"</title>"
nfoFile.Writeline "<artist>"&strArtist&"</artist>"
nfoFile.Writeline "<album></album>"
nfoFile.Writeline "<genre></genre>"
nfoFile.Writeline "<runtime></runtime>"
nfoFile.Writeline "<plot></plot>"
nfoFile.Writeline "<year></year>"
nfoFile.Writeline "<director></director>"
nfoFile.Writeline "<studio></studio>"
nfoFile.Writeline "</musicvideo>"
nfoFile.Close
set fsonfo = nothing
set nfofile = nothing
end if

timesecs = Timer - startTime
logFile.Writeline trackname & "        " & str1 & "        " & destfil & "        " & g & "        " & f & "        " & i & "        " &timesecs
logFile.Close

end if
next



elapsedTimesecs = Timer - startTime
elapsedtimesecs = CInt(elapsedtimesecs)


if i = "0" then
ermsg="No Music Videos were Found."
erTitle="Files not Found"
MsgBox erMsg, vbOkOnly + vbExclamation, erTitle
wscript.quit
end if

days=0
hours=0
mins=0

do while elapsedtimesecs > 59
mins=mins+1
elapsedtimesecs = elapsedtimesecs - 60
loop

do while mins > 59
hours=hours+1
mins = mins - 60
loop

do while hours > 24
days=days+1
hours = hours - 24
loop

timetaken = f & " Music Videos Nfo files created in "
if days > 1 then
timetaken = timetaken & days & " Days & "
end if
if days = 1 then
timetaken = timetaken & days & " Day & "
end if
if hours > 1 then
timetaken = timetaken & hours & " Hours & "
end if
if days <> 1 and hours = 1 then
timetaken = timetaken & hours & " Hour & "
end if
if mins > 1 then
timetaken = timetaken & mins & " Minutes & "
end if
if hours <> 1 and mins = 1 then
timetaken = timetaken & mins & " Minute & "
end if
if elapsedtimesecs <> 1 then
timetaken = timetaken & elapsedTimesecs & " Seconds"
end if
if elapsedtimesecs = 1 then
timetaken = timetaken & elapsedTimesecs & " Second"
end if

if g = 1 then
timetaken = timetaken & vbcrlf & g & " NFO File already existed & was ignored"
elseif g > 1 then
timetaken = timetaken & vbcrlf & g & " NFO Files already existed & were ignored"
end if

set FSOd = Nothing
set logFile = Nothing

msgbox(timetaken)

Edited by craigey, 19 December 2007 - 06:02 PM.


#2 dgm

dgm

    X-S Enthusiast

  • Members
  • 12 posts

Posted 21 December 2007 - 01:03 PM

Hi

Nice script, but you need to change is slightly.

QUOTE(craigey @ Dec 19 2007, 05:35 PM) View Post


CODE


        artist = Left(str1,seperator)              'seperate artist
    



CODE


        artist = Left(str1,seperator-2)              'seperate artist
    


add "-2" to remove the " -" from the Artist name.

Doug


#3 craigey

craigey

    X-S Member

  • Members
  • Pip
  • 90 posts

Posted 21 December 2007 - 04:54 PM

QUOTE(dgm @ Dec 21 2007, 02:39 PM) View Post

Hi

Nice script, but you need to change is slightly.
CODE


        artist = Left(str1,seperator-2)              'seperate artist
    


add "-2" to remove the " -" from the Artist name.

Doug


It depends on the format of your vides. I did mention in the top of the comments that it'd work for files with the filename format of Artist - trackname.xxx

Could you post an example of the filename format that the -2 would work for. I presume it'd be something like album - artist - track?

Anyway thanks for taking the time to comment. :-)

#4 dgm

dgm

    X-S Enthusiast

  • Members
  • 12 posts

Posted 21 December 2007 - 05:33 PM

Hi

The Police - Every Little Thing She Does Is Magic.avi

Gives with the unmodified script:

CODE

<musicvideo>
<title>Every Little Thing She Does Is Magic</title>
<artist>The Police -</artist>
<album></album>
<genre></genre>
<runtime></runtime>
<plot></plot>
<year></year>
<director></director>
<studio></studio>
</musicvideo>


And with the modified line:

CODE

<musicvideo>
<title>Every Little Thing She Does Is Magic</title>
<artist>The Police</artist>
<album></album>
<genre></genre>
<runtime></runtime>
<plot></plot>
<year></year>
<director></director>
<studio></studio>
</musicvideo>


The only difference is <artist> </artist>

Doug


#5 craigey

craigey

    X-S Member

  • Members
  • Pip
  • 90 posts

Posted 21 December 2007 - 11:15 PM

Bum!
Yep Thanks for that.


#6 craigey

craigey

    X-S Member

  • Members
  • Pip
  • 90 posts

Posted 21 December 2007 - 11:38 PM

Just in case anyone has run the script (like me) & ended up with "artist -" in the nfo files. You can use the following script to fix it. (Hopefully I wont need to post another script to fix this one)!!

CODE

Const ForReading = 1
Const ForWriting = 2

Set sa = CreateObject("Shell.Application")
set oF = sa.BrowseForFolder(0, "Source Folder:", ssfWINDOWS)
if (not oF is nothing) then
set fi = oF.Items.Item
else
wscript.quit
end if

Set filesys = CreateObject("Scripting.fileSystemObject")
Set Path = filesys.GetFolder(fi.Path)     ' The folder containing your Music Videos


Set objFSO = CreateObject("Scripting.FileSystemObject")

Set FSO = CreateObject("Scripting.FileSystemObject")

ScanDirectory FSO.GetFolder(path)

Sub ScanDirectory(oFolder)
    ScanFiles oFolder

    For each folder in oFolder.SubFolders
        ScanDirectory folder
    Next
End Sub

Sub Scanfiles(oFolder)

    For each file in oFolder.Files

extens = right(file,4)

if lcase(extens) = ".nfo" then

Set objFile = objFSO.OpenTextFile(file, ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, " -", "")
strNewText = Trim(strNewText)
If strNewText <> StrText Then
Set objFile = objFSO.OpenTextFile(file, ForWriting)
objFile.WriteLine strNewText
objFile.Close
end if

end if
    Next
End Sub

Msgbox("Done")


#7 bionic1234

bionic1234

    X-S Enthusiast

  • Members
  • 2 posts

Posted 08 January 2008 - 05:23 AM

Very cool craigey, thanks for sharing.
I am a newbie to using VBscripts, so I looked around a while and then figured out how to do it, for anyone else out there looking to use this awesome VBscript.
I used PrimalScript 2007 (as I first tried just copying and pasting the code to Notepad and saving as a .wsf file - but Windows Scripting Host didn't seem to like something in the code.
So I copied and pasted craigey's original VBscript into PrimalScript 2007.
Step1 Create a Project
Step2 Create a Data - Script file in that Project file
Step3 Copy and paste craigey's code into the data file (making the modification to the artist line of course)
Step4 Save
Step5 Run Active Project

Thanks again craigey






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users