OK, I've done It by myself
Description:
You may have collected your albums on your PC as cue-sheet-file + wavs for each track.
If you drop one or more of these cue-sheets on this script, each track will be imported to iTunes as lossless and as AAC coded tracks. Two playlists will be created. The one with the "°" indicates, that this playlist contains the lossless files. Playlist is "Album-Artist - Album Title" or "Album Title" if the album is a compilation.
During import, album, album-performer, title, title-performer, genre, date, track-number, etc will be set.
The Compilation-flag will be set, if performer is "VA", "Various" or "Various Artists".
If the album-title is something like "Title - CD4", then the CD-number is set as well.
If the album-title is something like "Title - CD4 - Grouping", then grouping is set as well.
If the album-title is something like "Artitst - Title", then album-title will be set as "Title" only.
The Gapless-flag will alway be set.
If tracks cannot be found, the script asks for their location.
The cue-files must be written by PC (ISO-8859-1 encoding) and not by Mac before using this script, otherwise you may have problems with special characters.
After executing the script each cue-file will be converted to macintosh encoding. You will find a .cue.txt file with the new encoding.
The script works with non-compliant cue-sheets created by Exact-Audio-Copy.
Hope, someone will find it useful.
CODE
(*
"ImportCue2iTunes"
v1.0 june 2 2008
*)
global oneDay
on open theItemsList
tell application "iTunes" to activate
set encoderList to {"Lossless Encoder", "AAC Encoder"}
set titleExtensions to {" °", ""}
set oneDay to 60 * 60 * 24
repeat with theItem in theItemsList
with timeout of oneDay seconds
set theFile to POSIX path of theItem
set cuePath to POSIX path of getParentPath(theItem)
if not folder of (info for theItem) then
set fileOK to true
try
do shell script "/usr/bin/textutil -convert txt -encoding macintosh -inputencoding ISO-8859-1 -extension CUE.txt " & quoted form of POSIX path of theItem
set theMacFile to (POSIX path of theItem) & ".txt"
set paragraphList to read POSIX file theMacFile using delimiter {ASCII character 10, return}
on error
set fileOK to false
end try
if fileOK then
set albumRecord to {albumTitle:"", albumGrouping:"", albumArtist:"", trackCount:0, discNumber:1, discCount:0, albumYear:2008, albumGenre:"", isCompilation:false, isGapless:true}
set trackRecord to {trackTitle:"", trackArtist:"", trackNumber:0, trackPath:"", trackRef:"", originalTrack:"", iTunesTrack:""}
set trackList to {}
set tracksReached to false
set trackComplete to false
set trackNumberCounter to 1
set nearlyComplete to false
set exited to false
repeat with oneLine in paragraphList
if not tracksReached then
set albumGenreTmp to getValue("REM GENRE", oneLine)
if albumGenreTmp is not equal to "" then set albumGenre of albumRecord to albumGenreTmp
set albumYearTmp to 0
try
set albumYearTmp to getValue("REM DATE", oneLine) as number
end try
if albumYearTmp is not equal to 0 then set albumYear of albumRecord to albumYearTmp
set albumArtistTmp to getValue("PERFORMER", oneLine)
if (albumArtistTmp is equal to "Various") or (albumArtistTmp is equal to "VA") then set albumArtistTmp to "Various Artists"
if albumArtistTmp is not equal to "" then set albumArtist of albumRecord to albumArtistTmp
if albumArtistTmp is equal to "Various Artists" then set isCompilation of albumRecord to true
set albumTitleTmp to getValue("TITLE", oneLine)
if albumTitleTmp is not equal to "" then set albumTitle of albumRecord to albumTitleTmp
set trackPathTmp to getValue("FILE", oneLine)
if trackPathTmp is not equal to "" then
set tracksReached to true
set atTemp to getValue((albumArtist of albumRecord) & " -", (albumTitle of albumRecord))
if atTemp is not equal to "" then set albumTitle of albumRecord to atTemp
set atTemp to albumTitle of albumRecord
set x to offset of " - CD" in atTemp
if x is not equal to 0 then
set restOfTitle to text (x + 5) thru (length of atTemp) of atTemp
if (x - 1) is greater than 0 then
set atTemp to text 1 thru (x - 1) of atTemp
else
set atTemp to ""
end if
set albumTitle of albumRecord to atTemp
set x to offset of " - " in restOfTitle
if x is equal to 0 then
try
set discNumber of albumRecord to restOfTitle as number
end try
else
try
if (x - 1) is greater than 0 then set discNumber of albumRecord to (text 1 thru (x - 1) of restOfTitle) as number
end try
set albumGrouping of albumRecord to text (x + 3) thru (length of restOfTitle) of restOfTitle
end if
end if
end if
end if
if tracksReached then
set index01 to getValue("INDEX 01", oneLine)
if index01 is not equal to "" then set nearlyComplete to true
set trackStatement to getValue("TRACK", oneLine)
if trackStatement is not equal to "" then
set trackType to text 4 thru (length of trackStatement) of trackStatement
if trackType is not equal to "AUDIO" then exit repeat
if nearlyComplete then set trackComplete to true
end if
set trackPathTmp to getValue("FILE", oneLine)
if trackPathTmp is not equal to "" then
if nearlyComplete then set trackComplete to true
end if
if trackComplete then
set trackNumber of trackRecord to trackNumberCounter
copy trackRecord to the end of trackList
set trackNumberCounter to trackNumberCounter + 1
set trackComplete to false
set nearlyComplete to false
end if
if trackPathTmp is not equal to "" then
set trackPath of trackRecord to (cuePath & trackPathTmp)
set fileExists to false
tell application "Finder" to if exists trackPath of trackRecord as POSIX file then set fileExists to true
if not (fileExists) then
set defaultLocation to (POSIX file cuePath)
activate
try
with timeout of oneDay seconds
set aFile to choose file with prompt "File '" & trackPathTmp & "' does not exist" default location defaultLocation
set trackPath of trackRecord to (the POSIX path of aFile)
end timeout
on error number -1712
set exited to true
exit repeat
end try
end if
end if
set trackTitleTmp to getValue("TITLE", oneLine)
if trackTitleTmp is not equal to "" then set trackTitle of trackRecord to trackTitleTmp
set trackArtistTmp to getValue("PERFORMER", oneLine)
if trackArtistTmp is not equal to "" then set trackArtist of trackRecord to trackArtistTmp
end if
end repeat
if not exited then
set trackNumber of trackRecord to trackNumberCounter
set trackCount of albumRecord to trackNumberCounter
copy trackRecord to the end of trackList
set iTunesTrackList to {}
repeat with oneRecord in trackList
addToItunes(albumRecord, oneRecord)
copy iTunesTrack of oneRecord to the end of iTunesTrackList
end repeat
set encoderCount to 1
repeat with oneEncoder in encoderList
set titleExtension to item encoderCount of titleExtensions
convertTracks(iTunesTrackList, albumRecord, trackList, oneEncoder, titleExtension)
set encoderCount to encoderCount + 1
end repeat
tell application "iTunes"
repeat with oneTrack in trackList
delete (some track of library playlist 1 whose database ID is (get database ID of (originalTrack of oneTrack)))
end repeat
end tell
end if
end if
end if
end timeout
end repeat
end open
on run
display dialog "Drop a copliant CUE-sheet on this Apple Script"
end run
to convertTracks(iTunesTrackList, albumRecord, trackList, iTunesEncoder, titleExtension)
with timeout of oneDay seconds
tell application "iTunes"
set encoderBackup to name of current encoder
set current encoder to encoder iTunesEncoder
set convertedList to (convert iTunesTrackList)
delay 5
if (isCompilation of albumRecord) then
set newPlaylistName to albumTitle of albumRecord
else
set newPlaylistName to (albumArtist of albumRecord) & " - " & (albumTitle of albumRecord)
end if
-- if iTunesEncoder is equal to "Lossless Encoder" then set newPlaylistName to newPlaylistName & " °"
set newPlaylistName to newPlaylistName & titleExtension
if not (exists user playlist newPlaylistName) then
make new playlist with properties {name:newPlaylistName}
end if
set newPlaylist to user playlist newPlaylistName
repeat with oneTrack in convertedList
duplicate oneTrack to newPlaylist
if titleExtension is not equal to "" then set album of oneTrack to (album of oneTrack & titleExtension)
end repeat
set current encoder to encoder encoderBackup
end tell
end timeout
end convertTracks
to addToItunes(albumRecord, trackRecord)
set trackRef of trackRecord to POSIX file (trackPath of trackRecord)
with timeout of oneDay seconds
tell application "iTunes"
set originalTrack of trackRecord to (add (trackRef of trackRecord))
set iTunesTrack of trackRecord to (location of (originalTrack of trackRecord))
set name of originalTrack of trackRecord to (trackTitle of trackRecord)
set artist of originalTrack of trackRecord to (trackArtist of trackRecord)
set album of originalTrack of trackRecord to (albumTitle of albumRecord)
set album artist of originalTrack of trackRecord to (albumArtist of albumRecord)
set track number of originalTrack of trackRecord to (trackNumber of trackRecord)
set track count of originalTrack of trackRecord to (trackCount of albumRecord)
set disc number of originalTrack of trackRecord to (discNumber of albumRecord)
set disc count of originalTrack of trackRecord to (discCount of albumRecord)
set year of originalTrack of trackRecord to (albumYear of albumRecord)
set genre of originalTrack of trackRecord to (albumGenre of albumRecord)
set compilation of originalTrack of trackRecord to (isCompilation of albumRecord)
set gapless of originalTrack of trackRecord to (isGapless of albumRecord)
set grouping of originalTrack of trackRecord to (albumGrouping of albumRecord)
end tell
end timeout
end addToItunes
to getValue(tid, tvar)
set tvarTmp to tvar
set tvar to " " & tvar
set x to offset of " " in tvar
repeat while (x is equal to 1) and (length of tvar is greater than 2)
set tvar to text 2 thru (length of tvar) of tvar
set x to offset of " " in tvar
end repeat
if (tvar is equal to " ") then set tvar to ""
set x to offset of tid in tvar
if x is equal to 1 then
set x to (length of tid) + 2
if (length of tvar) + 1 is greater than x then
set tvar to text x thru (length of tvar) of tvar
else
set tvar to ""
end if
set x to offset of "\"" in tvar
if x is greater than 0 then
set x to x + 1
if (length of tvar) + 1 is greater than x then
set tvar to text x thru (length of tvar) of tvar
end if
set x to offset of "\"" in tvar
if x is greater than 1 then
set x to x - 1
set tvar to text 1 thru x of tvar
else
if x is equal to 1 then set tvar to ""
end if
end if
else
set tvar to ""
end if
return tvar
end getValue
on getParentPath(aFile)
with timeout of oneDay seconds
tell application "Finder" to return container of aFile as text
end timeout
end getParentPath