Skip to content

Instantly share code, notes, and snippets.

@yuzebin
Last active June 15, 2018 08:10
Show Gist options
  • Save yuzebin/694b2082a9b5c7e4c1aeee0328899fa7 to your computer and use it in GitHub Desktop.
Save yuzebin/694b2082a9b5c7e4c1aeee0328899fa7 to your computer and use it in GitHub Desktop.
网易公开课下载脚本 open.163.com
#!/usr/bin/env bash
# author: yuzebin AT gmail
# 20180614
# open163_dl.sh
main() {
mkdir -p $2
cd $2
curl $1 | grep -e "http://open.163.com/movie/" | enca -L zh -x UTF-8 | sed -e "s/\<a href=\"//g" -e "s/\>//g" -e "s/<\/a//g" | grep -v class | sed -e "s/\ //g"> $2.lst
num=0
for i in `cat $2.lst`; do
let "num = $num + 1";
curl -A "Mozilla/5.0 (iPad; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1" `echo $i | awk -F"\"" '{print $1}'` | grep -ohE "https?://[a-zA-Z0-9\.\/_&=@$?~#-]*" | grep m3u8 | xargs -I{} ffmpeg -i {} -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 "$2_${num}_`echo $i | awk -F'\"' '{print $2}'`.mp4";
done
cd ..
}
if [[ $# -ne 2 ]]; then
echo "Install: brew install enca ffmpeg curl"
echo "Usage : $0 course_rul course_name"
echo "Example: $0 http://open.163.com/special/opencourse/bianchengdaolun.html 编程导论"
else
main $1 $2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment