Created
April 26, 2017 22:40
-
-
Save dlight/ac5db4bc1dd23331e12e15536b66a766 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
. $(dirname $(realpath $0))/lib.sh | |
[[ $# -lt 1 ]] && echo ERRO: yt-step chamado sem parâmetro && exit 1 | |
file=$(realpath $1) | |
lock=$controld/lock/$(basename $file) | |
mkdir -p $lock | |
trap 'rmdir "$lock" 2> /dev/null' INT TERM EXIT QUIT HUP | |
url=$(grab_url $file) | |
target=$(cat $file) | |
codified=$(basename $file) | |
echo downloading $url to $target | |
mkdir -pv $target | |
mkdir -p down/$codified | |
cd down/$codified | |
{ | |
echo | |
youtube-dl --write-info-json --restrict-filenames \ | |
--user-agent 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36' \ | |
--referer "$url" "$url" -o \ | |
'%(title)s:%(extractor)s.%(id)s.%(ext)s' | |
echo | |
} | |
cd ../.. | |
mv -v down/$codified/*.json json | |
multires=$(realpath $(find down/$codified -type f)) | |
i=0 | |
for res in $multires; do | |
echo qq | |
i=$((i+1)) | |
if [[ $i -eq 1 ]]; then | |
ext= | |
else | |
ext='::'$i | |
fi | |
final=$target/$(basename $res) | |
if [[ -f $final ]]; then | |
echo ERRO: $final existe "(download de $url)" >&2 | |
md5sum $res $final | |
rm -f $res | |
continue | |
fi | |
mv -v $res $final | |
cd completed | |
{ | |
relfinal=$(realpath --relative-to=. $final) | |
ln -s $relfinal "$codified"$ext | |
} | |
cd .. | |
done | |
rmdir down/$codified | |
rm -v $file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment