Created
May 27, 2018 10:52
-
-
Save dannote/c827895286fa5a8e9a46f953bd0e3372 to your computer and use it in GitHub Desktop.
Get song list from iTunes including Apple Music tracks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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