-
-
Save usayamadx/9c638d9b70bc714d6dd6043fcd54085f to your computer and use it in GitHub Desktop.
// init | |
let xhr = new XMLHttpRequest() | |
let domain = 'https://read.amazon.com/' | |
let items = [] | |
let csvData = "" | |
// function | |
function getItemsList(paginationToken = null) { | |
let url = domain + 'kindle-library/search?query=&libraryType=BOOKS' + ( paginationToken ? '&paginationToken=' + paginationToken : '' ) + '&sortType=recency&querySize=50' | |
xhr.open('GET', url, false) | |
xhr.send() | |
} | |
// request result | |
xhr.onreadystatechange = function() { | |
switch ( xhr.readyState ) { | |
case 0: | |
console.log('uninitialized') | |
break | |
case 1: | |
console.log('loading...') | |
break | |
case 4: | |
if(xhr.status == 200) { | |
let data = xhr.responseText | |
data = JSON.parse(data) | |
if(data.itemsList) { | |
items.push(...data.itemsList) | |
} | |
if(data.paginationToken) { | |
getItemsList(data.paginationToken) | |
} | |
} else { | |
console.log('Failed') | |
} | |
break | |
} | |
} | |
// action | |
getItemsList() | |
// to csv | |
items.forEach(item => { | |
csvData += '"' + item.asin + '","' + item.title + '"\n' | |
}) | |
window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData) |
I appreciate this! This export all of my titles, but did not export any additional details like author information. Would love if that would be captured.
if you'd like some of the extra properties, use this. I've commented out the percentageRead (as it always shows 0 for me), originType (same for all my books) and mangaOrComicAsin (not relevant for my stuff) - but you remove all the // preceding those lines, you'll get everything
it looks like that all authors are included in a single item in an array, but this code will deal with additional items
finally, the search order is changed to use the order of purchase - which will make it easier to identify just new items when exporting the list again later
@pdollar88 @betsy-2063 @darryllee - very late but just in case you're interested...
// init
let xhr = new XMLHttpRequest()
let domain = 'https://read.amazon.com/'
let items = []
let csvData = ""
// function
function getItemsList(paginationToken = null) {
let url = domain + 'kindle-library/search?query=&libraryType=BOOKS' + ( paginationToken ? '&paginationToken=' + paginationToken : '' ) + '&sortType=acquisition_desc&querySize=50'
xhr.open('GET', url, false)
xhr.send()
}
// request result
xhr.onreadystatechange = function() {
switch ( xhr.readyState ) {
case 0:
console.log('uninitialized')
break
case 1:
console.log('loading...')
break
case 4:
if(xhr.status == 200) {
let data = xhr.responseText
data = JSON.parse(data)
if(data.itemsList) {
items.push(...data.itemsList)
}
if(data.paginationToken) {
getItemsList(data.paginationToken)
}
} else {
console.log('Failed')
}
break
}
}
// action
getItemsList()
// to csv
items.forEach(item => {
let authorNames = "";
item.authors.forEach(author => {
let authorsList = author.split(":");
let prevAuthor = "";
authorsList.forEach((a, _i) => {
// ignore duplicate name and last item (empty string)
if (a !== prevAuthor && _i < authorsList.length - 1) {
authorNames += a + '; '
prevAuthor = a;
}
});
});
csvData +=
'"' + item.asin +
'","' +
item.title +
'","' +
authorNames +
'","' +
item.webReaderUrl +
'","' +
item.productUrl +
'","' +
item.resourceType +
// '","' +
// item.percentageRead +
// '","' +
// item.originType +
// '","' +
// mangaOrComicAsin +
'"\n'
})
window.location = 'data:text/csv;charset=utf8,' + `encodeURIComponent(csvData)
thanks so much to @usayamadx - really appreciate this!
I improved upon @usayamadx logic and made a Chrome extension to solve this problem: Kindle Book List Exporter
You can now get a csv file in 1 click. No need to deal with any code or console.
Please let me know if it works for you.
THANKS @usayamadx ! Awesome.
I, too, had something that prevented the download. I put it in a blob and it works great:
// init
let xhr = new XMLHttpRequest()
let domain = 'https://read.amazon.com/'
let items = []
let csvData = ""
const formatBook = item => '"' + item.asin + '","' + item.title + '","' + (item.authors || [])[0] + '"\n';
// function
function getItemsList(paginationToken = null) {
let url = domain + 'kindle-library/search?query=&libraryType=BOOKS' + ( paginationToken ? '&paginationToken=' + paginationToken : '' ) + '&sortType=recency&querySize=50'
xhr.open('GET', url, false)
xhr.send()
}
// request result
xhr.onreadystatechange = function() {
switch ( xhr.readyState ) {
case 0:
console.log('uninitialized')
break
case 1:
console.log('loading...')
break
case 4:
if(xhr.status == 200) {
let data = xhr.responseText
data = JSON.parse(data)
if(data.itemsList) {
items.push(...data.itemsList)
}
if(data.paginationToken) {
getItemsList(data.paginationToken)
}
} else {
console.log('Failed')
}
break
}
}
// action
getItemsList()
// to csv
items.forEach(item => {
csvData += formatBook(item);
})
const blobCSV = new Blob([csvData], {type: 'text/plain;charset=utf-8'});
blobURL = URL.createObjectURL(blobCSV);
window.location = blobURL;
@usayamadx: This is great - a BIG THANKS! I was able to download 10000 of my 17600+ books. Some minor formatting was required due to title details as mentioned above - but those are easy to fix in the spreadsheet.
Looks like the limitation on the Pagination Token is 9999 and the Query Size is limited to 50! Both prevent a complete download of the list. Has anyone else seen this limit? Any ideas on how to get the rest of the books on my list?
I'm trying to find how to modify the URL. So far I see these options:
Where do I get the reference to see others?
I'm currently building this reference at: https://github.com/MrMikey59/Kindle-Book-List