Skip to content

Instantly share code, notes, and snippets.

Created May 27, 2018 10:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Get song list from iTunes including Apple Music tracks
import Foundation
let path = NSString(string: "~/Music/iTunes/iTunes Music Library.xml").expandingTildeInPath
let data = NSDictionary(contentsOfFile: path)
let allowedTypes = ["File", "Remote"]
if let data = NSDictionary(contentsOfFile: path) as? [String : AnyObject] {
for (_, track) in data["Tracks"] as! [String : NSDictionary] {
if let artist = track["Artist"] ?? track["Album Artist"],
let album = track["Album"],
let name = track["Name"],
allowedTypes.contains(track["Track Type"] as! String) {
print("\(artist) - \(album) - \(name)")
} else {
print("Please open iTunes Preferences, go to Advanced and check \"Share iTunes Library XML with other applications\"")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment