Skip to content

Instantly share code, notes, and snippets.

@ChrisTowles
Last active December 24, 2023 16:07
Show Gist options
  • Save ChrisTowles/c71986f943499277ff75d246146455db to your computer and use it in GitHub Desktop.
Save ChrisTowles/c71986f943499277ff75d246146455db to your computer and use it in GitHub Desktop.
Get the download links from a book mp3 in overdrive
//using the json file from above.
var https = require('https');
var fs = require('fs');
var model = require('./book.json')
//console.log(model);
model.parts = [model.parts[0]]; //limit to 1
model.parts.forEach(x => {
var file = fs.createWriteStream(x.name);
console.log('writing: ' + x.name)
var request = https.get(x.path, function(response) {
// Getting a 500 error
console.log(response.statusCode);
response.pipe(file);
});
});
//open window to the lent book.
var baseUrl = "https://ofs-" + window.bData["-odread-buid"] + ".listen.overdrive.com"
window.bData.spine.forEach(function(x) { console.log("" + baseUrl + "/" + x.path ) } )
var model = {
title: window.bData.title,
parts: [],
};
window.bData.spine.forEach(function(x) {
var temp = x["-odread-original-path"];
var name = temp.substring(temp.lastIndexOf("-") + 1)
model.parts.push(
{
path: "" + baseUrl + "/" + x.path,
name: name
}
)
})
function download(dataurl, filename) {
var a = document.createElement("a");
a.href = dataurl;
a.setAttribute("download", filename);
var b = document.createEvent("MouseEvents");
b.initEvent("click", false, true);
a.dispatchEvent(b);
return false;
}
download("data:text/json," + JSON.stringify(model), "book.json")
//todo
//create a json object i can just copy to node that will download the book rather than one at a time by hand.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment