User:Slick/convert non-interlaced botscript V2.sh
Jump to navigation
Jump to search
cat list.txt | while read file ; do
if ! grep -m 1 "^${file}$" log/done.log &> /dev/null ; then
number="`expr ${number} + 1`"
echo "[${number}] process ${file} ... "
title="File:${file}"
tmpfile="`tempfile`"
xml="`curl --silent -G --data \"action=query\" --data \"prop=imageinfo\" --data \"format=xml\" --data \"iiprop=url|size\" --data-urlencode \"titles=${title}\" http://commons.wikimedia.org/w/api.php | tr '[\r\n]' ' '`"
url="`echo \"${xml}\" | sed 's/url=/\nurl=/g'| grep "url=" | head -n 1|sed '/url/s/\(.*url=\)\(.*\)/\2/' |awk -F\\" '{print $2}'`"
echo "> downloading ${url} ... "
echo -n "${file}" >> log/download.log
wget --quiet -t 5 -O "${tmpfile}" "${url}" && echo " OK" >> log/download.log || echo " FAIL" >> log/download.log
echo -n "${file}" >> log/jpegtran.log
echo "> check file ... "
#https://gist.github.com/3907106
check=$(exiftool -fast2 "${tmpfile}" | grep -i "Encoding Process")
if grep -qi "Baseline DCT" <<< $check; then
echo "> already fine ... "
echo "${file}" >> log/done.log
echo " FINE" >> log/jpegtran.log
else
echo "> convert file ... "
jpegtran -copy all -perfect "${tmpfile}" > "${tmpfile}.jpegtran.jpg" && echo " OK" >> log/jpegtran.log || echo " FAIL" >> log/jpegtran.log
echo "> get current raw content ... "
text="`curl --silent -G --data-urlencode \"title=${title}\" --data \"action=raw\" http://commons.wikimedia.org/w/index.php`"
if [ "${text}" != "" ] ; then
echo "> uploading ${file} ... "
echo ">> ${file}" >> log/upload.log
yes | python pywikipedia/upload.py -keep -filename:${file} -noverify ${tmpfile}.jpegtran.jpg "${text}" &>> log/upload.log && echo "${file}" >> log/done.log
else
echo "> text fail, ignoring file ... "
echo "${file}" >> log/done.log
echo "${file}" >> log/fail.log
fi
fi
test -e "${tmpfile}" && rm "${tmpfile}"
test -e "${tmpfile}.jpegtran.jpg" && rm "${tmpfile}.jpegtran.jpg"
fi
done