Marek Skrobacki

Safari Books - migration from legacy (Techbus) to new platform

I have been using Safari books for good few years now and managed to create quite large collection of books in various folders.

This morning I have learned that my company decided to move to new version of Safari's platform and I didn't have any choice to stay on the old platform. In other words, I was told that all of my lists are going to be lost unless I migrate them manually.

They suggested searching each book on the new platform and adding it by hand. Nope. I didn't have time for this, so I put together a way to semi-automate the migration. It's far from fully automated one-click "Migrate!" button, but it may help if you are faced with same problem.

Steps

  • Open the old platform
  • Combine all of your lists into single list. This can be easily done by simply selecting each of them, then clicking Select all then copy to 'My list' or whichever you choose.
  • Open your single list, then open your browser's console
  • Paste following snippet:
$("ul.items > li").map(function(idx, e) { return e.getAttribute('data-folder-item-fpid');});
  • You should now see a result that looks similar to this:
["9781449341527", "9781449317843", "9780132930895",
"9781617291692", "9781941222348", "9781680501629", "9781784394035",
"0321125215", "0201485672", "9780133135640", "9780133847086", "9780596516178",
"9780321620293", "9781430218333", "9781430228745", "9781449325527",
"9780321684097", "9780136083238", "9781617290572", "9781430260585",
"9780596517748", "9781593272821", "9780321700124", "9781782165224",
"9780133487954", "9781782162162", "9781782160007", "9781782161820",
"9781449355852", "9781939902047", "9781782163381", "9781593272944",
"9780321490452", "0596007124", "9781449393854", "9781118026694",
"9781430240952"]
  • Above list contains ID number of all books on a given list. Copy it to the clipboard
  • Open new platform in separate tab
  • Open the browser console
  • Paste the previously copied result, but prepend it with text var elements = so that your list of books is stored into elements variable.

For example:

var elements = ["9781449341527", "9781449317843", "9780132930895",  
"9781617291692", "9781941222348", "9781680501629", "9781784394035",
"0321125215", "0201485672", "9780133135640", "9780133847086", "9780596516178",
"9780321620293", "9781430218333", "9781430228745", "9781449325527",
"9780321684097", "9780136083238", "9781617290572", "9781430260585",
"9780596517748", "9781593272821", "9780321700124", "9781782165224",
"9780133487954", "9781782162162", "9781782160007", "9781782161820",
"9781449355852", "9781939902047", "9781782163381", "9781593272944",
"9780321490452", "0596007124", "9781449393854", "9781118026694",
"9781430240952"]; 
  • Paste following script to perform actual migration:
function addbook(bookID) {  
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/api/v1/queue-simple/', true);
    xhr.setRequestHeader('Content-Type', 'application/json');
    var csrf = document.cookie.replace(/(?:(?:^|.*;\s*)csrfsafari\s*\=\s*([^;]*).*$)|^.*$/, "$1");
    xhr.setRequestHeader('X-CSRFToken', csrf);
    xhr.onload = function () {
        // console.log(this.responseText);
        if(this.status === 404) {
            console.log("Book: " + bookID + " not found.")
        } else {
            console.log("Book: " + bookID + " added.")
        }
    };
    xhr.send(JSON.stringify(["/api/v1/book/" + bookID + "/"]));
}

elements.forEach(function(book) { console.log("Adding book: " + book); addbook(book); })  

If all goes well, you should see bunch of messages about books being added. It is likely that few books won't be found because they ditched some of those which were not available in 'new' format. Some of the missing books can still be found, so check those manually. For me it was just about 8 books out of 70+. Good luck!