3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation. #
8 # This program is distributed in the hope that it will be useful, but #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
11 # General Public License for more details. #
13 # You should have received a copy of the GNU General Public License #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
16 # Written by and Copyright (C) Francois Fleuret #
17 # Contact <francois.fleuret@idiap.ch> for comments & bug reports #
18 #########################################################################
24 [[ "${ARXIV_BIBFILE}" ]] || (echo >&2 "Define \$ARXIV_BIBFILE"; exit 2)
25 [[ "${ARXIV_BIBDIR}" ]] || (echo >&2 "Define \$ARXIV_BIBDIR"; exit 2)
27 tmp=$(mktemp /tmp/arxiv-bib.sh.XXXXXX)
34 id="$(echo "$1" | sed -e 's|^.*/\([0-9.]*\)$|\1|')"
35 wget "https://arxiv.org/pdf/${id}"
39 id="$(basename ${filename} .pdf)"
42 while [[ -f "${id}.pdf.part" ]] # dealing with firefox's download
44 echo "Waiting for ${id}.pdf.part to vanish"
48 echo -n "Fetching info from arxiv.org ... "
50 curl -s > "${tmp}" "https://arxiv.org/abs/${id}"
54 ######################################################################
61 [[ "${AUTHORS}" ]] && AUTHORS="${AUTHORS} and "
62 AUTHORS="${AUTHORS}${line}"
63 done < <(grep '<meta name="citation_author"' "${tmp}" | sed -e 's/^.*content="\([^,]*, .\).*$/\1./')
65 TITLE=$(grep '<meta name="citation_title"' ${tmp} | sed -e 's/^.*content="\([^"]*\)".*$/\1/')
66 YEAR=$(echo ${id} | sed -e 's/^\(..\).*$/20\1/')
68 if grep "${TITLE}" "${ARXIV_BIBFILE}"
71 echo "This article seems to be already in ${ARXIV_BIBFILE}"
75 cat >> ${ARXIV_BIBFILE} <<EOF
83 url={https://arxiv.org/pdf/${id}}
89 ######################################################################
101 FIRST_AUTHOR="${line}"
103 nb_authors=$((nb_authors+1))
104 AUTHORS="${AUTHORS}${line}"
105 done < <(grep '<meta name="citation_author"' "${tmp}" | sed -e 's/^.*content="\([^,.]*\), .*$/\1/')
107 TITLE=$(grep '<meta name="citation_title"' ${tmp} | sed -e 's/^.*content="\([^"]*\)".*$/\1/')
108 YEAR=$(echo ${id} | sed -e 's/^\(..\).*$/20\1/')
110 if [[ ${nb_authors} -gt 3 ]]
112 AUTHORS="${FIRST_AUTHOR} et al"
115 TITLE="$(echo "${AUTHORS} - ${TITLE} ${YEAR} ${id}.pdf" | sed -e 's/ /_/g')"
117 mv -v "${filename}" "${ARXIV_BIBDIR}/${TITLE}"
119 ######################################################################