iTunes Image Search
Shared by coomlata1
Searches Apple-iTunes libraries for images and presents them as html to be viewed in the 1Writer browser and copied to the clipboard or camera roll for use as icons, etc. Inspiration comes from a Python script written for OSX by @drdrang. This version is written entirely in JavaScript.
Script
var theRest = ''
String.prototype.toProperCase = function () {
return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
};
function isEmpty(theStr) {
if (theStr == null || theStr == "") {
return true
}
return false
}
ui.alert("Pick An iTunes Category For Image Search?",
"Apple-iTunes Libraries",
"iOS App",
"Mac App",
"Album",
"Film",
"TV Show",
"Book",
"Cancel",
function(selected) {
if (selected == 0) {
var size = '512'
var media = 'software'
var entity = 'software'
var name = 'trackName'
} else if (selected == 1) {
var size = 512
var media = 'software'
var entity = 'macSoftware'
var name = 'trackName'
} else if (selected == 2) {
var size = 600
var media = 'music'
var entity = 'album'
var name = 'collectionName'
} else if (selected == 3) {
var size = 600
var media = 'movie'
var entity = 'movie'
var name = 'trackName'
} else if (selected == 4) {
var size = 600
var media = 'tvShow'
var entity = 'tvSeason'
var name = 'collectionName'
} else if (selected == 5) {
var size = 600
var media = 'ebook'
var entity = 'ebook'
var name = 'trackName'
} else if (selected == 6) {
return
}
ui.input('Search', '', 'Enter '+media.toProperCase()+ ' Search Criteria:',
function(value) {
if (value) {
var searchStr = (value)
// Trim blank spaces at beginning or end of search string.
searchStr = searchStr.trim()
ui.hudProgress('Searching');
http.get('https://itunes.apple.com/search', {
term: searchStr,
media: media,
country: 'us',
entity: entity }, handleResponseData);
}
function handleResponseData(response, error) {
if (error) {
ui.hudError();
return;
}
ui.hudDismiss();
var listData = response.results.map(function(item) {
if (name == 'collectionName') {
var nameOne = item.collectionName
} else if (name == 'trackName') {
var nameOne = item.trackName
}
var itemOne = item.artworkUrl100.replace('100x100bb', size+'x'+size+'bb')
var itemTwo = item.artworkUrl100
theRest = theRest + '<a href='+itemOne+'><img src='+itemTwo+' alt='+nameOne+', title='+nameOne+' /></a>'
});
if (isEmpty(theRest)) {
ui.alert('No Images Found');
return;
}
var html = '<html> <head><title>' +searchStr+ ' pictures</title></head> <body> <h1> '+searchStr+ ' pictures</h1>'+theRest+'</body></html>'
app.setClipboard(html)
var webView = app.getClipboard()
if (editor.isClosed()) {
//create new file if needed
editor.newFile();
editor.replaceSelection(webView);
} else {
editor.replaceSelection(webView);
}
ui.alert("Success!! Press 'Preview' to View Output")
//ui.hudSuccess("Success!! Press 'Preview' to View Output");
}
});
})