批量下载 ffmpeg samples

需要下载 samples.ffmpeg.org 上的视频文件来做测试,写个脚本grab.sh搞定,幸甚至哉,歌以咏志

用法: ./grab.sh   ~/my/samples/folder

#!/bin/bash


DEFAULT_PATH=$(cd $(dirname $0); pwd)
SAMPLES_PATH=${1:-${DEFAULT_PATH}}

[ ! -d "${SAMPLES_PATH}" ] && echo "samples folder(${SAMPLES_PATH}) does NOT exist, create it ..."  && mkdir -p "${SAMPLES_PATH}"

[ ! -d "${SAMPLES_PATH}" ] && echo "Failed to create samples folder(${SAMPLES_PATH})"  && exit -1
cd "${SAMPLES_PATH}"

[ ! -f allsamples.txt ] &&  wget http://samples.ffmpeg.org/allsamples.txt

while read f; do
	[ "$f" == "." ] && continue;
	p=${f%/*}
	file_url="http://samples.ffmpeg.org/${f:2}"

	if [ "$p" != "." ]; then
		[ -f "$p" ] && echo "$p should be folder, remove file $p and create folder" && rm "$p" 
		[ ! -e "$p" ] &&  mkdir -p "$p"
	fi
	wget "$file_url"  -O "$f"
done < allsamples.txt

你可能感兴趣的:(shell,脚本,Linux,ffmpeg,bash,批量下载)