Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Mac OSX Terminal – Get Artist and Song From iTunes PlayList Export

Posted on December 28, 2016March 6, 2017 By David Kittell

There are more elegant ways to do this but I got bored and thought I’d do something that is only done with base Mac OSX tools

#!/bin/sh

#  Read_iTunes_PlayList.sh
#
#  Get only the artist list - remove duplicates
#  Read_iTunes_PlayList.sh 1 iTunesPlayListFileName ~/Desktop
#
#  Get Artist and Song Name
#  Read_iTunes_PlayList.sh 2 iTunesPlayListFileName ~/Desktop
#
#  Created by David Kittell on 12/27/16.
#

clear

XMLOption=$1
XMLFileName=$2
XMLFilePath=$3

case $XMLOption in
1)
# Only Get the Artist

clear
#echo $XMLOption
#echo $XMLFileName
#echo $XMLFilePath

rm -rf $(echo $XMLFilePath/$XMLFileName).txt || :

#echo "Parsing XML"
music=`grep 'Artist' $(echo $XMLFilePath/$XMLFileName.xml) | \
sed 's/<key>Artist<\/key><string>//g'| sed 's/<\/string>//g' \
| sed 's/%20/ /g' | sort`;

old_IFS=$IFS

# IFS by default is space tab return, and stands for
# Internal Field Separator.
IFS='
'

for i in $music
do
`echo $i >> $(echo $XMLFilePath/$XMLFileName.txt)`;
done

IFS=$old_IFS

cat $(echo $XMLFilePath/$XMLFileName.txt) | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' > $(echo $XMLFilePath/$XMLFileName_01.txt)

sed -i -e "s|&#38;|\&|g" $(echo $XMLFilePath/$XMLFileName_01.txt)
sed -i -e "s|&#60;|\<|g" $(echo $XMLFilePath/$XMLFileName_01.txt)
sed -i -e "s|&#62;|\>|g" $(echo $XMLFilePath/$XMLFileName_01.txt)

sort $(echo $XMLFilePath/$XMLFileName_01.txt) | uniq | grep -v '<key>' > $(echo $XMLFilePath/$XMLFileName.txt)

rm -f  $(echo $XMLFilePath/$XMLFileName_01.txt)

cat $(echo $XMLFilePath/$XMLFileName.txt)

;;
2)
# Get the Artist and Song

clear

#echo $XMLOption
#echo $XMLFileName
#echo $XMLFilePath

rm -rf $(echo $XMLFilePath/$XMLFileName).txt || :

#echo "Parsing XML"
grep -E '<key>Artist</key>|<key>Name</key>' iPhone.xml | sed 's/<key>Artist<\/key><string>/|/g'| sed 's/<\/string>//g' | sed 's/%20//g' | sed 's/<key>Name<\/key><string>/~/g'| sed 's/<\/string>//g' | sed 's/%20//g' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g' | sed -e "s|&#38;|\&|g" | sed -e "s|&#60;|\<|g" | sed -e "s|&#62;|\>|g" | tr '~' '\n' | sort > $(echo $XMLFilePath/$XMLFileName).txt

#cat $XMLFilePath/$XMLFileName.txt

#echo "Cleaning List - Start"
IFS=$'\n'
for next in `cat $filename`
do
song=$(echo $next | cut -d '|' -f1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
artist=$(echo $next | cut -d '|' -f2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
echo "$artist \t $song" >> $(echo $XMLFilePath/$XMLFileName)Filtered.txt
done < $XMLFilePath/$XMLFileName.txt
#echo "Cleaning List - Stop"

#echo "Remove iTunes PlayList name"
sed -i '' -e '$ d' $(echo $XMLFilePath/$XMLFileName)Filtered.txt

#echo "Sort the results"
cat $(echo $XMLFilePath/$XMLFileName)Filtered.txt | sort > $(echo $XMLFilePath/$XMLFileName).txt

cat $(echo $XMLFilePath/$XMLFileName).txt


;;
esac
Originally Posted on December 28, 2016
Last Updated on March 6, 2017
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code Mac OS X Shell Mac OSX UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

UNIX – SED Replace Tab with Space(s)

Posted on December 20, 2017

sed ‘s/\t/ /g’ tab-file.txt > no-tab-file.txt Originally found at https://linuxconfig.org/replace-all-tab-characters-with-spaces All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just…

Read More

Visual Studio Oracle Tools

Posted on February 28, 2013October 26, 2015

When working with Visual Studio and Oracle you will need to download Oracle’s Visual Studio Tools. Code Samples: http://www.oracle.com/technetwork/articles/dotnet/cook-dotnet-101788.html If I thought I could legally host the file I would. Official Page: http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html If the link fails to work do a search on http://www.oracle.com/ for Visual Studio ODAC 11.2 Release…

Read More

Mac OS X – Get Network Information

Posted on February 27, 2017May 2, 2017

Every once in a while you need to get some basic network information from your Mac or a Mac you are supporting, this script below will help get you some helpful information. #!/bin/sh clear sExternalMACALService="http://dns.kittell.net/macaltext.php?address=" # List all Network ports NetworkPorts=$(ifconfig -uv | grep ‘^[a-z0-9]’ | awk -F : ‘{print…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes