Skip to content

Instantly share code, notes, and snippets.

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