Created
April 11, 2017 01:33
-
-
Save Nielk1/530ff5b271696ba19f70e314c8dba517 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 safeSubproductFields = ['human_name','icon','library_family_name','machine_name','url','payee']; | |
var safeDownloadFields = ['android_app_only','download_identifier','download_version_number','machine_name','platform','options_dict']; | |
var safeDownloadStructFields = ['arch','external_link','file_size','force_download','human_size','kindle-friendly','md5','name','sha1','small','time','timestamp','timestmap','timetstamp','uploaded_at','uses_kindle_sender','asm_config'/*,'asm_manifest'*/]; | |
var safeTpkdFields = ['auto_expand','auto_redeem','class','created','custom_disclaimer','custom_expand_html','disallowed_countries','disallowed_platforms','disclaimer','display_separately','exclusive_countries','exclusive_platforms','hide_personal_use_note','human_name','icon','instructions_html','is_current_version','is_gift','keyindex','key_type','key_type_human_name','library_family_name','machine_name','made_current_at','notes','permanently_depletable','platforms','preinstruction_text','show_custom_instructions_in_user_libraries','sold_out','steam_app_id','steam_package_id','tpkds_to_supersede','version_changelog','visible']; | |
var exportdata = []; | |
function getFileName(url) { | |
//this removes the anchor at the end, if there is one | |
url = url.substring(0, (url.indexOf("#") == -1) ? url.length : url.indexOf("#")); | |
//this removes the query after the file name, if there is one | |
url = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?")); | |
//this removes everything before the last slash in the path | |
url = url.substring(url.lastIndexOf("/") + 1, url.length); | |
return url; | |
} | |
function download(content, filename, contentType) | |
{ | |
if(!contentType) contentType = 'application/octet-stream'; | |
var a = document.createElement('a'); | |
var blob = new Blob([content], {'type':contentType}); | |
a.href = window.URL.createObjectURL(blob); | |
a.download = filename; | |
a.click(); | |
} | |
jQuery.ajax('https://www.humblebundle.com/api/v1/user/order') | |
.done(function(orders){ | |
var counter = 0; | |
jQuery.each(orders,function(idx,order){ | |
counter = counter + 1; | |
jQuery.ajax('https://www.humblebundle.com/api/v1/order/'+order.gamekey+'?all_tpkds=true') | |
.done(function(data){ | |
var harvest = {}; | |
harvest.product = data.product; | |
harvest.subproducts = []; | |
if(data.subproducts != null) | |
{ | |
jQuery.each(data.subproducts,function(idx2,subproduct){ | |
var subproductX = {}; | |
$.each(safeSubproductFields, function(idx3, field) { | |
subproductX[field] = subproduct[field]; | |
}); | |
subproductX.downloads = []; | |
//$.each(subproduct, function(key, element) { | |
// console.log('key: ' + key + '\t' + 'value: ' + element); | |
//}); | |
$.each(subproduct.downloads, function(idx3, download) { | |
var downloadX = {}; | |
$.each(safeDownloadFields, function(idx4, field) { | |
downloadX[field] = download[field]; | |
}); | |
if(download.download_struct != null) { | |
downloadX.download_struct = []; | |
$.each(download.download_struct, function(idx5, download_struct_item) { | |
var download_structX = {}; | |
$.each(safeDownloadStructFields, function(idx6, field) { | |
download_structX[field] = download_struct_item[field]; | |
}); | |
if(download_struct_item.url != null) { | |
download_structX.url = {}; | |
$.each(download_struct_item.url, function(urlType, url) { | |
download_structX.url[urlType] = getFileName(url); | |
}); | |
} | |
downloadX.download_struct.push(download_structX); | |
}); | |
} | |
subproductX.downloads.push(downloadX); | |
}); | |
harvest.subproducts.push(subproductX); | |
}); | |
} | |
if(data.tpkd_dict != null) | |
{ | |
harvest.tpkd_dict = {}; | |
if(data.tpkd_dict.all_tpks != null) | |
{ | |
harvest.tpkd_dict.all_tpks = []; | |
$.each(data.tpkd_dict.all_tpks, function(idx, tpkd) { | |
var tpkdX = {}; | |
$.each(safeTpkdFields, function(key, field) { | |
tpkdX[field] = tpkd[field]; | |
}); | |
harvest.tpkd_dict.all_tpks.push(tpkdX); | |
}); | |
} | |
} | |
exportdata.push(harvest); | |
}) | |
.always(function(){ | |
counter = counter - 1; | |
if(counter <= 0){ | |
download(JSON.stringify(exportdata),'humble_export_'+Date.now()+'.json','application/json'); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment