convert "file://localhost..." urls into paths?

OK, here’s the deal. I have file locations in URL form:

file://localhost/Users/spark/Music/iTunes/iTunes%20Music/Tobin,%20Amon/Permutation/08%20People%20Like%20Frank.m4a

I need the path forms:

/Users/spark/Music/iTunes/iTunes Music/Tobin, Amon/Permutation/08 People Like Frank.m4a
Macintosh HD:Users:spark:Music:iTunes:iTunes Music:Tobin, Amon:Permutation:08 People Like Frank.m4a

I want a way to get Applescript (Tiger) to do all the conversion work for me. No string manipulation, no handlers to unescape %XX, no stripping “localhost”, no osaxen, no figuring out which application understands which file types, nothing. That is, what I really want is just a type coercion, like:

return path of (theURL as alias)

Of course that doesn’t work. But surely the necessary functions are hiding in here somewhere. Any ideas?

'Fraid not. You’ll need to roll your own, e.g.:

on urlToPOSIXPath(theURL)
	return do shell script "python -c \"import urllib, urlparse, sys; print urllib.unquote(urlparse.urlparse(sys.argv[1])[2])\" " & quoted form of theURL
end urlToPOSIXPath

urlToPOSIXPath("file://localhost/Users/spark/Music/iTunes/iTunes%20Music/Tobin,%20Amon/Permutation/08%20People%20Like%20Frank.m4a")
--> "/Users/spark/Music/iTunes/iTunes Music/Tobin, Amon/Permutation/08 People Like Frank.m4a"

"/Users/spark/Music/iTunes/iTunes Music/Tobin, Amon/Permutation/08 People Like Frank.m4a" as POSIX file as Unicode text
--> "Macintosh HD:Users:spark:Music:iTunes:iTunes Music:Tobin, Amon:Permutation:08 People Like Frank.m4a"