Created
September 15, 2014 21:06
-
-
Save cmittendorf/b3eac19571a0b2fb90ee to your computer and use it in GitHub Desktop.
A little script for exporting you iTunes library into an ElasticSearch database with an index named 'itunes' (requires Yosemite). You may then search for all your Beatles songs using the following command: curl --silent -XGET "localhost:9200/itunes/_search?pretty&size=10000" -d '{"query":{"match":{"artist":"beatles"}}}'|jq '[.hits.hits[]._source]'
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
var app = Application.currentApplication() | |
app.includeStandardAdditions = true | |
var itunes = Application("iTunes") | |
var url = "http://localhost:9200/itunes/track/" | |
var lib = itunes.sources["Library"] | |
var tracks = lib.tracks() | |
for(var i = 0; i < tracks.length; i++) { | |
var o = tracks[i] | |
var id = o.id() | |
var track = { | |
artist:o.artist(), | |
name:o.name(), | |
album:o.album(), | |
genre:o.genre() | |
} | |
// there should be a better way to escape single ' | |
var json = JSON.stringify(track).replace(/'/g, "") | |
// console.log(json) | |
app.doShellScript("curl -XPOST " + url + id + " -d '" + json + "'") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment