how to convert all the songs in my I-Tunes (on a Windows PC) which are Wav files over to Apple Lossless files.

GO TO ADMIN PANEL > ADD-ONS AND INSTALL VERTIFORO SIDEBAR TO SEE FORUMS AND SIDEBAR

soundhd

New member
Joined
Nov 30, 2005
Messages
23
Points
1
Age
75
Location
Ann Arbor
Have a PC with Windows 10. My I-Tunes has all Wav files. I pretty much use I-Tunes for loading music onto my I-Pods. Has worked fine up till recently where the 160 GB IPods can no longer handle all the songs so my options are delele some songs (which I would rather not do) or convert all the songs over to the Apple Lossless format to hopefully make more room for more songs. Now I figured out how to convert one song at a time but when I do that it also leaves the Wav version in place and I would have to delete it manually. Wondering if there is a way to convert all the songs (over 3500 songs) and at the same time delete all the Wav file songs. Do not have enough room on my PC's hard drive for both versions at the same time. Thanks
 

cjmnews

Moderator
Staff member
Moderator
Joined
Apr 26, 2006
Messages
10,061
Points
63
Location
Arizona
The easiest option is to get a bigger drive or make room on the existing drive by backing up data to external drive or DVD and deleting it. Restoring the data after the conversion.

If you can’t make more space, then there should be a way to script iTunes to convert and delete at the same time. I will look at my existing scripts to see what can be done.

Let me know if you need the in place conversion and I will write a script if it is possible.
 

soundhd

New member
Joined
Nov 30, 2005
Messages
23
Points
1
Age
75
Location
Ann Arbor
First thank you very much for replying to my posting. Please understand that I am an "older" person and not very versed on computer software. The "inplace conversion" I assume is a way to convert the Wav files to the Apple Lossless format and delete the existing Wave file versions? It sounds perfect but does one need to be an computer expert to be able to use the "program" you are talking about? Again the problem is not with the size of the hard drive in my PC, the issue is my 160 GB IPods are full and the only way to get more tracks into them is to reduce the space needed in my I-Tunes (3555 songs) by converting over to the Apple Lossless format (still want the songs to sound as best I can) so I can still have all the songs on my IPod(s).
 

cjmnews

Moderator
Staff member
Moderator
Joined
Apr 26, 2006
Messages
10,061
Points
63
Location
Arizona
You said you didn't have space on your PC's hard drive for the second set of the 3500 tracks at 70% of the size of the WAV files. ALAC files are approximately 30% smaller than their WAV form.

Since it seem you are unable or unwilling to move data to make space for the easy conversion, then you'll have to do some advanced things to run a script I will have to write.

There seems to be a ConvertTrack method in iTunes that I could use. So basically, you'll have to edit your iTunes Preferences, to set the Import Settings to use Apple Lossless. Then run the script.

Now I have to write a script to either use what you select or find all WAV files in your library. I typically make the user select the tracks as I think the user knows what they want to alter better than automatically selecting data in iTunes.

The script will convert the track from it's current form, to Apple Lossless, then delete the WAV. Since I am using iTunes to delete, there may be a prompt to see if you want to recycle the song or not, I will see later when I run the script on my system. Since there is not enough room on the PC drive for the new track and the original WAV, then you may be required to click NO 3555 times. Not sure yet.

I will provide instructions on how to run the script.

You need to make a backup of the WAV files in case there is a catastrophic failure, since you don't have room for a second copy of these files they need to be somewhere else, like an external hard drive, CD or DVD. You'll need to figure out your own backup solution. I suppose the iPods are a backup, but I would rather have to instruct an "older" person on how to pull tracks off of an iPod.

Off to make a few hundred WAV files in my system to test with. Then start writing the script. This may take a day or three. I have never made a destructive (delete) script before.
 

cjmnews

Moderator
Staff member
Moderator
Joined
Apr 26, 2006
Messages
10,061
Points
63
Location
Arizona
Bad news so far, but I am still looking at it.

iTunes will not let the script delete the track. I get an error that the playlist is not modifiable. I don't even have an official playlist, just selected tracks.
Deleting the file directly in the script is also blocked. This is a safety mechanism to stop websites from telling your browser to delete files through JavaScript.

I am looking at rewriting it into sections. Though I am not sure how to make it work yet.
Some sort of nested scripts to enable the delete of the files, but I need to figure out how to make it work for different albums and folders.

My quick attempt has failed.
 

cjmnews

Moderator
Staff member
Moderator
Joined
Apr 26, 2006
Messages
10,061
Points
63
Location
Arizona
I have a solution that seems to be working. 3 scripts, and when it is done, cleanup of iTunes afterwards.

I have another thought that may make iTunes do the conversion and deletion of the tracks, this would eliminate your need to manually clean up iTunes after the conversion process.

I will need to test it out to be sure.

Both versions currently assume that you want ALL the WAV files in iTunes converted and deleted. Is that true? Or do you want to select the tracks to be converted?
 

soundhd

New member
Joined
Nov 30, 2005
Messages
23
Points
1
Age
75
Location
Ann Arbor
Thanks for the replies. Just checked my hard drive (it is a 1 TB). Properties show 241 GB free of 903 GB. And yes I did try the I-Tunes built in conversion with one track and it worked fine but it also left the Wav file track in place so I would have to delete each Wav track manually......Note: Maybe I messed something but could not see a way to convert more than one track at a time. By the way my I-Tunes takes up 302 GB of space. (over 3400 songs.....7,074 Files, 2,393 Folders)
I want to hopefully have all Apple Lossless files when all is said & done...only way that I can keep all the songs that I have now and still be able to add more (which is something I do sparingly) and be able to get all the songs on my 160 GB IPod(s) (I own four of them and they all have the same songs on them)

thanks
 

cjmnews

Moderator
Staff member
Moderator
Joined
Apr 26, 2006
Messages
10,061
Points
63
Location
Arizona
My final test also failed as iTunes does not remove the file from the hard drive, just from iTunes. I can't seem to force it to delete the file either.

So, we are using 3 scripts.
  1. Get a list of all WAV files in your iTunes and put it in a temporary file
  2. Convert a single file with iTunes from WAV to the Import Setting.
  3. Process the temporary file, call the convert script and delete the file.
I am still trying to make it bullet proof, getting script 3 to stop if script 1 detects a bad iTunes import setting (not Apple Lossless) is my current issue.

The conversion process and deletion seems to work.

There will be an iTunes clean up process afterwards. Unless I create a 4th clean up script.
Also, any playlist you have will need to be re-populated with the converted tracks. I may be able to make the clean up script do this. Let me know if you need playlists updated as well.

You didn't answer my question. Is it OK that the script will convert and delete ALL WAV files?
 

soundhd

New member
Joined
Nov 30, 2005
Messages
23
Points
1
Age
75
Location
Ann Arbor
Thanks for all your help, guess I will just have to do the conversion one song at a time...will give me something to do next winter (I live in Michigan and don't "do" winter any more.....LOL)
Guess I am surprised that Apple did not set the I-Tunes system up in such a way to convert everything at once or be able to select more than one song to convert........would imagine I am not the first one trying to do this...
 

cjmnews

Moderator
Staff member
Moderator
Joined
Apr 26, 2006
Messages
10,061
Points
63
Location
Arizona
I have the conversion process working with no issues.

I have started on an automatic iTunes clean up.

You didn't answer my question. Is it OK that the script will convert and delete ALL WAV files?
 

soundhd

New member
Joined
Nov 30, 2005
Messages
23
Points
1
Age
75
Location
Ann Arbor
So how does one go about using this process? Is there a way you could send me step by step directions?
 

cjmnews

Moderator
Staff member
Moderator
Joined
Apr 26, 2006
Messages
10,061
Points
63
Location
Arizona
Since you won't answer the question I asked above 3 times, I am assuming you want ALL WAV files converted and deleted. The other option was to do selected groups of WAV files.

In-place WAV to ALAC conversion, where WAV files are PERMANENTLY DELETED as they are converted.

Usage:
For low disk space iTunes installations where standard conversion cannot be used due to lack of space for both the WAV and ALAC versions of the music.

Caution: This is a DESTRUCTIVE process. WAV files will be PERMANENTLY DELETED. This site and the author are NOT responsible for loss of your data through using these scripts. All playlists that contained WAV files will no longer play the WAV files since they were deleted.

Clean up: The user must clean up the WAV files in the iTunes Library manually (the clean up script was not completed as of the original posting, it may get written in a few days if time allows). The user must also update any playlists that used WAV files to use the new ALAC files instead. (a good clean up script would alter all standard playlists as well, but the requestor seems to want a conversion solution now instead of waiting for a full clean solution)


Overview of the process:
  1. ConvertWAV_ALAC.bat - This is the code the user executes. It calls ListWAVFiles.js then parses the list of WAV files 1 at a time and calls WAVtoALAC.js then deletes the WAV file from the hard drive, but not iTunes.
  2. ListWAVFiles.js - Verifies the user set Apple Lossless Encoder in the Import Settings, and builds a list of the full path to all the WAV files in the iTunes library, and writes it to a temporary file in C:\Windows\Temp named WAV_path_list.txt
  3. WAVtoALAC.js - Converts a single track by full path, waiting for the conversion process to complete.
Potential errors:
  • WAV files that were already deleted from the hard drive or do not exist and are still listed in iTunes are not processed (iTunes will have an exclamation mark ! to the right of these tracks)
  • WAV files that are corrupted will cause the WAVtoALAC.js script to run forever, stopping the conversion and deletion process. The user must stop the script (Type Ctrl-C in the command prompt, answer Yes to terminate the program) then find (by playing WAV files that have not been converted yet, the corrupt one will not play, and deleting the WAV file from iTunes before starting the conversion process again).
  • Failure to remove the _ in the word Active in ListWAVFiles.js may cause deletion of all WAV files without conversion. This mangling was required to allow the website to post this code.
Assumptions:
  • All WAV files are backed up to another location to recover IF the scripts do not work on your system.
  • All WAV files are known to be good and playable by iTunes.
Scripts:

ConvertWAV_ALAC.bat
Code:
@ECHO OFF

REM Get list of all WAV files in the library.
CScript /nologo ListWAVFiles.js

IF ERRORLEVEL 1 GOTO QUIT

REM Loop through all the WAV files and convert each one to ALAC, then delete it
FOR /F "usebackq tokens=*" %%A IN (`type WAV_path_list.txt`) DO (

  CScript /nologo WAVtoALAC.js %%A
  DEL %%A

)

ECHO Done
:QUIT
@ECHO ON
ListWAVFiles.js
Code:
var iTunesApp = WScript.CreateObject("iTunes.Application");
var mainLibrary = iTunesApp.LibraryPlaylist;
var    tracks = mainLibrary.Tracks;
var    numTracks = tracks.Count;
//var tracks = iTunesApp.SelectedTracks;
//var numTracks = tracks.Count;  // If an error is seen on Line 4 character 1, the user failed to select tracks in iTunes
var i;
var fileAndPath;
var encoder;

// Check that the user set ALAC encoder
encoder = iTunesApp.CurrentEncoder;

if (encoder.Name != "Lossless Encoder") {
    WScript.Echo("Edit->Preferences, Import Settings must be set to Apple Lossless Encoder");
    WScript.Quit(1);
}

//  Configuration is correct
else {

    // Store a list of files to be converted and deleted in a temp file
    var filesystem
    filesystem = new A_ctiveXObject("Scripting.FileSystemObject");
  
    //  Delete any previous copies
    var cleanup = filesystem.GetFile("C:\\Windows\\Temp\\WAV_path_list.txt");
    cleanup.Delete();
  
    // Create the file
    var outFile = filesystem.CreateTextFile("C:\\Windows\\Temp\\WAV_path_list.txt",2,true);
  
    //  Loop through all tracks and output the full path where they exist into a file
    for (i = 1; i <= numTracks; i++)
    {
        var currTrack = tracks.Item(i);
        if (currTrack.KindAsString  == "WAV audio file") {
            fileAndPath = currTrack.Location;
          
            // Don't add songs that have already been converted and deleted, that iTunes are still listed in iTunes.
            if (fileAndPath.length > 0) {
                // Put quotes around the path in case of spaces
                outFile.WriteLine('"' + fileAndPath + '"');
            }
        }
    }
    outFile.Close();
}
WAVtoALAC.js
Code:
var iTunesApp = WScript.CreateObject("iTunes.Application");
var fileAndPath = WScript.arguments.item(0);

// Use the Import settings to convert the file
iTunesApp.ConvertFile2(fileAndPath);

// Wait for the conversion to be complete before exiting
while (iTunesApp.ConvertOperationStatus+"" != "null");
Steps to Install locally:
  1. Find a place to store these scripts on your system, it is preferable you make a folder for them.
  2. Open Notepad or other text editor on your computer.
  3. Copy all the text in one of the above code sections.
  4. Paste the text into Notepad.
  5. Click on File->Save As
  6. In the left and top of the Save As dialog, navigate to the folder you created above in step 1.
  7. In the bottom of the Save As dialog, change the Save as type: to All Files
  8. Just above that type (or copy/paste) in the file name above the section of code.
  9. Click the Save button.
  10. Repeat for all 3 code segments.
  11. Open File Explorer in the folder where the scripts are stored, verify the full name and extension is identical to the names listed on this page. Any misspelling or typos or an extension of .txt will cause these scripts to fail to do anything. In File Explorer, you can click on the View tab, then near the far right, there is a check box next to File name extensions put a check in that box to see the extension. If you see something like WAVtoALAC.js.txt then rename the file to be WAVtoALAC.js and answer YES to changing the extension/file type.
  12. Important: Edit the ListWAVFiles.js file and remove the _ in the word "A_ctive" I had to add the _ to allow the website to post the code. Missing this step will cause the scripts to fail, possibly deleting ALL WAV files without conversion!!!!!!
Steps to run:
  1. Open iTunes
  2. Open a Command Prompt
  3. In the Command Prompt navigate to where the scripts were saved.
    1. Use File Explorer in the scripts folder to get the location by clicking in the bar where the folder name is. It usually starts with This PC.
    2. Once you click in there the This PC goes away and it shows the full path. Type Ctrl-C to copy it.
    3. Click in the Command Prompt
    4. Type CD and a space
    5. Right click the mouse in the Command Prompt to paste the full path copied from File Explorer.
    6. Press the Enter/Return key to complete the task
  4. If there was no error message displayed, then the script should be ready to run.
  5. Type DIR and press the Enter/Return key
  6. The list of files shown should match the files listed above, there will be other data about the files, but the names are important.
    1. ConvertWAV_ALAC.bat
    2. ListWAVFiles.js
    3. WAVtoALAC.js
  7. If any of the files end in .txt, you need to rename them so they match the list above.
  8. Type ConvertWAV_ALAC.bat and press the Enter/Return key.
  9. Turn your speakers off as the conversion process will beep for every track, and wait for it to complete.
Optional Task:
  • Update standard playlists to replace WAV files with ALAC files.
Steps to clean up iTunes:
  1. Click on Songs in iTunes
  2. Look for a column named Kind
    1. If Kind does not appear
      1. Right click on the column named Name
      2. In the popup window click on Kind so that there is a check mark next to it.
  3. Click on the column name Kind to sort by Kind.
  4. Scroll until the first track with the "WAV audio file" Kind is seen and click on that track.
  5. Scroll until the last track with the "WAV audio file" Kind is seen.
    1. Hold SHIFT key
    2. Click on the last track
    3. Release the SHIFT key
    4. Tap the Del or DELETE key.
    5. Click on Delete Songs
 

soundhd

New member
Joined
Nov 30, 2005
Messages
23
Points
1
Age
75
Location
Ann Arbor
Thank you for all the instructions.....hopefully I can figure it all out....."older" guy...LOL You probably missed it but I did answer your question about all the files

(I want to hopefully have all Apple Lossless files when all is said & done...only way that I can keep all the songs that I have now and still be able to add more (which is something I do sparingly) and be able to get all the songs on my 160 GB IPod (s I own four of them and they all have the same songs on them)

in my last reply. Thanks again and maybe someone else will have the same issue/problem......still think that Apple (with all their technology) would have put that option in with I-Tunes...I cannot believed that I would be the only one having this issue. Anyway thanks so much for your time.
A dedicated I-Pod user
 

cjmnews

Moderator
Staff member
Moderator
Joined
Apr 26, 2006
Messages
10,061
Points
63
Location
Arizona
You can of course do this manually without my script 1 track at a time.
  1. Convert a track
  2. Optionally, move the new track to any playlists that used the converted track
  3. Delete the track in iTunes
  4. Answer Yes to move to recycle bin
  5. Manually empty the Recycle Bin
  6. Start again with Step 1.
That is the Apple option for those with limited disk space such as yourself.

My script will perform this on all tracks and does not use the recycle bin. That is the difference.
 
Top