-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf2isbn
executable file
·58 lines (46 loc) · 1.01 KB
/
pdf2isbn
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
#!/usr/bin/env sh
#: Extract the ISBN from a PDF.
#:
#: Usage:
#:
#: pdf2doi [filename]
#:
#: If no filename is specified, read from stdin.
#:
#: Requirements: pdfinfo (install poppler_utils), pdftotext (install xpdf or python's pdftotext).
method1() {
pdfinfo $1 | sed -n 's/.*ISBN:* *\([0-9\-]\+\)/\1/Ip'
}
method2() {
pdfinfo -meta $1 | sed -n 's/.*>ISBN:* *\(.*\)<.*/\1/p'
}
method3() {
pdftotext -l 10 $1 - | sed -n 's/.*isbn/ISBN/ip'
}
method4() {
pdftotext -l 10 $1 - | sed -n 's/.*\(978\)/\1/ip'
}
method5() {
pdftotext -l 10 $1 - | sed -n 's/.*0-/0-/ip'
}
ISBN=$(method1 $1)
if [ -z "${ISBN}" ]; then
# echo "Trying method 2 for $1"
ISBN=$(method2 $1)
fi
if [ -z "${ISBN}" ]; then
# echo "Trying method 3 for $1"
ISBN=$(method3 $1)
fi
if [ -z "${ISBN}" ]; then
# echo "Trying method 4 for $1"
ISBN=$(method4 $1)
fi
if [ -z "${ISBN}" ]; then
# echo "Trying method 5 for $1"
ISBN=$(method4 $1)
fi
if [ -z "${ISBN}" ]; then
ISBN=???
fi
echo "ISBN for $1 is ${ISBN}"