Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Import Old iTunes Library - Convert Old iTunes Library

After a recuperation of a TimeMachine of 2019 the iTunes Library inside was too OLD to be imported in the recent version MUSIC iTunes of Apple.


inside the iTunes folder there is a XML file "iTunes Music Library 2010-06-28 20.52.30.xml"


2 Problems need to be solved:


The Location of the files (New HardDrive)


in my case I had multiple different PATH need to be changed.


OLD_PATH1="file://localhost/Users/printi/Music/iTunes/"

OLD_PATH2="file://localhost/Volumes/Work/iTunes/"


NEW_PATH="file://localhost/Volumes/Matrice%20Raid/iTunes/"


To do the replacement of the path, create a file 'replace.sh'


in the Terminal:


  1. vi replace1.sh
  2. i (to insert)
  3. paste the content
  4. :wq (to save)
  5. chmod +x replace1.sh (to give authorisations to be launched)
  6. ./replace1.sh (to launch the script)


#!/bin/bash

# Chemin d'origine à remplacer
OLD_PATH1="file://localhost/Users/printi/Music/iTunes/"
OLD_PATH2="file://localhost/Volumes/Work/iTunes/"

# Nouveau chemin de remplacement
NEW_PATH="file://localhost/Volumes/Matrice%20Raid/iTunes/"

# Nom du fichier XML
XML_FILE="iTunes Music Library 2010-06-28 20.52.30.xml"

# Vérifie si le fichier XML est lisible
if [ -r "$XML_FILE" ]; then
    # Effectue le remplacement de tous les chemins dans le fichier XML
    sed -i '' "s@$OLD_PATH1@$NEW_PATH@g" "$XML_FILE"
    sed -i '' "s@$OLD_PATH2@$NEW_PATH@g" "$XML_FILE"

    echo "Tous les remplacements de chemin ont été effectués avec succès dans le fichier $XML_FILE."
else
    echo "Le fichier $XML_FILE n'est pas lisible."
fi




The sorting of iTunes that have changed from


file://localhost/Volumes/Work/iTunes/iTunes%20Music/Artist/Album/filename.mp3

to

file://localhost/Volumes/Work/iTunes/iTunes%20Music/Artist/S/filename.mp3


The Goal is to reuse the Album name and replace the S into the file url


<key>Artist</key><string>Bonnie Tyler</string>

<key>Album</key><string>Slowtime 02</string>

<key>Location</key><string>file://localhost/Volumes/Work/iTunes/iTunes%20Music/Bonnie%20Tyler/S/01%20Total%20Eclipse%20Of%20The%20Heart.mp3</string>


Result:


<key>Location</key><string>file://localhost/Volumes/Matrice%20Raid/iTunes/iTunes%20Music/Bonnie%20Tyler/Slowtime%2002/01%20Total%20Eclipse%20Of%20The%20Heart.mp3</string>



in the Terminal:


vi replace2.sh

i (to insert)

paste the content

:wq (to save)

chmod +x replace2.sh (to give authorisations to be launched)

./replace2.sh (to launch the script)



#!/bin/bash

# Define XML file name
XML_FILE="iTunes Music Library 2010-06-28 20.52.30.xml"

# Check if the XML file is readable
if [ -r "$XML_FILE" ]; then
    # Temporary file to store updated XML
    TEMP_FILE="temp.xml"
    # Variable to hold the current album name
    CURRENT_ALBUM=""

    # Read the XML file line by line
    while IFS= read -r line; do
        # Check for album name and update the CURRENT_ALBUM variable
        if [[ $line =~ \<key\>Album\</key\>\<string\>(.*)\</string\> ]]; then
            CURRENT_ALBUM="${BASH_REMATCH[1]}"
        fi

        # Check if the line contains the location key and path with "/S/"
        if [[ $line == *"<key>Location</key>"* && $line == *"/S/"* ]]; then
            # Prepare the album name for URL by replacing spaces with %20
            ALBUM_FOR_URL="${CURRENT_ALBUM// /%20}"
            # Replace "/S/" with the URL-safe album name in the path
            NEW_LOCATION=$(echo "$line" | sed -E "s@/S/@/${ALBUM_FOR_URL//@/%40}/@")
            echo "$NEW_LOCATION" >> "$TEMP_FILE"
        else
            echo "$line" >> "$TEMP_FILE"
        fi
    done < "$XML_FILE"

    # Replace the original XML file with the updated one
    mv "$TEMP_FILE" "$XML_FILE"
    echo "Updates have been successfully applied to the file $XML_FILE."
else
    echo "The file $XML_FILE is not readable."
fi



Hope this will help.


Mac Pro, macOS 10.12

Posted on Apr 27, 2024 1:09 PM

Reply

There are no replies.

Import Old iTunes Library - Convert Old iTunes Library

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.