Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kanzure/papermonk-downloader-plosone
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2233c786435a
Choose a base ref
...
head repository: kanzure/papermonk-downloader-plosone
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 57f71eed7410
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Aug 12, 2013

  1. make a callable pipe for each downloadable file

    The returned dictionary now includes files that each have a property
    called "pipe" that can be given a writable stream.
    kanzure committed Aug 12, 2013

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    57f71ee View commit details
Showing with 34 additions and 3 deletions.
  1. +34 −3 index.js
37 changes: 34 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,12 @@ var urlparser = require("url-parser");
var request = require("request");
var jsdom = require("jsdom");

function makepipe(url) {
return function download(writestream) {
return request.get(url).pipe(writestream);
};
};

module.exports.test = function test(url) {
parsedurl = urlparser.parse(url);

@@ -21,22 +27,47 @@ module.exports.test = function test(url) {
};

module.exports.download = function download(url, options, callback) {
request.get(url, function requestcallback(error, response, body) {
return request.get(url, function requestcallback(error, response, body) {
var metadata = null;

if (!error && response.statusCode == 200) {
var window = jsdom.jsdom(body).createWindow();
var title = window.document.getElementsByTagName("title")[0].innerHTML;

var meta_elements = window.document.evaluate("//meta[@name='citation_pdf_url']", window.document, null, 0, null);
var meta_pdf_url_element = meta_elements.iterateNext();

var pdfurl1 = null;
var pdfurl2 = null;

if (meta_pdf_url_element) {
pdfurl1 = meta_pdf_url_element.content;
} else {
pdfurl1 = "http://dx.plos.org/10.1371/journal.pone.0071630.pdf";
}

pdfurl2 = pdfurl1;

metadata = {
"html": {
"title": title,
},

"files": [
{
"name": "paper.pdf",
"url": pdfurl1,
"pipe": makepipe(pdfurl1),
},
{
"name": "supplementary.pdf",
"url": pdfurl2,
"pipe": makepipe(pdfurl2),
},
],
};
}

callback(error, metadata);
});

return undefined;
};