吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2157|回复: 69
收起左侧

[Java 原创] dou因视频下载

  [复制链接]
lishizhendipi 发表于 2023-3-14 11:26
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();
    }

免费评分

参与人数 9吾爱币 +3 热心值 +9 收起 理由
LoyiGood + 1 + 1 谢谢@Thanks!
安道尔的鱼 + 1 + 1 热心回复!
kaoyu + 1 谢谢@Thanks!
yinzhe116 + 1 谢谢@Thanks!
fuwei52406 + 1 用心讨论,共获提升!
YangHC123 + 1 谢谢@Thanks!
ljp2580369 + 1 + 1 谢谢@Thanks!
taotao1314520 + 1 可以可以如果能出个exe文件就更好了
wang92643 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

苏紫方璇 发表于 2023-3-14 11:33
请参考这篇置顶帖插入代码
【公告】发帖代码插入以及添加链接教程(有福利)
https://www.52pojie.cn/thread-713042-1-1.html
(出处: 吾爱破解论坛)
mumarc 发表于 2023-3-14 13:30
nanjie212 发表于 2023-3-14 11:41
虽然看不懂,但不影响崇拜感。编程小白想提个问题:想做一款提升无纸化办公的系统需要学习哪类知识?需要实 ...

飞书就可以做到吧
xiaofendui001 发表于 2023-3-14 11:57
nanjie212 发表于 2023-3-14 11:41
虽然看不懂,但不影响崇拜感。编程小白想提个问题:想做一款提升无纸化办公的系统需要学习哪类知识?需要实 ...

前后端就可以了呀,搜索管理系统就行
newlan 发表于 2023-3-14 11:33
没看明白,要继续学习了。。。。
小狸momo 发表于 2023-3-14 11:38
看不懂大神直接上破解版APP可以不?
Zeusky 发表于 2023-3-14 11:40
感谢楼主的分享
yexinzzz 发表于 2023-3-14 11:41
要继续学习了。。。。
nanjie212 发表于 2023-3-14 11:41
虽然看不懂,但不影响崇拜感。编程小白想提个问题:想做一款提升无纸化办公的系统需要学习哪类知识?需要实现的功能例如数据统计、文件下发、材料上报、提醒公示、沟通交流、传达领导签批指示等等。
llh0101 发表于 2023-3-14 11:41
谢谢分享
kuangpk2023 发表于 2023-3-14 11:41
看不懂,还是要继续学习啊
by3721 发表于 2023-3-14 11:42
感谢楼主分享,学习了!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-10 05:18

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表