Well I got it to work...
When it was comparing the mask with the number of lines in the file with the number of tracks selected, it was always 1 off. I did not have an extra CR at the bottom of my txt file. Added one also didn't work.
So I changed the following line:
TagListLines = Count(TagListContent, Chr(13))
to:
TagListLines = Count(TagListContent, Chr(13)) - 1
And it works like a charm. For example, if your text file has only the Title, seperated by CR LF, use the mask <Title>.
Let me know if anyone (or the original author) has another idea, but this is the one I came up with. With some minor testing, it seems to work well.
BTW, msdos CR LF is in fact the accepted file type, since it parses on CR (13) and then automatically skips the next character, which is a LF. If you don't have a LF, then it will always skips the first letter on each line. IMO, it would be best to auto parse CR LF, or CR or LF - or at least give you the option to choose in the dialog. Perhaps when I have time I will add this feature, then I will post it.
Here is the updated file:
Code: Select all
Option Explicit
Sub OnStartUp
if not (SDB.VersionHi >= 2 and SDB.VersionLo >= 5 and SDB.VersionRelease >= 3) then
Dim Text
Text = "'Auto-Tag from Taglist' needs MediaMonkey 2.5.3 or above." + chr(13)
Text = Text & "Please Download the latest Version on http://www.MediaMonkey.com" + chr(13) + Chr(13)
Text = Text & "Since MediaMonkey 2.5.3 isn't officially released, search the Forum for the latest Beta!"
SDB.MessageBox Text, mtError, Array(mbOK)
else
Dim MenuItem
Set MenuItem = SDB.UI.AddMenuItem(SDB.UI.Menu_Tools, 1, -3)
MenuItem.Caption = "Auto-Tag from Tag-List..."
MenuItem.IconIndex = 26
MenuItem.UseScript = Script.ScriptPath
MenuItem.OnClickFunc = "TagFromTagList"
Set MenuItem = Nothing
end if
End Sub
Sub TagFromTagList(MenuItem)
Dim Form, Label, Button, Dialog, DropDownMask
Dim EditPath, DropDownMaskMask
Dim FileSys, File
Set FileSys = CreateObject("Scripting.FileSystemObject")
Dim Content
Dim a
Set Form = SDB.UI.NewForm
Form.Common.SetRect 0, 0, 310, 180
Form.FormPosition = 4 ' Screen Center
Form.BorderStyle = 3 ' Dialog
Form.Caption = "Auto-Tag from Tag-List"
Set Label = SDB.UI.NewLabel(Form)
Label.Common.SetRect 10, 15, 280, 18
Label.Caption = "Tag-List File:"
Set EditPath = SDB.UI.NewEdit(Form)
EditPath.Common.SetRect 10, 30, 280, 18
EditPath.Text = SDB.INIFile.StringValue("TagsFromFileList", "LastFile")
Set Dialog = SDB.CommonDialog
Dialog.InitDir = EditPath.Text
Dialog.Filter = "*.txt|*.txt|*.csv|*.csv|*.*|*.*"
Dialog.ShowOpen
if Dialog.OK then
EditPath.Text = Dialog.Filename
'show first line of file
Set File = FileSys.OpenTextFile(EditPath.Text, 1, False)
Set Label = SDB.UI.NewLabel(Form)
Label.Common.SetRect 10, 94, 280, 18
Content = File.ReadLine
If Left(Content, 3) = "" Then Content = Mid(Content, 4)
Label.Caption = Content
Set File = Nothing
end if
Set Dialog = Nothing
Set Label = SDB.UI.NewLabel(Form)
Label.Common.SetRect 10, 54, 280, 18
Label.Caption = "Mask:"
Set DropDownMask = SDB.UI.NewDropDown(Form)
DropDownMask.Common.SetRect 10, 69, 280, 18
DropDownMask.Common.Hint = "<Tabulator>" & Chr(13)
DropDownMask.Common.Hint = DropDownMask.Common.Hint & "<Return>" & Chr(13)
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%T") & Chr(13) 'Song #
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%S") & Chr(13) 'Titel
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%A") & Chr(13) 'Interpret
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%R") & Chr(13) 'Album Interpret
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%L") & Chr(13) 'Album
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%Y") & Chr(13) 'Jahr
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%G") & Chr(13) 'Genre
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%B") & Chr(13) 'Bitrate
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%M") & Chr(13) 'BPM
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%C") & Chr(13) 'Komponist
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%P") & Chr(13) 'Ordner
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%F") & Chr(13) 'Dateiname
DropDownMask.Common.Hint = DropDownMask.Common.Hint & SDB.Tools.Mask2UFText("%X") 'Überspringen
for a = 1 to 10
Content = SDB.INIFile.StringValue("TagsFromFileList", "LastMask" & a)
if Content <> "" then
DropDownMask.AddItem(Content)
if a = 1 then DropDownMask.Text = Content
end if
next
Set Button = SDB.UI.NewButton( Form)
Button.Caption = SDB.Localize("&Ok")
Button.Common.SetRect 115, 110, 75, 25
Button.ModalResult = 1
Button.Default = True
Set Button = SDB.UI.NewButton( Form)
Button.Caption = SDB.Localize("&Cancel")
Button.Common.SetRect 215, 110, 75, 25
Button.ModalResult = 2
Button.Cancel = True
if Form.ShowModal = 1 then
Dim Tracks, Track
Dim FileListPos
Dim Mask, MaskLines
Dim TagListContent, TagListLines, LastFileListPos
Dim intTemp
Set Tracks = SDB.SelectedSongList
for a = 1 to 10
SDB.INIFile.DeleteKey "TagsFromFileList", "LastMask" & a
next
for a = 0 to DropDownMask.ItemCount
if a = 0 then
Content = DropDownMask.Text
else
Content = DropDownMask.ItemText(a - 1)
end if
if Content <> "" then SDB.INIFile.StringValue("TagsFromFileList", "LastMask" & (a + 1)) = Content
'clear Duplicates in DropDownList
for intTemp = a to DropDownMask.ItemCount - 1
if DropDownMask.ItemText(intTemp) = Content then DropDownMask.DeleteItem(intTemp)
next
next
if not SDB.Tools.FileSystem.FileExists(EditPath.Text) then
SDB.MessageBox "File " & EditPath.Text & " not found!", mtError, Array(mbOK)
Exit Sub
end if
Set File = FileSys.OpenTextFile(EditPath.Text, 1, False)
Mask = SDB.Tools.UFText2Mask(DropDownMask.Text)
Mask = Replace(Mask, "<Tabulator>", Chr(9))
Mask = Replace(Mask, "<Return>", Chr(13))
MaskLines = Count(Mask, Chr(13))
TagListContent = File.ReadAll
'modified by MJM 01-05-2007
TagListLines = Count(TagListContent, Chr(13)) - 1
'MsgBox "Int(TagListLines / MaskLines): " & Int(TagListLines / MaskLines)
'MsgBox "TagListLines / MaskLines: " & TagListLines / MaskLines
If (TagListLines / MaskLines) <> Int(TagListLines / MaskLines) Then
if TagListLines <> (Int(TagListLines / MaskLines)*MaskLines + 1) then
SDB.MessageBox "Number of Lines in Tag-List and Mask doesn't fit!", mtError, Array(mbOK)
Exit Sub
end if
End If
If Tracks.Count <> Int(TagListLines / MaskLines) Then
SDB.MessageBox "Number of Lines in Tag-List and Track-List doesn't fit!", mtError, Array(mbOK)
Exit Sub
End If
FileListPos = 0
LastFileListPos = 0
TagListContent = TagListContent + Chr(13)
For intTemp = 1 To (TagListLines / MaskLines) 'soviele Tracks
Set Track = Tracks.Item(intTemp - 1)
For a = 1 To MaskLines
FileListPos = InStr(FileListPos + 1, TagListContent, Chr(13))
Next
Content = Trim(Mid(TagListContent, LastFileListPos + 1, FileListPos - LastFileListPos-1))
If Left(Content, 3) = "" Then Content = Mid(Content, 4)
'necessary for ParseText:
if InStr(Mask, "%A") then Track.ArtistName = ""
if InStr(Mask, "%L") then Track.AlbumName = ""
if InStr(Mask, "%R") then Track.AlbumArtistName = ""
if InStr(Mask, "%G") then Track.Genre = ""
Track.ParseText Content, Mask
LastFileListPos = FileListPos + 1
Set Track = Nothing
Next
'Refresh Screen
SDB.MainTracksWindow.RemoveSelectedTracks
for a = 0 to Tracks.Count - 1
SDB.MainTracksWindow.AddTrack(Tracks.Item(a))
next
SDB.MainTracksWindow.FinishAdding
If SDB.MessageBox("Correct?", mtConfirmation, Array(mbYes, mbNo)) = mrYes Then
Tracks.UpdateAll
Else
SDB.MainTracksWindow.Refresh
End If
End if
End Sub
Function Count(Text, Seperator)
Dim intTemp
Count = 0
intTemp = 1
Do
Count = Count + 1
intTemp = InStr(intTemp + 1, Text, Seperator)
Loop While intTemp > 0
End Function