Download from EX.UA

#!/bin/bash
#
#Bash script for downloading media from site ex.ua
#Writen by oleksdovz@gmail.com
#
# ver 0.3
set -e

function usage() {
echo -e "Usage $0 options:
run:
$0 -b -l \nor\t-l 'http://ex.ua/.../123456789.urls' \nor\t-l '' -n ''

-l download files from remote filelist
-h print help message
-n optionally describe content: -n 'media'
"

}


while getopts ":l:i:ln:in:hn" opt; do
case "$opt" in

i) list="$OPTARG"
;;
l) link=${OPTARG}
echo "Debud:: $link"
if [[ "${link}" =~ ^http.*.urls ]]
then
echo ""
else
echo -e "\nError: link not contain 'http' or 'urls'\n"
usage
exit 1
fi
;;
h)usage
exit 1
;;
n) _describe=${OPTARG}
if [[ -z "${_describe}" ]]
then
usage
exit 1
else
_describe=`echo ${_describe} | sed 's/ /_/g;s/(/_/g;s/)/_/g;s/,/_/g;s/\./_/g;s/\///g'`

fi
;;
esac
done

## [ -n "${list}" ]
if [[ -z ${link} ]]
then
usage
fi
echo "link:: $link"

if [[ -n ${link} ]]
then
echo "Info:: Will be used link: '${link}'"
echo "Info:: Will be added to store path part - '${_describe}'"
sleep 2;

_prefix=`echo "${link}" | cut -d "/" -f5 | cut -d "." -f1`

if [ -n "${_describe}" ]
then
_pw="${HOME}/ex-ua-media/${_prefix}_${_describe}_EX_UA";
else
_pw="${HOME}/ex-ua-media/${_prefix}_EX_UA"
fi

mkdir -pv "${_pw}" || (echo "Error cannt create ${_pw} "; exit 1 )

wget --trust-server-names=on --restrict-file-names=nocontrol -c "${link}" -P "${_pw}" -t 0
wget --trust-server-names=on --restrict-file-names=nocontrol -c -i "`ls ${_pw}/*.urls`" -P ${_pw} -t 0

fi

Коментарі