iPlaylist Importer 1.6 - Updated 25/05/2008
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
Well, the music sure looks like it is in the MMW library. The first thing that I did with MMW was to have it scan for all of the music. MMW found and listed all of our music files out of the iTunes folder.
Is there something more necessary that I should have done?
Is there something more necessary that I should have done?
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
Hi,
I try iPlaylist Importer and it import all my iTunes Playlist but did not work if the Playlist or the trackname have special characters or german umlauts in it.
Is there a possibility to correct this?
Another point is that the script always check all files at the playlist with the library but if you often sync your iTunes Plalists with MM it would be nice to skip this in some cases!
Regards, Pauli
I try iPlaylist Importer and it import all my iTunes Playlist but did not work if the Playlist or the trackname have special characters or german umlauts in it.
Is there a possibility to correct this?
Another point is that the script always check all files at the playlist with the library but if you often sync your iTunes Plalists with MM it would be nice to skip this in some cases!
Regards, Pauli
Re: iPlaylist Importer 1.6 [MM2+3]
Hi, trixmoto.trixmoto wrote:After more than 10 hours invested in this, unfortunately I have to report that I have failed. VBScript simply cannot read UTF-8 files, which is what this XML file is, only UTF-16. I spent many hours working on binary level conversion and was having some success, but unfortunately I just can't make it work.
First I would like to issue a WARNING to all users who read this:
>> BEWARE: THIS SCRIPT MAY CORRUPT YOUR MEDIA FILES!
I'd like to try and fix this script to read UTF-8, if possible.
Is the code you have posted on first page of this thread the latest version [DATE : 25/05/2008] ?
I just installed MM and tried downloaded your script from your web site as iPlaylistImporter16.mmip.
I'm not sure if I installed it correctly. I used the MM Tools menu: Extensions... to add iPlaylistImporter16.mmip
This method is different from what is included in the text of the vbs code, which says:
Code: Select all
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
In any case, what happened to me was that I have a great many mp3 files with tags in UTF-8 that got incorrectly mangled by iPlaylistImporter16.
That wouldn't have been so bad except, for some reason, this garbled text was then WRITTEN to the media files, thereby corrupting about half of my music library [1.5 TB]. Fortunately, I was able to restore from backup.
I'd like to see if I can fix your script and contribute to the MM community.
Hope to hear from you, but if not I'll take a stab at it anyway.
I have found some promising info here:
http://wiki.mcneel.com/developer/script ... d=noscript
It seems that the problem is that you are using the wrong File System Object.The File System Object, generally used by VBScript devlopers to read and write text files, can read only ASCII or Unicode text files. You cannot use it to read or write UTF-8 encoded text files.
But, if you can use Microsoft ActiveX Data Objects (ADO), you can read UTF-8 encoded text files like this:
Code: Select all
Dim objStream, strData Set objStream = CreateObject("ADODB.Stream") objStream.CharSet = "utf-8" objStream.Open objStream.LoadFromFile("C:\Users\admin\Desktop\test.txt") strData = objStream.ReadText()
Re: iPlaylist Importer 1.6 [MM2+3]
Yep. I've gone ahead and fixed the problem by using ADODB.Stream to read iTunes playlist as UTF-8.gk wrote: It seems that the problem is that you are using the wrong File System Object.
I'll wait a bit to see if trixmoto wants to publish my fix, otherwise I'll upload the source code here in a day or two.
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
Here is a test script which reproduces the two bugs I've mentioned previously.
Tomorrow, I'll post the fix for both problems.
Tomorrow, I'll post the fix for both problems.
Code: Select all
'
' MediaMonkey Script
'
' NAME: iPlaylistImporter161.vbs
' iPlaylistImporter (1.6 ShowBug)
'
'--------------------------------------------------------------------
' EDITOR: gk (http://proliberty.com)
' DATE : 5/13/2015
'
' DEBUG: Corruption of mp3 file tag data when reading UTF-8 encoded XML file as ASCII
'
' STEPS TO REPRODUCE:
' 0. Edit an mp3 file, named test.mp3, so that the Title tag contains a character with diacritical marks [i.e., non-ASCII].
' In this example, my Title tag was 'Águas de Março'
' 1. Create iTunes playlist, 'Test', containing the above file with non-ASCII tag.
' 2. Export this playlist from iTunes as 'Test.xml'
' 3. Install this script, per instructions below.
' 4. Launch MediaMonkey and remove any songs in the Library database and playlists.
' 5. Confirm that the default MediaMonkey Option is set:
' > Tools > Options > Library > Tags & Playlists
' Update tags when editing properties
' 6. Run this script (with default ShowBug=True)
' Tools > Scripts > iPlaylistImporter161
' Open the 'Test.xml' playlist, created above.
' 7. Inspect the value of test.mp3 Title tag
'
' EXPECTED RESULT: no change. Title tage should still contain diacritical character(s):
' Águas de Março
'
' ACTUAL RESULT [bug]: The diactrical character(s) in Title tag will have been changed to:
' Ãguas De Março
' This script and/or MediaMonkey should not have altered the tag data without warning.
'
' To test the fix for the tag corruption, set ShowBug = False
' Library tag data will be corrupted, but this won't be written back to the mp3 file anymore.
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
'
' [iPlaylistImporter161]
' FileName=iPlaylistImporter161.vbs
' ProcName=iPlaylistImporter
' Order=61
' DisplayName=iPlaylist Importer 1.6 (ShowBug)
' Description=Import XML playlists from iTunes
' Language=VBScript
' ScriptType=0
'
'--------------------------------------------------------------------
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 25/05/2008
'
'
' FIXES: Fixed trim function doesn't work with tabs
'
Option Explicit
'If ShowBug = True, the bug will occur due to list.UpdateAll() writing bad data to tags
'Otherwise, I have implemented itm.UpdateDB() to be used instead.
Dim ShowBug : ShowBug = True
Dim Debug : Debug = False
Sub iPlaylistImporter
'get filename
Dim dlg : Set dlg = SDB.CommonDialog
dlg.Filter = "Playlist (XML)|*.xml"
dlg.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly + cdlOFNNoChangeDir
dlg.InitDir = SDB.MyMusicPath
dlg.ShowOpen
If Not dlg.Ok Then
Exit Sub
End If
Dim xml : xml = dlg.FileName
'create progress bar
Dim prog : Set prog = SDB.Progress
prog.Text = "iPlaylistImporter: Initialising..."
prog.Value = 0
prog.MaxValue = 1
'create parent playlist
Dim ply : Set ply = Nothing
Dim par : Set par = SDB.PlaylistByTitle("iPlaylists")
If par.Title = "" Then
Set par = SDB.PlaylistByTitle("").CreateChildPlaylist("iPlaylists")
End If
If par Is Nothing Then
Call SDB.MessageBox("iPlaylistImporter: Could not find or create 'iPlaylists' parent playlist.",mtError,Array(mbOk))
Exit Sub
End If
'create logfile
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
If Debug Then
Dim wsh : Set wsh = CreateObject("WScript.Shell")
Dim loc : loc = wsh.ExpandEnvironmentStrings("%TEMP%")&"\iPlaylistImporter.log"
Dim log : Set log = fso.CreateTextFile(loc,True)
If log Is Nothing Then
Debug = False
Else
Call log.WriteLine("Import file: "&xml)
End If
End If
'initialise
Dim mode : mode = 0
Dim trid : trid = 0
Dim fndt : fndt = 0
Dim cret : cret = 0
Dim fndp : fndp = 0
Dim crep : crep = 0
Dim dic : Set dic = CreateObject("Scripting.Dictionary")
Dim dat : Set dat = CreateObject("Scripting.Dictionary")
Dim dtn : Set dtn = CreateObject("Scripting.Dictionary")
Dim txt : Set txt = fso.OpenTextFile(xml,1,False)
Dim prg : prg = ""
Dim tot : tot = 0
Dim gtot : gtot = 0
'read file
Do While Not txt.AtEndOfStream
Dim str : str = txt.ReadLine
If InStr(str,"<") > 0 Then
str = Mid(str,InStr(str,"<"))
End If
Dim key : key = gettag(str,"key")
Select Case mode
Case 0 'reading header
If key = "Tracks" Then
mode = 1
trid = 0
End If
Case 1 'reading tracks
If key = "Playlists" Then
mode = 3
trid = 0
Else
If key = "Track ID" Then
mode = 2
trid = Int(gettag(str,"integer"))
Set dat = CreateObject("Scripting.Dictionary")
prog.Text = "iPlaylistImporter: Reading XML file (Track ID = "&trid&")..."
SDB.ProcessMessages
If Debug Then Call log.Write("Reading track: "&CStr(trid))
End If
End If
Case 2 'reading track data
If key = "" Then
Set dic.Item(CStr(trid)) = dat
mode = 1
trid = 0
If Debug Then Call log.WriteLine(": "&dat.Item("Name"))
Else
dat.Item(CStr(key)) = gettag2(str)
End If
Case 3 'reading playlists
If key = "Name" Then
mode = 4
tot = 0
Dim nam : nam = Replace(gettag(str,"string"),"&","&")
Set ply = SDB.PlaylistByTitle(nam)
If Not (ply.Title = "") Then
trid = SDB.MessageBox("iPlaylistImporter: Do you wish to overwrite playlist '"&nam&"'?",mtConfirmation,Array(mbYes,mbNo))
If trid = mrNo Then
mode = 3
End If
End If
If mode = 4 Then
If ply.Title = "" Then
crep = crep+1
Set ply = par.CreateChildPlaylist(nam)
If Debug Then Call log.WriteLine("**Creating playlist: "&ply.Title)
prg = "iPlaylistImporter: Creating playlist '"
Else
fndp = fndp+1
Call ply.Clear()
If Debug Then Call log.WriteLine("**Updating playlist: "&ply.Title)
prg = "iPlaylistImporter: Updating playlist '"
End If
prog.Text = prg&ply.Title&"'..."
SDB.ProcessMessages
Set dtn.Item((crep+fndp)&"p") = ply
Else
Set ply = Nothing
End If
End If
Case 4 'reading playlist data
If key = "Track ID" Then
trid = gettag(str,"integer")
If dic.Exists(CStr(trid)) Then
Set dat = dic.Item(CStr(trid))
tot = tot+1
gtot = gtot+1
Set dtn.Item((crep+fndp)&"d"&tot) = dat
End If
Else
If str = "</array>" Then
mode = 3
End If
End If
Case Else
Call SDB.MessageBox("iPlaylistImport: Unknown mode '"&mode&"'.",mtError,Array(mbOk))
Exit Sub
End Select
If prog.Terminate Then
Exit Do
End If
Loop
txt.Close
'create playlists
prog.MaxValue = gtot
Dim max : max = crep+fndp
For trid = 1 To max
If dtn.Exists(trid&"p") Then
Set ply = dtn.Item(trid&"p")
tot = 1
While (dtn.Exists(trid&"d"&tot))
Set dat = dtn.Item(trid&"d"&tot)
Dim fil : fil = fixhex(dat.Item("Location"))
If Left(fil,7) = "file://" Then
fil = Mid(fil,8)
End If
If InStr(fil,":") > 0 Then
fil = Mid(fil,InStr(fil,":")-1)
End If
fil = Replace(fil,"/","\")
Dim upd : upd = False
Dim itm : Set itm = Nothing
Dim pat : pat = Replace(Mid(fil,2),"'","''")
Dim sit : Set sit = SDB.Database.QuerySongs("AND (Songs.SongPath = '"&pat&"')")
If sit.EOF Then
cret = cret+1
Set itm = SDB.NewSongData
upd = True
If Debug Then Call log.Write("****Creating track: ")
Else
fndt = fndt+1
Set itm = sit.Item
upd = False
If Debug Then Call log.Write("****Updating track: ")
End If
Set sit = Nothing
If upd Then
itm.Path = fil
itm.AlbumName = dat.Item("Album")
itm.ArtistName = dat.Item("Artist")
itm.Year = dat.Item("Year")
itm.Genre = dat.Item("Genre")
itm.Title = dat.Item("Name")
itm.TrackOrder = dat.Item("Track Number")
itm.UpdateDB
itm.UpdateArtist
itm.UpdateAlbum
Dim list : Set list = SDB.NewSongList
Call list.Add(itm)
If ShowBug Then
Call list.UpdateAll()
Else
'UpdateDB saves song to newly created playlist, avoiding possible tag corruption
itm.UpdateDB
End If
End If
If Debug Then Call log.WriteLine(itm.Title&" ("&itm.ID&")")
prog.Text = "iPlaylistImporter: Adding track '"&itm.Title&"'..."
prog.Increase
SDB.ProcessMessages
Call ply.AddTrack(itm)
tot = tot+1
WEnd
End If
Next
'finish off
prog.Text = "iPlaylistImporter: Finalising..."
prog.Value = prog.MaxValue
SDB.ProcessMessages
If Debug Then
Call log.WriteBlankLines(1)
Call log.WriteLine((fndt+cret)&" tracks (found "&fndt&", created "&cret&")")
Call log.WriteLine((fndp+crep)&" playlists (found "&fndp&", created "&crep&")")
If prog.Terminate Then
Call log.WriteLine("**Cancelled by user")
End If
log.Close
End If
If Not prog.Terminate Then
Call SDB.MessageBox("iPlaylistImporter: "&(fndt+cret)&" tracks (found "&fndt&", created "&cret&") added to "&max&" playlists (found "&fndp&", created "&crep&").",mtInformation,Array(mbOk))
End If
End Sub
Function fixhex(str)
fixhex = str
Dim s1,s2,s3,d1,d2,b1,b2,b3
Dim i : i = InStr(fixhex,"%")
While (i > 0)
s1 = Mid(fixhex,i+1,2)
If IsHex(s1) Then
d1 = HexToDec(s1)
s1 = Left(fixhex,i-1)
s2 = Mid(fixhex,i+4,2)
If (Mid(fixhex,i+3,1) = "%") And (IsHex(s2)) Then
d2 = HexToDec(s2)
b1 = DecToBin(d1)
b2 = DecToBin(d2)
If (Left(b1,3) = "110") And (Left(b2,2) = "10") Then
b3 = Mid(b1,4)&Mid(b2,3)
s2 = ChrW(BinToDec(b3))
s3 = Mid(fixhex,i+6)
Else
s2 = Chr(d1)
s3 = Mid(fixhex,i+3)
End If
Else
s2 = Chr(d1)
s3 = Mid(fixhex,i+3)
End If
fixhex = s1&s2&s3
End If
i = InStr(i+1,fixhex,"%")
WEnd
End Function
Function IsHex(h)
IsHex = False
Dim i : i = 0
For i = 1 To Len(h)
If Instr("0123456789ABCDEF",UCase(Mid(h,i,1))) = 0 Then
Exit Function
End If
Next
IsHex = True
End Function
Function HexToDec(h)
HexToDec = 0
Dim i : i = 0
For i = Len(h) To 1 Step -1
Dim d : d = Mid(h,i,1)
d = Instr("0123456789ABCDEF",UCase(d))-1
If d >= 0 Then
HexToDec = HexToDec+(d*(16^(Len(h)-i)))
Else
HexToDec = 0
Exit For
End If
Next
End Function
Function DecToBin(intDec)
DecToBin = ""
Dim d : d = intDec
Dim e : e = 128
While e >= 1
If d >= e Then
d = d - e
DecToBin = DecToBin&"1"
Else
DecToBin = DecToBin&"0"
End If
e = e / 2
Wend
End Function
Function BinToDec(strBin)
Dim d : d = 0
Dim i : i = 0
For i = Len(strBin) To 1 Step -1
Select Case Mid(strBin,i,1)
Case "0"
'do nothing
Case "1"
d = d + (2^(Len(strBin)-i))
Case Else
d = 0
Exit For
End Select
Next
BinToDec = d
End Function
Function gettag(str,tag)
gettag = ""
Dim p1 : p1 = InStr(str,"<"&tag&">")
If p1 > 0 Then
Dim p2 : p2 = InStr(str,"</"&tag&">")
If p2 > 0 And p2 > p1 Then
p1 = p1+Len(tag)+2
gettag = Mid(str,p1,p2-p1)
End If
End If
End Function
Function gettag2(str)
gettag2 = gettag(str,"string")
If gettag2 = "" Then
gettag2 = gettag(str,"integer")
If gettag2 = "" Then
gettag2 = gettag(str,"date")
End If
Else
gettag2 = Replace(gettag2,"&","&")
End If
End Function
Sub Install()
Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
If Not (inif Is Nothing) Then
inif.StringValue("iPlaylistImporter","Filename") = "iPlaylistImporter.vbs"
inif.StringValue("iPlaylistImporter","Procname") = "iPlaylistImporter"
inif.StringValue("iPlaylistImporter","Order") = "30"
inif.StringValue("iPlaylistImporter","DisplayName") = "iPlaylist Importer"
inif.StringValue("iPlaylistImporter","Description") = "Import XML playlists from iTunes"
inif.StringValue("iPlaylistImporter","Language") = "VBScript"
inif.StringValue("iPlaylistImporter","ScriptType") = "0"
SDB.RefreshScriptItems
End If
End Sub
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
Great + Thank you! If you publish I will Test ...
Pauli
Pauli
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
I've responded to your PMs, certainly happy for you to take up the mantle on this one, and I'll help where I can.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
Thanks, trixmoto, and hats off to you for the creation of this very great script!trixmoto wrote:I've responded to your PMs, certainly happy for you to take up the mantle on this one, and I'll help where I can.
I'll post the update in another day or two - we are just trying to decide on best venue, and format, for release.
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
Hi Pauli,Pauli wrote: Another point is that the script always check all files at the playlist with the library but if you often sync your iTunes Plalists with MM it would be nice to skip this in some cases!
Can you expand upon this a bit more?
I think I understand what you are saying, I'd just like to better understand your particular use case.
It sounds like you are having to use iTunes as your main playlist creator, but then you need to use MM to sync devices and iTunes playlists?
Is this because you are syncing to a non-Apple device?
Why do you continually sync Apple playlists to MM, why not just forget about iTunes?
Since I'm taking over support on this script, I'm trying to fix as many things as possible right now.
You will be happy to know that German language support is already fixed. That part was easy.
The reason I haven't released the update yet is because I expanded my testing to include other languages and have found a major problem with Korean, Japanese, Chinese, as well as some simple symbols that use 3-bit unicode character encodings.
If you would like an advance beta version of iPlaylist Importer 1.7 just let me know and I can send you something, prior to the official release.
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
Hi.
Yes I use iTunes as master system, but for several jobs I use MM. So I want to transfer all my Playlists to MM but without resync or control all tracks! All tracks and the mediathek is the same, so the importer must only import all playlists from iTunes.
Another point is to select which playlist to import from iTunes and to MM. Because some playlist are special ones only used at iTunes!
Thanks, Pauli
Yes I use iTunes as master system, but for several jobs I use MM. So I want to transfer all my Playlists to MM but without resync or control all tracks! All tracks and the mediathek is the same, so the importer must only import all playlists from iTunes.
Another point is to select which playlist to import from iTunes and to MM. Because some playlist are special ones only used at iTunes!
Thanks, Pauli
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
If I understand you correctly, this problem is already fixed.Pauli wrote: Yes I use iTunes as master system, but for several jobs I use MM. So I want to transfer all my Playlists to MM but without resync or control all tracks! All tracks and the mediathek is the same, so the importer must only import all playlists from iTunes.
The current version 1.6 was updating tags for every track imported. That is no longer the case.
In upcoming v. 1.7 only the MM library database is updated from iTunes playlist info but this info is never written to the mp3 file tags anymore.
So, if I understand you correctly, you would like the chance to approve every playlist for import or not?Pauli wrote: Another point is to select which playlist to import from iTunes and to MM. Because some playlist are special ones only used at iTunes!
Let me know if this is what you want.
I could add that easily, but, in my case, I have hundreds of playlists and I prefer to simply always update them all, on import, with no dialogs.
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
I think that's it! in 1.6 after importing the playlists every track is checked if the track is in the MM DB and if not it is add - this should be unnecessary.
Selecting the Playlist is a nice to have. So the Playlist of all tracks is importing but nobody need this. So I think a windows with all playlist (default all selected) should be open and there I could deselect some of the list before import is starting. Perfect would be saving the selection future imports.
Regards, Pauli
Selecting the Playlist is a nice to have. So the Playlist of all tracks is importing but nobody need this. So I think a windows with all playlist (default all selected) should be open and there I could deselect some of the list before import is starting. Perfect would be saving the selection future imports.
Regards, Pauli
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
Well, I haven't changed that aspect yet - I only stopped the updating of file metadata tags, not the importing of tracks.Pauli wrote:I think that's it! in 1.6 after importing the playlists every track is checked if the track is in the MM DB and if not it is add - this should be unnecessary.
I think, if you don't want to import tracks from a playlist into MM, you should choose not to import the playlist at all.
That is an option that is the default currently, when the imported playlist name collides with an existing name, though it is not documented.
The current interface is misleading where it asks: "Do you want to overwrite?" actually, if you say YES, the playlist is not overwritten, it is merged with incoming tracks.
Also, it is not explained that, if you say NO, then the playlist import is skipped over, and no tracks in the playlist are added to MM library.
At least, this is my analysis of current behavior. Please correct me if I'm wrong.
Personally, I like being able to import tracks by importing playlists that contain them since the only other option to sync my iTunes with MM libraries is to tell MM to import an entire directory, which may contain files that I have deleted from iTunes library and don't want to import - but my iTunes playlists always reflect the current state that I want to sync with MM.
Ok. I understand what you want.Pauli wrote:Selecting the Playlist is a nice to have. So the Playlist of all tracks is importing but nobody need this. So I think a windows with all playlist (default all selected) should be open and there I could deselect some of the list before import is starting. Perfect would be saving the selection future imports.
This would be nice, but I'm afraid it is beyond my abilities to implement in VBscript.
Probably a different plugin interface would be required to support this.
If you know of any MM plugin that is able to present such an interface, please let me know.
Thanks
Re: iPlaylist Importer 1.6 - Updated 25/05/2008
For example the Backup Plugin (find here at the forum in version 6.0) open different windows for settings etc.!gk wrote:Ok. I understand what you want.
This would be nice, but I'm afraid it is beyond my abilities to implement in VBscript.
Probably a different plugin interface would be required to support this.
If you know of any MM plugin that is able to present such an interface, please let me know.
Thanks
Pauli
Playlists are listed, but no content
Hello -
I'm new to MM and having a difficult time getting playlists imported from iTunes. I have used the plug-in and it imports the files into the library and also imports the playlists' names. But when I open any playlist, it's empty. I've cleared the database several times and started by scratch, using the Add/Rescan function first, and then using the Playlist Import script first. Nothing seems to get the files in the playlists. Other than that, everything seems to be working.
Any ideas??
Thanks.
I'm new to MM and having a difficult time getting playlists imported from iTunes. I have used the plug-in and it imports the files into the library and also imports the playlists' names. But when I open any playlist, it's empty. I've cleared the database several times and started by scratch, using the Add/Rescan function first, and then using the Playlist Import script first. Nothing seems to get the files in the playlists. Other than that, everything seems to be working.
Any ideas??
Thanks.
Last edited by Lowlander on Mon Jun 22, 2015 5:39 pm, edited 1 time in total.
Reason: Merged with existing post
Reason: Merged with existing post