-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdoi2pdf
More file actions
executable file
·73 lines (63 loc) · 1.72 KB
/
doi2pdf
File metadata and controls
executable file
·73 lines (63 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Script for finding and downloading a PDF or PS for a given
# Digital Object Identifier (DOI), which usually points to a website
# containing a link to the actual file.
#
# Usage: doi2pdf DOI [filename]
# doi2pdf http://dx.doi.org/DOI [filename]
#
# If filename is omitted the raw PDF/PS is written to a temporary file.
#
# Example: doi2pdf 10.1016/j.orl.2012.11.009
#
# Notes:
# IEEE is not working because it uses JavaScript
function test()
{
grep doi ../../Resources/Bibliography/World.bib | sed 's/[ \t,}]//g' | sed 's#doi={#http://dx.doi.org/#g' | while read doi
do
php doi2pdf.php $doi /dev/null
if [ $? -eq 0 ]
then
echo *PASS* $doi
else
echo *FAIL* $doi
fi
done
}
function gettmpfile()
{
local tmppath=${1:-/tmp}
local tmpfile=$2${2:+-}
tmpfile=$tmppath/$tmpfile$RANDOM$RANDOM.tmp
if [ -e $tmpfile ]
then
# if file already exists, recurse and try again
tmpfile=$(gettmpfile $1 $2)
fi
echo $tmpfile
}
# Issue help message if necessary
if [ $# = 0 ]; then
echo "Usage: $(basename $0) DOI [filename]"
echo "or: $(basename $0) http://dx.doi.org/DOI [filename]"
echo "will try and retrieve the PDF file for the DOI given and save it to filename or writes to stdout if filename is omitted."
exit 1
fi
# Extract doi. Pattern from https://github.com/regexhq/doi-regex/blob/master/index.js
DOI=$(echo $1 | grep '10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?![%"#? ])\S)+' -P -o )
# Assign output file name if possible
# and call doi2pdf.php
if [ -z "$2" ]
then
# invent a good filename
FN=$(doi2pdfname.sh "$DOI")
if [ -z "$FN" ]
then
FN=$(gettmpfile);
fi
php $(dirname $0)/doi2pdf.php $DOI $FN || exit 1
else
php $(dirname $0)/doi2pdf.php $@ || exit 1
fi
exit 0