Created
June 11, 2019 10:36
-
-
Save febuiles/6c2818eb34fce07b12f1bb86980e54c3 to your computer and use it in GitHub Desktop.
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
import iTunesLibrary | |
import Foundation | |
let library = try ITLibrary(apiVersion: "1.0") | |
let localPlaylists = library.allPlaylists | |
var result: [String: [Any]] = [:] | |
var playlists: [Any] = [] | |
for playlist in localPlaylists { | |
var list = [String: Any]() | |
var entries: [Any] = [] | |
if ["Library", "Music"].contains(playlist.name) { | |
continue | |
} | |
list["name"] = playlist.name | |
for song in playlist.items { | |
var entry = [String: Any]() | |
entry["album"] = song.album.title | |
entry["artist"] = song.artist.name | |
entry["rating"] = song.rating | |
entry["title"] = song.title | |
entry["trackNumber"] = song.trackNumber | |
entries.append(entry) | |
} | |
list["entries"] = entries | |
playlists.append(list) | |
} | |
result["playlists"] = playlists | |
let data: Data = try JSONSerialization.data(withJSONObject: result, options:[]) | |
print(String(data: data, encoding: .utf8)! as Any) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment