Last active
December 24, 2023 16:07
-
-
Save ChrisTowles/c71986f943499277ff75d246146455db to your computer and use it in GitHub Desktop.
Get the download links from a book mp3 in overdrive
This file contains 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
//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); | |
}); | |
}); | |
This file contains 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
//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