- 1.将
code.js
和download.sh
下载并放置同一目录下 - 2.将
download.sh
中的COUNT
和WEB_PAGE
变量的值替换为你需要下载的内容 - 3.执行
download.sh
, 如提示无权限, 可以先执行chmod +x download.sh
然后在执行脚本
Last active
September 26, 2020 04:45
-
-
Save 0x1306a94/9a901e2cd1f8d5c8ea43a929b460f605 to your computer and use it in GitHub Desktop.
批量下载AcFun视频
This file contains 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
system = require('system') | |
fs = require('fs'); | |
var page = require('webpage').create(); | |
page.settings.userAgent= 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'; | |
const address = system.args[1]; | |
var count = parseInt(system.args[2]) | |
var indexNumber = 1 | |
var playList = [] | |
// page.onConsoleMessage = function(msg) { | |
// console.log('The web page said: ' + msg); | |
// }; | |
var parseURL = function(number) { | |
if (number > count) { | |
console.log("解析完成...."); | |
const path = "playlist.json" | |
if (playList.length >= 2 && playList[0].name == playList[1].name) { | |
// 移除第一个,重复的 | |
playList.delete(0); | |
} | |
fs.write(path, JSON.stringify(playList, null, "\t"), "w"); | |
phantom.exit(); | |
return; | |
} | |
var url = address + '_' + number; | |
console.log(url) | |
page.open(url, function (status) { | |
//Page is loaded! | |
if (status !== 'success') { | |
console.log('Unable to post!'); | |
phantom.exit(); | |
} else { | |
console.log("完成......"); | |
var script = "function(){ return window.videoInfo; }"; | |
var obj = page.evaluateJavaScript(script) | |
var play = JSON.parse(obj.currentVideoInfo.ksPlayJson) | |
playList.push({name: obj.currentVideoInfo.fileName, url: play.adaptationSet.representation[0].url}) | |
indexNumber += 1; | |
parseURL(indexNumber); | |
} | |
}); | |
}; | |
parseURL(indexNumber); |
This file contains 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/sh | |
# 检查命令是否存在 | |
function check_commond() { | |
command -v $1 >/dev/null 2>&1 || { echo >&2 "I require \033[31m\033[01m\033[05m[ $1 ]\033[0m but it's not installed. Aborting. Use the \033[31m\033[01m\033[05m$2\033[0m command to install"; exit 1; } | |
} | |
check_commond phantomjs "brew cask install phantomjs" | |
check_commond jq "brew install jq" | |
check_commond ffmpeg "brew install ffmpeg" | |
COUNT=20 | |
# phantomjs code.js 'https://www.acfun.cn/v/ac15856717' $COUNT | |
PLAY_LIST='playlist.json' | |
if [[ ! -f $PLAY_LIST ]]; then | |
echo "播放列表文件不存在"; | |
exit 0; | |
fi | |
DIR="$PWD/Videos" | |
mkdir -p $DIR | |
echo "" | |
echo "" | |
echo "" | |
echo "开始下载......." | |
for((i=0;i<$COUNT;i++)); do | |
key1=".[$i].name" | |
fileName=$(cat $PLAY_LIST | jq $key1 | sed 's/\"//g') | |
key2=".[$i].url" | |
url=$(cat $PLAY_LIST | jq $key2 | sed 's/\"//g') | |
echo "ffmpeg -i $url -y -c copy $DIR/$fileName.mp4" | |
ffmpeg -i $url -y -c copy "$DIR/$fileName.mp4" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment