I recently consolidated my iTunes Library and now many videos have a "1" at the end of the file name. And weirdly, in the media library, there are two files - one with the "1" and one without. Luckily only one video appears in iTunes. Is there some way to clean up my media folder AND the filenames in itunes?
-
And in some cases, iTunes put a "2" after the file name in the library. By "1" and "2" I mean that there is a space, and then a 1 or 2. Kind of like when you add a file to a folder and the Finder asks if you wish to keep both, it adds a number.– isaunders501Commented Mar 16, 2013 at 16:55
-
Potential solutions exist but it heavily depends on the number of impacted files. Are we talking about a handful or hundreds?– nohillside ♦Commented Mar 16, 2013 at 19:32
3 Answers
I just use a quick and dirty AppleScript to do things like this:`
-- BP Jan 2014
-- Trims a set number of characters from the Start of track names in an iTunes playlist
-- Or trims a set number of characters from the End of track names in a playlist
-- Or adds a prefix to each track name in a playlist.
-- Or adds a suffix to each track name in a playlist.
-- Trims take precedence over adds
-- It's best to do just one operation at a time, and set all the other variables to "" or 0 as appropriate.
--------------------------------- User settable variables
set PlaylistName to "AAA" -- Just add the tracks you want to change to a single playlist. When dione, delete the playlist.
set trimInitialchars to 0 -- nonzero value takes precedence over any addstart value
set trimFinalchars to 0
set addstart to "" -- nonempty value wil overide addend
set addend to ""
--------------------------------- End of user settable variables
set trimstart to trimInitialchars + 1
tell application "iTunes"
activate
set tracklst to every track of playlist PlaylistName
set trackcount to number of items in tracklst
repeat with n from 1 to trackcount -- Do the whole playlist:
set oldtitle to name of track named (name of item n of tracklst)
if trimInitialchars is greater than 0 then -- Trim stuff from front of track names
set name of (item n of tracklst) to (characters trimstart through length of oldtitle) as text
else if trimFinalchars is greater than 0 then -- Trim stuff from front of track names
set name of (item n of tracklst) to (characters 1 through ((length of oldtitle) - trimFinalchars) of oldtitle) as text
else if addstart is not "" then -- Add something to front of track names
set name of (item n of tracklst) to (addstart & oldtitle)
else if addend is not "" then -- Add something to end of track names
set name of (item n of tracklst) to (oldtitle & addend)
end if
end repeat
end tell`
I had a similar issue recently when I moved my media files from my computer's internal hard drive to an external hard drive. The problem occurred when I first manually moved all the folders under USERNAME/Music/ on my computer to a folder on my external drive, opened the Music application on my computer (formerly iTunes) while holding the option key, changed the library to refer to the copied library now in the external drive, and under File > Organize Library..., checking "Consolidate files" and clicking ok. This created the exact same issue where I ended up with duplicates of all the songs in the new copy of the iTunes Media folder with a one (1) at the end of each duplicate file. These duplicates were the ones being referred to by each song in my library, and the originals did not show up when I checked for duplicate songs on the Music Application.
Here is how I got rid of the duplicates using only the Music application on my computer and two different folder locations, the original location and a new location. In my case, the original folder location is on my external drive, where I want my files to be now, and the new one is in a temporary folder on my internal drive, but you can change this to meet your needs.
NOTE: If you use two folders in the same drive, make sure you have enough space on the drive for two copies of your music files.
- When in the Music application, go to the Music menu, choose Preferences, and go to the Files tab.
- Under Music Media folder location, click Change…, then go from the original folder where the music currently resides to the new folder to where the music will be moved (this may be from the external drive’s folder to the internal drive’s folder, or from an internal drive’s folder to another folder in the same drive).
- After that process is done, in the Music application, go to the File menu, go to the Library submenu, and choose Organize Library…
- Check the Consolidate files option, then click OK. This will make copies of the music files to the new media folder without affecting the original files in the original location.
- After the copying process is done, check the songs in your Music application library, both those downloaded from Apple Music and those that are yours, and make sure that they are referring to the files in the new location. To do this, right-click the song or click the three horizontal dots that show up when your cursor hovers over the song, choose Get Info, and go to the File tab.
- Near the bottom of that display, the location value should refer to the new folder instead of the old one.
- Verify that the songs are not showing duplicates anymore by going to the new folder and seeing any album of songs there.
- Verify that the songs from different sources are able to play.
- NOTE BEFORE DELETING MEDIA: Audiobooks, ringtones, home videos, and other media types will not copy through the Apple Music application anymore. If you want to keep these, do not delete them.
- In the original folder, you are now able to delete the Music and Apple Music folders.
- You now have your library residing in the new folder. If you want to move the music back to the original folder, just repeat steps 1 through 4. Otherwise, you're done!
- Change the Music Media folder location back to the original folder.
- Go to Organize Library…, choose the Consolidate files options, and click OK.
- Check each type of song in your Music application library, check the original folder to make sure that there are no more duplicates, and make sure they can play.
- In the new folder, you can safely delete the Music and Apple Music folders.
The most possible issue is you already have added songs (with copying to iTunes folder, it's by default), removed them with 'keep files' variant.
following steps should fix this:
- Remove weird titles from iTunes library and quit from.
- open your iTunes media folder
~/Music/iTunes/iTunes Media/Videos
(you can find it in preferences) - remove weird titles from this folder (you can save correct file copies if you have no backup)
- Also you should remove these entries from iTunes library.
- re-add correct versions into library.
UPDATE: added awk script and description for.
How to use this script:
- save it to the file named
~/dups.awk
(~
is your home directory) - open your
Terminal.app
and change directory to your iTunes media folder like we talked before (e.g.cd "~/Music/iTunes/iTunes Meda/Videos"
) - remove duplicate files with command
find $(pwd) -type f|sort -r|awk -f ~/dups.awk| xargs -L 1 rmtrash
some important notes:
- this script does respect unicode and spaces in file names. I've tested it.
- I believe that unix-way tools are enough to do this task.(they are the fastest too)
rmtrash
is utility from MacPorts, sends files to your Trash.rm
command remove files directly from file system and they can't be restored from trash bin. This is the fastest and the best way if you really sure what do you do.- using automated stuff like this I always double check if there's no mistakes in output. You can replace command
xargs
with arguments withless
command or redirect output to the file (e.g.~/dups.txt
)
func checkfile(a,b)
{
if (length(a)+2 < length(b) || a != substr(b, 1, length(a)))
return 1;
suffix = substr(b, length(a)+1);
return !match(suffix, "^ [0-9]+$");
}
func cutext(a)
{
return substr(a, 1, length(a)-4);
}
{
file=cutext($0);
if (length(name) > 0)
if (checkfile(name, file))
name = file;
else
printf("%s\n",$0);
else
name = file;
}
-
Thank you. We are talking hundreds, if not thousands, of files here. I was wondering if there was a program or script (like a doug's apple script) that would compare what itunes is displaying, with what is in the media folder - and ELIMINATE anything that's in the media folder that itunes isn't displaying. Or perhaps there is a script that looks to see if there is a " 1" or " 2" after the name in iTunes, and remove that extra 1 or 2? Commented Mar 16, 2013 at 20:31
-
Right now, I think Eir Nym is the only way to go: delete files from library, then delete duplicates from media folder, and reimport all files. Problem is, I have nearly 10TB of files - more than 25000 songs and about 10,000 movies and TV shows. It would be an impossibly big task. Commented Mar 16, 2013 at 20:35
-
I see. Please, wait just a little, I'll write you little script.– Eir NymCommented Mar 17, 2013 at 4:25
-
-
WOW. OK Eir Nym. You are making me brave. I need to study this script a bit and then see if I am going to make it work. Just to be careful I think I am going to get help from a more confident Terminal junkie than me. On the plus side I do have my old library which I THINK I could roll back to if needed. Commented Mar 17, 2013 at 21:24