Fixing iTunes M3U handling gone awry

I am very new to AppleScript, but I am an experience programmer.

Many of you may have noticed the awful way that iTunes handles .m3u playlists of remote files. It tries to add them to the main library as if they were local songs, and as soon as the first file of the .m3u is played its metadata is retrieved and the song is moved into the same order as the rest of the library, effectively moving it away from the other tracks in the .m3u so that you can never play a .m3u file in order.

I found the script below and it was working perfectly until the 7.6 update. The script creates a new playlist named for the current date and time and then adds the tracks to it in the original order. Here’s the code:

on open m3uFileList
	tell application "iTunes"
		set newPlaylist to make new user playlist
		set name of newPlaylist to (current date) as string
		repeat with m3uFile in m3uFileList
			add m3uFile to newPlaylist
		end repeat
		play newPlaylist
	end tell
end open

When this script runs now I get the following error:

I can’t for the life of me figure out what is going wrong. The line that appears to be causing this problem is “add m3uFile to newPlaylist”.

Any help would be greatly appreciated. Thanks!

Use duplicate when adding to a playlist. Not logical, but it’s the verb that works! :slight_smile:

EDIT: I realized after posting that I missed that you’re adding a local file, not a track. You probably need to add the file to library playlist 1 and then use duplicate to copy it to the playlist you’re building.

The following code produces the same error:

repeat with m3uFile in m3uFileList
		add m3uFile to library playlist 1
end repeat

If I skip the repeat list and just try to add the m3uFileList to the library playlist 1 I get a “Parameter Error.”

This is incredibly frustrating. :frowning:

Is it just one m3u file you’re fighting with, or have you tried others? Could be a faulty file, I suppose, but I will try downloading an m3u from some place like Shoutcast and see if I can get it to work.

Ok, after a bit of trial and error (mostly in finding an M3U file to use!), here’s a script snippet that works for me, adding the M3U to the library and then successfully copying the resulting track to the user playlist.

set myM3U to "Morpheus:Users:nitewing98:Downloads:wfmu.m3u"
tell application "iTunes"
	set myTrack to add file myM3U to library playlist 1
	duplicate myTrack to user playlist "my Radio"
end tell

Remember, once you import the M3U, from iTunes’ perspective it’s not a file anymore, it’s a track.

The m3u files I am trying to load have multiple tracks. Would the same method apply in that case?

When I try this:

set newPlaylist to make new user playlist
		set name of newPlaylist to (current date) as string
		repeat with m3uFile in m3uFileList
			set myTrack to add file m3uFile to library playlist 1
			duplicate myTrack to newPlaylist
		end repeat
		play newPlaylist

I get an error that says:

“A descriptor type mismatch occurred.”

When I simplified the code to debug, I found that the error happens on the “set myTrack to…” line.

Thank you, by the way, for all your help.

What’s the genesis of this M3U file? Are you building a custom playlist file yourself using local tracks or is this a pointer to an internet stream? That might make the difference. The file I used was just a wrapper for a URL stream and it sounds like this is not what you’re doing.

If you want to shoot me a copy of the file (either pasted into an email, posted here, or via iChat/Adium/AIM [as “nitewing98”]) let me know and I’ll take a deeper look at it.

OK, here’s an interesting twist: iTunes no longer opens the .m3u files I’m working with directly. I set iTunes to be the default application for all .m3u files, and when I double-click on one (which was freshly created by my streaming software, MyTunesRSS) it doesn’t do anything except bring iTunes to the front.

I’m running iTunes 7.6 on OS X 10.4.11


So, it seems that my iTunes installation is broken somehow. M3U lists are not loaded at all, even when opened with iTunes directly. Reinstalling iTunes didn’t fix the problem.

When you say

I’m curious what you mean. By default, my copy of iTunes 7.6 handled your M3U file correctly.

My question really is, how much tinkering, customization, etc. have you done with either a) iTunes or b) the OS’s file types? Either of those could be affecting your experiments with the M3U file.

One thought - create a separate user account (temporarily) and test iTunes’ reaction to this file under “clean” conditions. It could very well be that your current user login is overly customized and that’s causing problems.