jove
Member
Hello,
I am working on am Apple Script to clean up the MP3 tags using iTunes. Unfortunately, the "path" from the "location" alias object sometimes gives the "#123456" notation. And its not consistent!This is almost as bad as WALKTH~1.MP3. Does anybody know how to extract a clean name from an alias object?
If anybody finds the ideas in the below script useful, please use.
I am working on am Apple Script to clean up the MP3 tags using iTunes. Unfortunately, the "path" from the "location" alias object sometimes gives the "#123456" notation. And its not consistent!This is almost as bad as WALKTH~1.MP3. Does anybody know how to extract a clean name from an alias object?
If anybody finds the ideas in the below script useful, please use.
PHP:
tell application "iTunes"
activate
tell source "Library"
tell playlist "Library"
set the these_tracks to every track
end tell
end tell
repeat with this_track in these_tracks
set this_location to the location of this_track
if this_location is not missing value then
set this_path to this_location as string
set AppleScript's text item delimiters to the ":"
set this_filename to the last text item of this_path
set final_title to my extract_title(this_filename)
if final_title is not "" then
display dialog final_title
-- set the name of this_track to final_title
end if
set final_artist to my extract_artist(this_filename)
if final_artist is not "" then
-- set the artist of this_track to final_artist
end if
set final_genre to my extract_genre(this_filename)
if final_genre is not "" then
-- set the genre of this_track to final_genre
end if
end if
end repeat
end tell
(*
HD:folder:Artist - Title (Genre).mp3
all items except Title are optional
*)
on extract_title(this_filename)
if this_filename contains "-" then
set AppleScript's text item delimiters to "-"
set this_title to the second text item of this_filename
else
set this_title to this_filename
end if
if this_title contains "(" then
set AppleScript's text item delimiters to "("
set this_title to the first text item of this_title
end if
if this_title contains "." then
set AppleScript's text item delimiters to "."
set this_title to the first text item of this_title
end if
-- if this_title contains "#" then
-- set this_title to ""
-- end if
return this_title
end extract_title
on extract_artist(this_filename)
if this_filename contains "-" then
set AppleScript's text item delimiters to "-"
set this_artist to the first text item of this_filename
else
set this_artist to ""
end if
return this_artist
end extract_artist
on extract_genre(this_filename)
if this_filename contains "(" then
set AppleScript's text item delimiters to "("
set this_genre to the last text item of this_filename
set AppleScript's text item delimiters to ")"
set this_genre to the first text item of this_genre
else
set this_genre to ""
end if
return this_genre
end extract_genre