dou因视频下载
final static String fileSrc = "F:"+ File.separator + "down" + File.separator;public static void main(String[] args) {
//文件地址
String fileSrc = "F:" + File.separator + "360download" + File.separator;
//文件名称
String fileSuffix = "3.txt";
//将批量准备下载的链接放入txt文件
//格式为: 文件名下载链接
readFileByLine(fileSrc, fileSuffix);
//单个下载的链接
dowVedio("test.mp4","https://www.douyin.com/video/7209110067788942649");
}
public static boolean isInteger(String str) {
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
return pattern.matcher(str).matches();
}
/**
* fileSrc = "盘符"+"存放路径文件夹"
* @Param buffer
* @param num
* @return
*/
public static boolean isExists(StringBuffer buffer, StringBuffer num) {
String src = "【" + num.toString() + "】" + buffer.toString().substring(buffer.toString().indexOf("*") + 1, buffer.toString().indexOf(" "));
String vedioSuffix = ".mp4";
if (new File(fileSrc + src + vedioSuffix).exists()) {
System.out.println("文件已存在");
return true;
}
return false;
}
/**
* 按行读取文件
*
* @param
*/
public static void readFileByLine(String fileSrc, String fileSuffix) {
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(300);
try {
File file = new File(fileSrc + fileSuffix);
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
String strLine = null;
StringBuffer buffer = new StringBuffer();
StringBuffer num = new StringBuffer();
int lineCount = 1;
while (null != (strLine = bufferedReader.readLine())) {
// System.out.println("第[" + lineCount + "]行数据:[" + strLine + "]");
if (strLine.contains("\\")) {
if (isInteger(strLine.substring(1))) {
num.append(strLine.substring(1));
}
}
if (strLine.contains("*")) {
buffer.append(strLine);
if (isExists(buffer, num)) {
//break;结束所有循环
num.delete(0, num.length());
buffer.delete(0, buffer.length());
continue;//立即结束本次循环,继续执行下一次循环。
}
Thread.sleep(9000);
fixedThreadPool.execute(new Runnable() {
@Override
public void run() {
//do something
String OldUrl = buffer.toString();
int httpOne = buffer.toString().indexOf("h");
int httpTwo = buffer.toString().lastIndexOf("/");
String src = "【" + num + "】" + buffer.toString().substring(buffer.toString().indexOf("*") + 1, buffer.toString().indexOf("%"));
src = src.replace(".", "")
.replace("…", "")
.replace("“", "")
.replace("\"", "")
.replace("!", "")
.replace("?", "")
.replace(":", "")
.replace("/", "");
String vedioSuffix = ".mp4";
System.out.println("正在保存:" + src + " 正极:" + httpOne + " 负极:" + httpTwo);
dowVedio(fileSrc + src + vedioSuffix,
OldUrl.substring(httpOne, httpTwo));
// System.out.println("mn");
// System.out.println(buffer.toString().substring(buffer.toString().indexOf("h"),buffer.toString().indexOf("复")));
}
});
Thread.sleep(1000);
num.delete(0, num.length());
buffer.delete(0, buffer.length());
// System.out.println(strLine.substring(strLine.indexOf("h"),strLine.indexOf("复")));
}
lineCount++;
}
fixedThreadPool.shutdown();//关闭线程池
} catch (Exception e) {
e.printStackTrace();
}
}
public static void getFile(InputStream is, String fileName) throws IOException {
BufferedInputStream in = null;
BufferedOutputStream out = null;
in = new BufferedInputStream(is);
out = new BufferedOutputStream(Files.newOutputStream(Paths.get(fileName)));
int len = -1;
byte[] b = new byte[1024];
while ((len = in.read(b)) != -1) {
out.write(b, 0, len);
}
in.close();
out.close();
}
public static String dowVedio(String saveFileName, String urlStr) {
InputStream inputStream = null;
HttpURLConnection urlConnection = null;
try {
String dowUrl = getDowUrl(urlStr);
URL url = new URL(dowUrl);
urlConnection = (HttpURLConnection) url.openConnection();
//Post Request Define:
urlConnection.setRequestMethod("GET");
urlConnection.connect();
inputStream = urlConnection.getInputStream();
getFile(inputStream, saveFileName);
} catch (Exception e) {
throw new RuntimeException("下载失败!");
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
if (urlConnection != null) {
urlConnection.disconnect();
}
} catch (IOException e) {
e.printStackTrace();
}
return "成功!";
}
}
public static String getDowUrl(String h) {
//https://v.douyin.com/JogG5tc/ https%3A//v.douyin.com/Joguhrm/";
String param = "?url=";
String http = h.replaceAll(":", "%3A").trim();
String r = "&r=" + SnowflakeIdWorker.generateId().toString().substring(0, 16);
String s = "&s=" + UUID.randomUUID().toString().replaceAll("-", "");
String urls = "https://3g.gljlw.com/diy/douyin.php" + param + http + r + s;
String downloadURL = null;
try {
URL url = new URL(urls);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
//Post Request Define:
urlConnection.setRequestMethod("GET");
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
String responseStr = ConvertToString(inputStream);
String elemStart = "<textarea name=\"book_content\" class=\"KL_bbs_textarea\" rows=\"5\" style=\"width:100%\">";
String elemEnd = "</textarea>";
int indexa = responseStr.indexOf(elemStart);
int indexb = responseStr.indexOf(elemEnd);
downloadURL = responseStr.substring(indexa + elemStart.length(), indexb);
} catch (Exception e) {
e.printStackTrace();
}
return downloadURL;
}
public static String ConvertToString(InputStream inputStream) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder result = new StringBuilder();
String line = null;
try {
while ((line = bufferedReader.readLine()) != null) {
result.append(line).append("\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
inputStreamReader.close();
inputStream.close();
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return result.toString();
} 请参考这篇置顶帖插入代码
【公告】发帖代码插入以及添加链接教程(有福利)
https://www.52pojie.cn/thread-713042-1-1.html
(出处: 吾爱破解论坛) nanjie212 发表于 2023-3-14 11:41
虽然看不懂,但不影响崇拜感。编程小白想提个问题:想做一款提升无纸化办公的系统需要学习哪类知识?需要实 ...
飞书就可以做到吧 nanjie212 发表于 2023-3-14 11:41
虽然看不懂,但不影响崇拜感。编程小白想提个问题:想做一款提升无纸化办公的系统需要学习哪类知识?需要实 ...
前后端就可以了呀,搜索管理系统就行 没看明白,要继续学习了。。。。 看不懂{:1_908:}大神直接上破解版APP可以不? 感谢楼主的分享 要继续学习了。。。。 虽然看不懂,但不影响崇拜感。编程小白想提个问题:想做一款提升无纸化办公的系统需要学习哪类知识?需要实现的功能例如数据统计、文件下发、材料上报、提醒公示、沟通交流、传达领导签批指示等等。 谢谢分享 看不懂,还是要继续学习啊 感谢楼主分享,学习了!