全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
楼主: 揽月

[疑问] 【开源】20分钟下载MM131全站图片Java程序

  [复制链接]
发表于 2019-6-10 11:41:04 | 显示全部楼层
emm可以学习学习代码
发表于 2019-6-10 11:46:44 | 显示全部楼层
前排留名,谢谢大佬的共享
发表于 2019-6-10 11:55:05 | 显示全部楼层
配合你的Beauty项目来一份呀
发表于 2019-6-10 11:58:07 | 显示全部楼层
没有环境运行代码啊
发表于 2019-6-10 12:04:27 | 显示全部楼层
  1. package ee.coding.download;

  2. import ee.coding.download.pojo.Target;
  3. import ee.coding.download.service.ITargetService;
  4. import ee.coding.download.service.impl.TargetServiceImpl;
  5. import ee.coding.download.util.CommonUtil;
  6. import ee.coding.download.util.DownloadUtil;

  7. import java.util.concurrent.ExecutorService;
  8. import java.util.concurrent.Executors;

  9. public class Download {
  10.     private final String referer = CommonUtil.getProperties().getProperty("referer");
  11.     private final String downloadDirectory = CommonUtil.getProperties().getProperty("downloadDirectory");
  12.     private final ITargetService service = new TargetServiceImpl();

  13.     public static void main(String[] args) {
  14.         final Download download = new Download();
  15.         ExecutorService pool = Executors.newFixedThreadPool(20);
  16.         for (int i = 0; i < 5000; i++) {
  17.             final int j = i;
  18.             pool.submit(new Runnable() {
  19.                 public void run() {
  20.                     download.download(j);
  21.                 }
  22.             });
  23.         }
  24.     }

  25.     private void download(int i) {
  26.         String directory = "";
  27.         Integer totalPicCount = 0;
  28.         long beginTime = System.currentTimeMillis();
  29.         Target target = service.get(i);
  30.         if (target == null) {
  31.             return;
  32.         }
  33.         directory = downloadDirectory + target.getPath() + "/";
  34.         String urls = target.getUrls();
  35.         String[] urlArr = urls.split("#");
  36.         Integer index = 0;
  37.         for (String url : urlArr) {
  38.             if (DownloadUtil.download(url, referer, directory, ++index + ".jpg")) {
  39.                 System.out.println("成功下载" + ++totalPicCount + "张图片,URL: " + url);
  40.             }
  41.         }
  42.         System.out.println("总用时(毫秒):" + (System.currentTimeMillis() - beginTime));
  43.     }
  44. }
复制代码

你试试吧,没改动你的逻辑,你也可以将download逻辑抽取为TargetDownloader类。
或者按照你原来的方式,将ThreadN抽取为一个类,start,end设置为参数,比你直接建这么多个类也好许多。
发表于 2019-6-10 12:07:21 | 显示全部楼层
https://dev.tencent.com/u/iht/p/download/git 打开白屏
发表于 2019-6-10 12:10:03 | 显示全部楼层
一个人下载就好了
多了把人家mm131搞挂就不好了
发表于 2019-6-10 12:12:04 来自手机 | 显示全部楼层
谢谢大佬分享
发表于 2019-6-10 12:20:26 | 显示全部楼层
代码规范太差了,,去看看设计模式吧
发表于 2019-6-10 12:21:37 | 显示全部楼层
这是jdk9之前jdk自带的httpclient 建议换成jdk9之后的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-5-4 12:24 , Processed in 0.062328 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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