├── .gitignore ├── LanzouDownloader.iml ├── out ├── META-INF │ └── MANIFEST.MF └── artifacts │ └── LanzouDownloader_jar │ └── LanzouDownloader.jar ├── pom.xml ├── readme.md └── src ├── main └── kotlin │ └── com │ └── wan │ ├── app │ ├── MyApp.kt │ ├── Styles.kt │ └── test.kt │ ├── util │ └── LanzouParse.kt │ └── view │ ├── AboutView.kt │ ├── DescView.kt │ ├── ItemView.kt │ ├── ListView.kt │ └── MainView.kt └── resources └── img ├── 2.png ├── icon.png ├── weixin.jpg └── zhifubao.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Kotlin template 3 | # Compiled class file 4 | *.class 5 | .idea/ 6 | target/ 7 | test.kt 8 | # Log file 9 | *.log 10 | 11 | # BlueJ files 12 | *.ctxt 13 | 14 | # Mobile Tools for Java (J2ME) 15 | .mtj.tmp/ 16 | 17 | # Package Files # 18 | 19 | *.war 20 | *.nar 21 | *.ear 22 | *.zip 23 | *.tar.gz 24 | *.rar 25 | 26 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 27 | hs_err_pid* 28 | 29 | -------------------------------------------------------------------------------- /LanzouDownloader.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /out/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: com.wan.app.MyApp 3 | 4 | -------------------------------------------------------------------------------- /out/artifacts/LanzouDownloader_jar/LanzouDownloader.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stars-one/LanzouDownloader/e0ab31004c34fb8e23aed16b6ccf7d81f0a0493f/out/artifacts/LanzouDownloader_jar/LanzouDownloader.jar -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.example 8 | tornadofx-maven-project 9 | 1.0 10 | jar 11 | 12 | 13 | 1.2.60 14 | 1.7.17 15 | 16 | 17 | 18 | 19 | org.jsoup 20 | jsoup 21 | 1.12.1 22 | 23 | 24 | net.sourceforge.htmlunit 25 | htmlunit 26 | 2.36.0 27 | 28 | 29 | no.tornado 30 | tornadofx 31 | ${tornadofx.version} 32 | 33 | 34 | org.jetbrains.kotlin 35 | kotlin-stdlib 36 | ${kotlin.version} 37 | 38 | 39 | org.jetbrains.kotlin 40 | kotlin-test 41 | ${kotlin.version} 42 | test 43 | 44 | 45 | com.google.code.gson 46 | gson 47 | 2.6 48 | 49 | 50 | 51 | 52 | src/main/kotlin 53 | 54 | 55 | org.jetbrains.kotlin 56 | kotlin-maven-plugin 57 | ${kotlin.version} 58 | 59 | 60 | compile 61 | compile 62 | 63 | compile 64 | 65 | 66 | 1.8 67 | 68 | 69 | 70 | test-compile 71 | test-compile 72 | 73 | test-compile 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 说明:master主分支版本为新版,新版由于采用了Jsoup来进行解析,所以解析速度较快 2 | 3 | **旧版由于速度较慢所以放弃,当然,还可以使用,请切换分支到old-version中进行下载jar包** 4 | 5 | **新版本v1.8,不打算开源,想使用软件请查看[https://stars-one.site/2020/07/20/lanzoudownloader](https://stars-one.site/2020/07/20/lanzoudownloader)** 6 | 7 | # 蓝奏云批量下载工具 8 | 一款可以批量下载蓝奏云分享的文件夹下的所有文件 9 | 10 | 基于HtmlUnit和Jsoup开源库,由于HTMLUnit依赖的第三方库较多,所以打包后的jar包文件有点大 11 | 12 | [蓝奏云下载地址](https://www.lanzous.com/b0cpwdmrc) 13 | 14 | [github地址](https://github.com/Stars-One/LanzouDownloader) 15 | 16 | ~~已更新v1.1版本(软件内并没有修改版本号,请知晓)~~ 17 | 18 | 19 | 20 | ## 需求 21 | 之前找电子书资源的时候,网友分享的蓝奏云地址,里面的文件有点多,但是,蓝奏云并没有批量下载功能,我又不想一个个点击下载,便是产生了这款软件 22 | 23 | ## 使用说明 24 | 需要Java环境,jdk1.8版本,win10可双击文件打开 25 | ## 软件功能 26 | - 支持有密码和无密码的蓝奏云连接 27 | - 自带下载功能,无需再次跳转到IDM中下载 28 | - 采用多线程解析和下载 29 | - 支持自动翻页(若分享的文件夹中文件过多,可以自动翻页,默认翻5页,可以在软件中进行设置) 30 | 31 | PS:过大的文件下载未进行过测试,有bug联系我,QQ1053894518 32 | 33 | **v1.1 新增自定义分享链接的解析** 34 | 35 | 下图截图即为自定义分享链接(此功能是蓝奏云的会员功能),由于没有具体的例子,所以暂不支持有提取码的自定义分享链接,如果有人乐意提供,我可以增加此功能 36 | 37 | ![](https://img2020.cnblogs.com/blog/1210268/202003/1210268-20200311134101354-869792422.png) 38 | 39 | **对你有帮助的话,希望得到你的赞赏与支持!** 40 | 41 | ![](https://img2018.cnblogs.com/blog/1210268/201906/1210268-20190610221153050-892061431.png) 42 | 43 | ## 截图 44 | ![](https://img2018.cnblogs.com/blog/1210268/202001/1210268-20200118183941480-1854744572.png) 45 | 46 | ![](https://img2018.cnblogs.com/blog/1210268/202001/1210268-20200118184027009-1031892218.png) 47 | 48 | ![](https://img2018.cnblogs.com/blog/1210268/202001/1210268-20200118184117720-1166218675.png) 49 | 50 | ![](https://img2018.cnblogs.com/blog/1210268/202001/1210268-20200118184210779-643145230.png) 51 | -------------------------------------------------------------------------------- /src/main/kotlin/com/wan/app/MyApp.kt: -------------------------------------------------------------------------------- 1 | 2 | package com.wan.app 3 | import com.wan.view.MainView 4 | import javafx.scene.image.Image 5 | import javafx.stage.Stage 6 | import tornadofx.* 7 | 8 | class MyApp: App(MainView::class, Styles::class){ 9 | override fun start(stage: Stage) { 10 | super.start(stage) 11 | stage.icons += Image("img/icon.png") 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/wan/app/Styles.kt: -------------------------------------------------------------------------------- 1 | package com.wan.app 2 | 3 | import javafx.scene.text.FontWeight 4 | import tornadofx.Stylesheet 5 | import tornadofx.box 6 | import tornadofx.cssclass 7 | import tornadofx.px 8 | 9 | class Styles : Stylesheet() { 10 | companion object { 11 | val heading by cssclass() 12 | } 13 | 14 | init { 15 | label and heading { 16 | padding = box(10.px) 17 | fontSize = 20.px 18 | fontWeight = FontWeight.BOLD 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/wan/app/test.kt: -------------------------------------------------------------------------------- 1 | package com.wan.app 2 | 3 | /** 4 | * 5 | * @author StarsOne 6 | * @date Create in 2019/12/31 0031 23:00 7 | * @description 8 | * 9 | */ 10 | fun main(args: Array) { 11 | 12 | 13 | /*val controller = MainController() 14 | val itemDatas = controller.download("https://www.lanzous.com/b607378", "ggdw") 15 | val dir = File("R:\\神话终将来临的放学后战争epub合集") 16 | 17 | val dirFile = File("下载") 18 | if (!dirFile.exists()) { 19 | dirFile.mkdirs() 20 | } 21 | for (itemData in itemDatas) { 22 | val file = File(dirFile, itemData.fileName) 23 | downloadFile(itemData.url, file) 24 | println(itemData.fileName + "已下载") 25 | }*/ 26 | // val url = "https://vip.d0.baidupan.com/file/?BGIHOQg5Dj9UXQszU2ZSPlBvADhR6QOkA5oE6lekB5tVsgHtD9oEtQPlU4MKuFXJUK9QsQTjUecA4FvHVo4G4QSQB+4IsA73VKQLuFOXUt1Q7ACNUZYD5QO+BItXKwfgVcIB8w+3BN4D01PiCvFV01AkUDAEK1EmAGVbe1ZsBm4EaAc1CAoOM1RmC2BTMFJiUDMAMVE4AzQDMwQkV20HdVVoAWQPYgRgA2NTNApnVWJQLFAlBCtRbgA1W21WOwY+BCsHYAhnDnVUMAtrUyhSZVBpADxRNwNjAzcEZFc8BzZVMQFnDzAEZwNhUzAKbFVkUG9QNgRsUWQANltqVjIGNwQ8B2AIZg4+VDALbFNiUn1QbwB1UXsDYwMiBHdXeAdjVScBPw82BG0DbVMyCmpVZlA7UGMEfVEnAG5bMFZvBmEEOQdhCGAObVQ7C29TM1JrUDsANVE8Ay8DIgR3V3sHO1VkAXgPdAQ2AzlTcgpjVWVQP1BiBGJRYQAzW2hWOQY+BDQHdgggDipUdQtgUzZSZlA/ADRRPwM5AzMEM1czBzNVcwEjDzsEIANoUzQKb1VjUCRQZARjUWAAKVtvVjoGNQQqB2EIZg5v" 27 | /* val mainController = MainController() 28 | val download = mainController.download("https://www.lanzous.com/b0cpr90ti") 29 | for (itemData in download) { 30 | println(itemData.toString()) 31 | } 32 | */ 33 | 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/main/kotlin/com/wan/util/LanzouParse.kt: -------------------------------------------------------------------------------- 1 | package com.wan.util 2 | 3 | import com.google.gson.Gson 4 | import org.jsoup.Jsoup 5 | import sun.net.www.protocol.http.HttpURLConnection.userAgent 6 | import java.util.* 7 | 8 | 9 | 10 | 11 | /** 12 | * 解析单条蓝奏云分享地址的真事链接 13 | * @author StarsOne 14 | * @date Create in 2020/3/10 0010 17:04 15 | */ 16 | class LanzouParse { 17 | 18 | fun getDownloadLink(url: String): String { 19 | //先获得iframe的src连接(包含电信下载,联通下载和普通下载的一个页面) 20 | val iframeUrl = getFrameUrl(url) 21 | //获得伪直链 22 | return getLink(iframeUrl) 23 | } 24 | 25 | private fun getLink(iframeUrl: String): String { 26 | val doc = Jsoup.connect(iframeUrl) 27 | .userAgent("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; .NET CLR 2.0.50727; CIBA)") 28 | .get() 29 | val scriptCodeText = doc.body().getElementsByTag("script").toString() 30 | //正则匹配,获得sign(之后post请求需要此数据) 31 | val signLine = Regex("var sg = '([\\w]+?)';").find(scriptCodeText)?.value as String 32 | val sign = signLine.substring(signLine.indexOf("'") + 1, signLine.lastIndex - 1) 33 | 34 | val postUrl = "https://www.lanzous.com/ajaxm.php" 35 | //请求头参数 36 | val header = HashMap() 37 | header["Accept-Language"] = "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2" 38 | header["referer"] = "https://www.lanzous.com" 39 | //请求参数 40 | val params = LinkedHashMap() 41 | params["action"] = "downprocess" 42 | params["sign"] = sign 43 | params["ves"] = "1" 44 | 45 | //获得伪链接(此处若没有请求头,会导致下一步访问获得伪链出现400错误) 46 | val result = Jsoup.connect(postUrl) 47 | .headers(header) 48 | .data(params) 49 | .post() 50 | .body() 51 | .text() 52 | 53 | //json转为实体类 54 | val lanzouData = Gson().fromJson(result, LanzouData::class.java) 55 | //拼接得到伪链 56 | val link = lanzouData.dom +"/file/"+ lanzouData.url 57 | 58 | //从请求头得到Location重定向地址(即真实下载地址) 59 | val reqHeads = Jsoup.connect(link) 60 | .headers(header) 61 | .ignoreContentType(true) 62 | .userAgent(userAgent) 63 | .followRedirects(false) 64 | .execute() 65 | .headers() 66 | return reqHeads["Location"] as String 67 | } 68 | 69 | 70 | private fun getFrameUrl(url: String): String { 71 | val doc = Jsoup.connect(url) 72 | .userAgent("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; .NET CLR 2.0.50727; CIBA)") 73 | .get() 74 | val result = doc.getElementsByTag("iframe")[0].attr("src") 75 | return "https://www.lanzous.com$result" 76 | } 77 | 78 | } 79 | data class LanzouData( 80 | val dom: String, 81 | val inf: Int, 82 | val url: String, 83 | val zt: Int 84 | ) -------------------------------------------------------------------------------- /src/main/kotlin/com/wan/view/AboutView.kt: -------------------------------------------------------------------------------- 1 | package com.wan.view 2 | 3 | import javafx.geometry.Pos 4 | import javafx.scene.text.FontWeight 5 | import tornadofx.* 6 | import java.awt.Desktop 7 | import java.net.URI 8 | 9 | class AboutView : View(" by stars-one") { 10 | 11 | override val root = vbox { 12 | 13 | vbox { 14 | paddingTop = 10.0 15 | spacing = 10.0 16 | setPrefSize(800.0, 300.0) 17 | text("蓝奏云批量下载 v1.1") { 18 | alignment = Pos.TOP_CENTER 19 | style { 20 | fontWeight = FontWeight.BOLD 21 | //字体大小,第二个参数是单位,一个枚举类型 22 | fontSize = Dimension(18.0, Dimension.LinearUnits.px) 23 | } 24 | } 25 | text("使用HtmlUnit和okhttp打造的蓝奏云批量下载工具") { 26 | alignment = Pos.TOP_CENTER 27 | } 28 | form { 29 | hbox(20) { 30 | fieldset { 31 | alignment = Pos.CENTER 32 | field("软件作者:") { 33 | text("stars-one") 34 | } 35 | field("项目地址:") { 36 | hyperlink("https://github.com/Stars-One/LanzouDownloader") { 37 | setOnMouseClicked { 38 | Desktop.getDesktop().browse(URI(this.text.toString())) 39 | } 40 | } 41 | } 42 | 43 | field("博客地址:") { 44 | hyperlink("www.cnblogs.com/stars-one") { 45 | tooltip(this.text.toString()) 46 | maxWidth = 300.0 47 | setOnMouseClicked { 48 | Desktop.getDesktop().browse(URI(this.text.toString())) 49 | } 50 | } 51 | } 52 | field("联系QQ:") { 53 | text("1053894518") 54 | } 55 | field("软件交流群:") { 56 | text("1046548165") 57 | } 58 | } 59 | fieldset { 60 | vbox(20) { 61 | text("对你有帮助的话,不妨打赏一波") { 62 | alignment = Pos.TOP_CENTER 63 | style { 64 | fontWeight = FontWeight.BOLD 65 | //字体大小,第二个参数是单位,一个枚举类型 66 | fontSize = Dimension(18.0, Dimension.LinearUnits.px) 67 | } 68 | } 69 | hbox(20) { 70 | vbox(15) { 71 | text("微信") { 72 | alignment = Pos.TOP_CENTER 73 | } 74 | imageview(url = "img/weixin.jpg") { 75 | alignment = Pos.TOP_CENTER 76 | fitHeight = 160.0 77 | fitWidth = 160.0 78 | isPreserveRatio = true 79 | } 80 | } 81 | vbox(15) { 82 | text("支付宝") { 83 | alignment = Pos.TOP_CENTER 84 | } 85 | imageview(url = "img/zhifubao.jpg") { 86 | alignment = Pos.TOP_CENTER 87 | fitHeight = 160.0 88 | fitWidth = 160.0 89 | isPreserveRatio = true 90 | } 91 | } 92 | } 93 | } 94 | } 95 | } 96 | 97 | } 98 | 99 | } 100 | 101 | } 102 | 103 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/wan/view/DescView.kt: -------------------------------------------------------------------------------- 1 | package com.wan.view 2 | 3 | import javafx.geometry.Pos 4 | import tornadofx.* 5 | 6 | /** 7 | * 说明自定义分享地址 8 | * @author StarsOne 9 | * @date Create in 2020/2/25 0025 13:59 10 | * @description 11 | * 12 | */ 13 | class DescView : View("My View") { 14 | override val root = vbox { 15 | setPrefSize(600.0,650.0) 16 | imageview(url = "img/2.png") { 17 | alignment = Pos.TOP_CENTER 18 | isPreserveRatio = true 19 | } 20 | text("上图的图片就不是属于自定义分享外链") 21 | text("如果打开的蓝奏云的分享页面与上面不同,那就是属于自定义分享,由于自定义分享外链需要开通蓝奏云会员才能创建,所以,暂时不支持有提取码的自定义外链(其实是没有作为测试的链接)") 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/kotlin/com/wan/view/ItemView.kt: -------------------------------------------------------------------------------- 1 | package com.wan.view 2 | 3 | import javafx.scene.control.CheckBox 4 | import javafx.scene.control.Hyperlink 5 | import javafx.scene.text.FontWeight 6 | import javafx.scene.text.Text 7 | import tornadofx.* 8 | import java.io.File 9 | import java.net.URL 10 | 11 | /** 12 | * 13 | * @author StarsOne 14 | * @date Create in 2020/1/2 0002 21:59 15 | * @description 16 | * 17 | */ 18 | class ItemView : View("My View") { 19 | var checkBox by singleAssign() 20 | var fileNameTv by singleAssign() 21 | var fileSizeTv by singleAssign() 22 | var downloadHyperLink by singleAssign() 23 | var timeTv by singleAssign() 24 | var flagTv by singleAssign() 25 | var flag = false //下载完成标志 26 | 27 | override val root = hbox { 28 | form { 29 | fieldset { 30 | 31 | field { 32 | setOnMouseClicked { 33 | checkBox.isSelected = !checkBox.isSelected 34 | } 35 | checkBox = checkbox { 36 | 37 | } 38 | flagTv = text() 39 | fileNameTv = text(""){ 40 | style { 41 | fontWeight = FontWeight.BOLD 42 | } 43 | } 44 | fileSizeTv = text(""){ 45 | style { 46 | fill = c("orange") 47 | } 48 | } 49 | timeTv = text(){ 50 | style { 51 | fill = c("#c792ea") 52 | } 53 | } 54 | downloadHyperLink = hyperlink { 55 | prefWidth = 200.0 56 | } 57 | 58 | } 59 | } 60 | } 61 | } 62 | 63 | fun downloadFile(dirPath: String) { 64 | if (dirPath.isBlank()) { 65 | //下载文件到默认下载目录 66 | //创建默认的下载目录 67 | val dirFile = File("蓝奏云下载") 68 | if (!dirFile.exists()) { 69 | dirFile.mkdirs() 70 | } 71 | runAsync { 72 | downloadFile(downloadHyperLink.text, File(dirFile, fileNameTv.text)) 73 | 74 | runLater { 75 | flagTv.text = "已下载" 76 | flagTv.fill = c("green") 77 | flag = true 78 | } 79 | } 80 | } else { 81 | //下载文件到用户选择的目录 82 | runAsync { 83 | downloadFile(downloadHyperLink.text, File(dirPath, fileNameTv.text)) 84 | runLater { 85 | flagTv.text = "已下载" 86 | flagTv.fill = c("green") 87 | flag = true 88 | } 89 | } 90 | } 91 | } 92 | 93 | /** 94 | * 下载文件到本地 95 | * @param url 网址 96 | * @param file 文件 97 | */ 98 | private fun downloadFile(url: String, file: File) { 99 | if (!file.exists()) { 100 | val conn = URL(url).openConnection() 101 | conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)") 102 | val bytes = conn.getInputStream().readBytes() 103 | file.writeBytes(bytes) 104 | } 105 | } 106 | 107 | fun updateUi(itemData: ItemData) { 108 | flagTv.text = "未下载" 109 | downloadHyperLink.autosize() 110 | downloadHyperLink.text = itemData.downloadLink 111 | fileNameTv.text = itemData.fileName 112 | fileSizeTv.text = itemData.fileSize 113 | timeTv.text = itemData.time 114 | } 115 | 116 | fun select(flag: Boolean) { 117 | checkBox.isSelected = flag 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/main/kotlin/com/wan/view/ListView.kt: -------------------------------------------------------------------------------- 1 | package com.wan.view 2 | 3 | import javafx.geometry.Pos 4 | import javafx.scene.control.ScrollPane 5 | import javafx.scene.control.TextField 6 | import javafx.scene.text.Text 7 | import tornadofx.* 8 | 9 | /** 10 | * 11 | * @author StarsOne 12 | * @date Create in 2020/1/2 0002 22:16 13 | * @description 14 | * 15 | */ 16 | class ListView : View("My View") { 17 | var contentVbox = vbox {} 18 | var scrollpane by singleAssign() 19 | var dirInput by singleAssign() 20 | var itemViews = arrayListOf() 21 | var flagText by singleAssign() 22 | 23 | override val root = vbox { 24 | spacing = 15.0 25 | scrollpane = scrollpane { 26 | prefHeight = 300.0 27 | this += contentVbox 28 | } 29 | hbox { 30 | spacing = 20.0 31 | checkbox("全选") { 32 | action { 33 | if (this.isSelected) { 34 | for (itemView in itemViews) { 35 | itemView.select(true) 36 | } 37 | } else { 38 | for (itemView in itemViews) { 39 | itemView.select(false) 40 | } 41 | } 42 | } 43 | } 44 | button("下载已选") { 45 | action { 46 | flagText.text = "下载中" 47 | flagText.fill = c("black") 48 | val list = itemViews.filter { itemView -> itemView.checkBox.isSelected } 49 | for (itemView in list) { 50 | itemView.downloadFile(dirInput.text) 51 | } 52 | runAsync { 53 | while (true) { 54 | if (list.filter { it.flag }.size == list.size) { 55 | ui { 56 | flagText.text = "下载完毕" 57 | flagText.fill = c("green") 58 | } 59 | break 60 | } 61 | Thread.sleep(500) 62 | } 63 | } 64 | } 65 | } 66 | button("下载全部") { 67 | action { 68 | flagText.text = "下载中" 69 | flagText.fill = c("black") 70 | for (itemView in itemViews) { 71 | itemView.downloadFile(dirInput.text) 72 | } 73 | runAsync { 74 | while (true) { 75 | if (itemViews.filter { it.flag }.size == itemViews.size) { 76 | ui { 77 | flagText.text = "下载完毕" 78 | flagText.fill = c("green") 79 | } 80 | break 81 | } 82 | Thread.sleep(500) 83 | } 84 | } 85 | } 86 | } 87 | flagText = text("") { 88 | alignment = Pos.CENTER_LEFT 89 | } 90 | } 91 | hbox { 92 | spacing = 10.0 93 | dirInput = textfield { 94 | prefWidth = 500.0 95 | promptText = "输入下载目录(默认下载地址在 当前jar包路径/蓝奏云下载文件夹中)" 96 | } 97 | button("选择目录") { 98 | action { 99 | val file = chooseDirectory("选择目录") 100 | if (file != null) { 101 | dirInput.text = file.path 102 | } 103 | } 104 | } 105 | } 106 | 107 | } 108 | 109 | 110 | fun setDataList(itemDatas: ArrayList) { 111 | for (itemData in itemDatas) { 112 | val itemView = ItemView() 113 | itemView.updateUi(itemData) 114 | itemViews.add(itemView) 115 | contentVbox.add(itemView) 116 | } 117 | flagText.text = "解析完毕" 118 | } 119 | 120 | fun clearData() { 121 | if (contentVbox.children.size > 0) { 122 | itemViews.clear() 123 | contentVbox.removeFromParent() 124 | contentVbox = vbox { } 125 | scrollpane.add(contentVbox) 126 | } 127 | } 128 | 129 | } 130 | 131 | -------------------------------------------------------------------------------- /src/main/kotlin/com/wan/view/MainView.kt: -------------------------------------------------------------------------------- 1 | package com.wan.view 2 | 3 | import com.gargoylesoftware.htmlunit.BrowserVersion 4 | import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController 5 | import com.gargoylesoftware.htmlunit.WebClient 6 | import com.gargoylesoftware.htmlunit.html.HtmlPage 7 | import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput 8 | import com.gargoylesoftware.htmlunit.html.HtmlTextInput 9 | import com.wan.util.LanzouParse 10 | import javafx.scene.control.TextField 11 | import javafx.scene.control.ToggleGroup 12 | import tornadofx.* 13 | import java.util.concurrent.CountDownLatch 14 | import kotlin.concurrent.thread 15 | 16 | class MainView : View("蓝奏云批量下载v1.1 by stars-one") { 17 | var urlTf by singleAssign()//网址 18 | var passTf by singleAssign()//提取码 19 | var threadCountTf by singleAssign()//线程数 20 | var pageTf by singleAssign()//自动翻页数 21 | var toggle by singleAssign() 22 | val controller = MainController() 23 | val listView = ListView() 24 | override val root = vbox { 25 | prefWidth = 630.0 26 | menubar { 27 | menu("帮助") { 28 | item("关于") { 29 | action { 30 | find(AboutView::class).openModal() 31 | } 32 | } 33 | } 34 | } 35 | form { 36 | fieldset { 37 | field { 38 | text("地址是否为自定义分享地址") 39 | toggle = togglegroup { 40 | radiobutton("是") { 41 | userData = 1 42 | } 43 | radiobutton("否") { 44 | isSelected = true 45 | userData = 0 46 | } 47 | } 48 | hyperlink("什么是自定义分享地址?") { 49 | action { 50 | find(DescView::class).openWindow() 51 | } 52 | } 53 | } 54 | field { 55 | urlTf = textfield { 56 | promptText = "输入蓝奏云网址" 57 | isFocusTraversable = false 58 | } 59 | passTf = textfield { 60 | promptText = "提取码(若没有则不输入)" 61 | isFocusTraversable = false 62 | } 63 | button("解析地址") { 64 | action { 65 | println("开始解析") 66 | val url = urlTf.text 67 | val password = passTf.text 68 | listView.clearData() 69 | listView.flagText.text = "解析中,请耐心等待.." 70 | val flag = toggle.selectedToggle.userData as Int 71 | val threadCount = if (threadCountTf.text.isBlank()) 5 else threadCountTf.text.toInt() 72 | val pageCount = if (pageTf.text.isBlank()) 5 else pageTf.text.toInt() 73 | runAsync { 74 | val data = controller.download(url, password, threadCount, pageCount, flag) 75 | //需要等待,否则最后一条数据解析不到真实地址 76 | while (true) { 77 | if (!data.last().downloadLink.isBlank()) { 78 | runLater { 79 | listView.setDataList(data) 80 | } 81 | break 82 | } 83 | Thread.sleep(400) 84 | } 85 | } 86 | } 87 | } 88 | } 89 | field { 90 | threadCountTf = textfield { promptText = "输入解析线程数(1-128),默认为5,理论上线程数越多解析速度越快,但也不要设置过大" } 91 | } 92 | field { 93 | pageTf = textfield { promptText = "输入翻页数(当文件列表不止一页,自动翻页),默认为5,翻5页后开始解析" } 94 | } 95 | } 96 | this += listView 97 | } 98 | } 99 | } 100 | 101 | class MainController { 102 | /** 103 | * 此方法是适合普通的那些蓝奏云列表分享地址 104 | * @param url 多文件蓝奏云地址,如 https://www.lanzous.com/b607378 105 | * @param password 提取码,默认为无 106 | * @return 下载地址 List 107 | */ 108 | fun download(url: String, password: String , threadCount: Int , pageCount: Int , flag: Int): ArrayList { 109 | return if (flag == 1) { 110 | //解析自定义分享链接的 111 | parseCustomShare(url, password, threadCount, pageCount) 112 | } else { 113 | parseNormalShare(url, password, threadCount, pageCount) 114 | } 115 | } 116 | 117 | /** 118 | * 解析自定义分享地址 119 | */ 120 | private fun parseCustomShare(url: String, password: String , threadCount: Int, pageCount: Int): ArrayList { 121 | val webClient = WebClient(BrowserVersion.CHROME) //创建一个webclient 122 | //webclient设置 123 | webClientConfig(webClient) 124 | var page = webClient.getPage(url) 125 | //自动翻页 126 | for (i in 0 until pageCount) { 127 | if (page.getElementById("filemore") != null) { 128 | page = page.getElementById("filemore").click() 129 | } else { 130 | break 131 | } 132 | } 133 | //等待数据加载 134 | webClient.waitForBackgroundJavaScript(2000) 135 | val readyNodes = page.getElementsById("ready") 136 | println(readyNodes.size) 137 | val itemDatas = arrayListOf() 138 | for (readyNode in readyNodes) { 139 | val link = readyNode.getElementsByTagName("a")[0].getAttribute("href") 140 | val size = readyNode.getElementsByTagName("div")[3].textContent 141 | val fileName = readyNode.textContent.replace(size, "") 142 | itemDatas.add(ItemData(fileName, link, "", size, "")) 143 | } 144 | getAllDownloadLink(itemDatas, threadCount) 145 | return itemDatas 146 | } 147 | 148 | /** 149 | * 普通链接分享 150 | */ 151 | private fun parseNormalShare(url: String, password: String , threadCount: Int, pageCount: Int ): ArrayList { 152 | val webClient = WebClient(BrowserVersion.CHROME) //创建一个webclient 153 | //webclient设置 154 | webClientConfig(webClient) 155 | 156 | var page = webClient.getPage(url) 157 | val readyNodes = if (password.isNotBlank()) { 158 | //有密码的情况 159 | val pwdInput = page.getElementByName("pwd") 160 | val button = page.getElementsById("sub")[0] as HtmlSubmitInput 161 | pwdInput.valueAttribute = password 162 | val finishPage = button.click() 163 | webClient.waitForBackgroundJavaScript(2000) 164 | 165 | //文件可能不止一页,为了防止被封IP,限定最大翻页数,由用户输入 166 | for (i in 0 until pageCount) { 167 | if (page.getElementById("filemore") != null) { 168 | page = page.getElementById("filemore").click() 169 | } else { 170 | break 171 | } 172 | } 173 | finishPage.getElementsById("ready") 174 | } else { 175 | //文件可能不止一页,为了防止被封IP,限定最大翻页数,由用户输入 176 | for (i in 0 until pageCount) { 177 | if (page.getElementById("filemore") != null) { 178 | page = page.getElementById("filemore").click() 179 | } else { 180 | break 181 | } 182 | } 183 | webClient.waitForBackgroundJavaScript(2000) 184 | page.getElementsById("ready") 185 | } 186 | //初始化列表(分享的蓝奏云地址中的所有文件) 187 | val itemDatas = arrayListOf() 188 | //readyNode包含name,size,time 189 | for (readyNode in readyNodes) { 190 | val childNodes = readyNode.getElementsByTagName("div") 191 | val nameNode = childNodes[0].lastElementChild 192 | val sizeNode = childNodes[1] 193 | val timeNode = childNodes[2] 194 | 195 | val name = nameNode.textContent 196 | val link = nameNode.getAttribute("href") 197 | val size = sizeNode.textContent 198 | val time = timeNode.textContent 199 | itemDatas.add(ItemData(name, link, "", size, time)) 200 | } 201 | //多线程解析 202 | getAllDownloadLink(itemDatas, threadCount) 203 | return itemDatas 204 | } 205 | 206 | /** 207 | * 获得列表中每个单条蓝奏云地址的真实地址(普通) 208 | */ 209 | private fun getAllDownloadLink(itemDatas: ArrayList, threadCount: Int = 5) { 210 | 211 | val countDownLatch = CountDownLatch(threadCount) 212 | val step = itemDatas.size / threadCount 213 | val yu = itemDatas.size % threadCount 214 | val firstList = itemDatas.take(step) 215 | val lastList = itemDatas.takeLast(step + yu) 216 | thread { 217 | for (itemData in firstList) { 218 | getDownloadLink(itemData) 219 | } 220 | countDownLatch.countDown() 221 | } 222 | thread { 223 | for (itemData in lastList) { 224 | getDownloadLink(itemData) 225 | } 226 | countDownLatch.countDown() 227 | } 228 | 229 | for (i in 1..threadCount - 2) { 230 | val list = itemDatas.subList(i * step, (i + 1) * step + 1) 231 | thread { 232 | for (itemData in list) { 233 | getDownloadLink(itemData) 234 | } 235 | countDownLatch.countDown() 236 | } 237 | } 238 | countDownLatch.await() 239 | } 240 | 241 | /** 242 | * 获得真实下载地址,并存入itemData的downloadLink属性中(普通) 243 | * @param itemData 单个文件对象 244 | */ 245 | fun getDownloadLink(itemData: ItemData) { 246 | val url = itemData.url 247 | itemData.downloadLink = LanzouParse().getDownloadLink(url) 248 | } 249 | 250 | /** 251 | * webclient设置 252 | */ 253 | private fun webClientConfig(webClient: WebClient) { 254 | webClient.options.isJavaScriptEnabled = true // 启动JS 255 | webClient.options.isUseInsecureSSL = true//忽略ssl认证 256 | webClient.options.isCssEnabled = false//禁用Css,可避免自动二次请求CSS进行渲染 257 | webClient.options.isThrowExceptionOnScriptError = false//运行错误时,不抛出异常 258 | webClient.options.isThrowExceptionOnFailingStatusCode = false 259 | webClient.ajaxController = NicelyResynchronizingAjaxController()// 设置Ajax异步 260 | } 261 | } 262 | 263 | data class ItemData(var fileName: String, var url: String, var downloadLink: String, var fileSize: String, var time: String) -------------------------------------------------------------------------------- /src/resources/img/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stars-one/LanzouDownloader/e0ab31004c34fb8e23aed16b6ccf7d81f0a0493f/src/resources/img/2.png -------------------------------------------------------------------------------- /src/resources/img/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stars-one/LanzouDownloader/e0ab31004c34fb8e23aed16b6ccf7d81f0a0493f/src/resources/img/icon.png -------------------------------------------------------------------------------- /src/resources/img/weixin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stars-one/LanzouDownloader/e0ab31004c34fb8e23aed16b6ccf7d81f0a0493f/src/resources/img/weixin.jpg -------------------------------------------------------------------------------- /src/resources/img/zhifubao.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stars-one/LanzouDownloader/e0ab31004c34fb8e23aed16b6ccf7d81f0a0493f/src/resources/img/zhifubao.jpg --------------------------------------------------------------------------------