User:Slick/convert non-interlaced botscript.sh

From Wikimedia Commons, the free media repository
Jump to: navigation, search
cat links.txt | while read file ; do
 
	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 "> convert file ... "
 
	echo -n "${file}" >> log/jpegtran.log
	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 "Download text failed."
		echo "${title}"
		exit 1
	fi
 
	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
 
	rm "${tmpfile}"
	rm "${tmpfile}.jpegtran.jpg"
done