-
-
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) |
@darryllee OH! Thank you, your nice comment!!
I will think the best solution.
Thank you @usayamadx. This worked for me, got all my stuff (about 1500). In case anyone else reading was unsure like me how you use this: copy the text (github "raw" button is one way), login to read.amazon.com, hit F12 to get developer tools, find the Console, paste the code into the console.... and the script will run and download the contents.
Thanks @darryllee for "this good comment"
I'm interested in parsing my notes, and one way in is https://read.amazon.com/notebook... if anyone does/knows of any work on this, would be grateful for info.
Background: a 2016 answer to a 2010 Stack overflow answer: https://stackoverflow.com/a/39958932/514608
Thanks, @usayamadx -- it worked beuatifully for me, and I'm a Java novice. I too would like more details about my books (like author, purchase date, read/unread, Prime vs. purchased). Have you had a chance to think about any solutions??
@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:
- &sortType=recency
- &sortType=acquisition_asc
Where do I get the reference to see others?
I'm currently building this reference at: https://github.com/MrMikey59/Kindle-Book-List
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;
This is awesome, @usayamadx. Thank you for writing this!
One bug: I have this book in my collection, which has a ridiculously long title that happens to include a backslashed double-quote in it. Your script got confused by that:
"title": "The Awkward Thoughts of W. Kamau Bell: Tales of a 6' 4\", African American, Heterosexual, Cisgender, Left-Leaning, Asthmatic, Black and Proud Blerd, Mama's Boy, Dad, and Stand-Up Comedian",
Feature request:
It would be awesome if your export could include all attributes for each book. So then:
I would try fixing this myself and creating a pull request, but hey, this is just a gist. :-} LMK if you make it into a real repo.