Skip to content

Instantly share code, notes, and snippets.

@dannote
Created May 27, 2018 10:52
Show Gist options
  • Save dannote/c827895286fa5a8e9a46f953bd0e3372 to your computer and use it in GitHub Desktop.
Save dannote/c827895286fa5a8e9a46f953bd0e3372 to your computer and use it in GitHub Desktop.
Get song list from iTunes including Apple Music tracks
#!/usr/bin/swift
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