1.服务器端,采用PHP框架,扫描视频文件夹下所有MP4视频并发布到数据库函数:
<?php
function dir_list($dir) {
if(!is_dir($dir)) return false;
$dir_list = array();
$opendir = opendir($dir);
if($opendir) {
while(($file = readdir($opendir)) !== false) {
if($file !== '.' && $file !== '..') {
$tem = $dir . '/' . $file;
if(is_dir($tem)) {
//$dir_list[$tem . '/'] = $file . '/';
//dir_list($tem);
} else {
if(strstr($file, 'mp4')){
$dir_list[] = $file;
}
}
}
}
closedir($opendir);
return $dir_list;
}
}
//$dir = dir_list('/www/wwwroot/www.xxxx.com/video/gaoxiao');
// $sum = count($dir);
// print_r($dir)
..............
$name = $_POST['taskid'];
/*iconv方法是为了防止中文乱码,保证可以创建识别中文目录,不用iconv方法格式的话,将无法创建中文目录*/
$dir = iconv("UTF-8", "GBK",$name);
$dir = "/www/wwwroot/www.xxxx.com/video/".$dir;
if (!file_exists($dir)){
mkdir ($dir,0777,true);}
.............
$dirf = dir_list('/www/wwwroot/www.xxxx.com/video/'.$taskid);
$sum = count($dirf);
for($u = 0; $u<$sum; $u++)
{
unset($_POST['id']);
$_POST['url']="https://".$_SERVER['HTTP_HOST']."/video/".$_POST['taskid']."/".urlencode($dirf[$u]);
$_POST['filename']=$dirf[$u];
$_POST['title']=str_replace("抖音小助手","",str_replace(".mp4","",$dirf[$u]));
$_POST['ifread']="0";
if($bw->insert('bw_douyinvideo', $_POST))
.............
?>
2.autojs获取链接函数,替换http.get
/**
url123 = 网址
lgg = 1 则打印网址日志
mods
0=返回源码-
1=返回json
2=返回字节
3=返回body
**/
function fa_get(url123, lgg, mods) {
if (lgg == 1) {
console.log("[fa_get]", url123)
}
var fan = undefined;
var codeee = undefined;
try {
codeee = http.get(url123)
} catch (e) {
codeee = undefined;
console.log("[fa_get]", "get异常1:" + e)
}
if (codeee == undefined) {
try {
codeee = http.get(url123)
} catch (e) {
codeee = undefined;
console.log("[fa_get]", "get异常2:" + e)
}
if (codeee == undefined) {
try {
sleep(5000);
codeee = http.get(url123)
} catch (e) {
codeee = undefined;
console.log("[fa_get]", "get异常3:" + e)
}
}
}
if (codeee != undefined && codeee.statusCode == 200) {
if (mods == 0) {
try {
fan = codeee.body.string()
} catch (e) {
fan = undefined;
console.log("[fa_get]", "codeee.body.string():" + e)
}
} else if (mods == 1) {
try {
fan = codeee.body.json()
} catch (e) {
fan = undefined;
console.log("[fa_get]", "codeee.body.json():" + e)
}
} else if (mods == 2) {
try {
fan = codeee.body.bytes()
} catch (e) {
fan = undefined;
console.log("[fa_get]", "codeee.body.bytes():" + e)
}
} else if (mods == 3) {
try {
fan = codeee.body
} catch (e) {
fan = undefined;
console.log("[fa_get]", "codeee.body:" + e)
}
}
}
return fan
}
3.autojs下载视频并保留到手机本地代码
jsonr = fa_get(server+"/video.php?taskid="+taskid,0,1);//JSON.parse(r);
if(jsonr== undefined){task=task-1;toastLog("视频服务器连接失败");continue;}
uid = jsonr.dyid;
nicname = jsonr.nicname;
url=jsonr.url;
filename=jsonr.filename;
title=jsonr.title;
limit=jsonr.limit;
amount=jsonr.amount;
storage.put("url", url);
storage.put("title",title);
toastLog("今天第"+task+"/"+limit+"次任务");
toastLog("视频库"+taskid+"还有"+amount+"条数据");
if(url!="NULL" && amount>0){
if(net==null||!net.isAvailable()){
toastLogLog("网络连接不可用!");
task=task-1;
continue;
}else{
device.vibrate(2000);
toastLog("正在下载视频["+filename+"]");
times=filename;
storage.put("times",times);
var thread = threads.start(function(){
taskid=storage.get("taskid");
times=storage.get("times");
url=storage.get("url");
var r=fa_get(url,0,2);
sleep(random(6000,10000));
var scriptPath='/storage/emulated/0/DCIM/'+taskid+"/"+"lv_0_"+times+'.mp4';
storage.put("scriptPath",scriptPath);
files.writeBytes(scriptPath,r);
toastLog("下载结束");
});
4.autojs推送视频到抖音(已测试兼容安卓6-安卓9)
运行后会调出分享界面再用文本判断抖音按钮即可
如果有大神能告知直接推送到抖音的方法不胜感激!
function sharefiles(videoPath) {
var imageUri =app.getUriForFile(videoPath);
var shareIntent = new Intent("android.intent.action.SEND");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("video/*");
context.startActivity(Intent.createChooser(shareIntent, "分享到").setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_GRANT_READ_URI_PERMISSION));
};
5.autojs删除手机本地路径下视频
function getFilesFromPath(path) {
/*格式:H.getFilesFromPath(文件夹路径)*/
/*解释:获取文件夹所有文件和文件夹 递归遍历 返回文件路径数组*/
var arrDir = new Array();
var arrFile = new Array();
try {
var rp = /^([/][^\/:*?<>|]+[/]?)+$/;
if (rp.test(path) == false) throw "非法文件路径,H.getFilesFromPath(?);" + path;
} catch (err) {
log(err);
exit();
}
/*获取path目录下所有MP4文件*/
var arr = files.listDir(path);
//, function(name){ return name.endsWith(".m4a") && files.isFile(files.join(dir, name));});
/*遍历文件和文件夹*/
for (var i = 0; i < arr.length; i++) {
/*连接路径*/
newPath = files.join(path, arr[i]);
/*判断路径类型*/
if (files.isDir(newPath)) {
//arrDir.push(newPath);
/*递归遍历文件夹*/
var arrF = getFilesFromPath(newPath);
arrDir = arrDir.concat(arrF);
} else if (files.isFile(newPath) & files.getExtension(newPath)=="mp4") {
arrFile.push(newPath);
}
}
/*按字母升序排序数组*/
arrDir.sort();
arrFile.sort();
/*连接数组并返回*/
return arrDir.concat(arrFile);
//return arrFile;
}
//autojs删除本地所有已缓存视频
function delvideo(arr){
if (arr.length != 0) {
var oldsum=arr.length;
toastLog("找到"+oldsum+"段视频缓存,准备删除");
arr.forEach(function(currentValue, index) {
files.remove(arr[index]);
})
} else {
toastLog("视频缓存为空");
}
}
删除服务器上已保存的视频(PHP)
$taskid= $_GET['taskid'];
$filename= $_GET['filename'];
if(!empty($taskid) && !empty($filename)){
$name = $_GET['taskid'];
/*iconv方法是为了防止中文乱码,保证可以创建识别中文目录,不用iconv方法格式的话,将无法创建中文目录*/
$dir = iconv("UTF-8", "GBK",$name);
$dir = "/www/wwwroot/www.xxxx.com/video/".$dir."/".$filename;
$bw->query('DELETE FROM bw_douyinvideo WHERE filename= "'.$filename.'"');
delFile($dir);
if(file_exists($dir)){
echo '{"statues":"远程服务器删除失败!"}';
}else{
echo '{"statues":"远程服务器删除成功!"}';
}
}else{
echo '{"statues":"参数错误"}';
}
autojs获取返回结果
jsonr = fa_get(server+"/videodel.php?taskid="+taskid+"&filename="+filename,0,1);//JSON.parse(r);
if(jsonr== undefined){toastLog("视频服务器连接失败");
}else{
statues = jsonr.statues;
toastLog(statues);
}