Last active
February 2, 2020 11:59
-
-
Save iseki0/9fd3669da725f8e2ace68d10bdac9b16 to your computer and use it in GitHub Desktop.
Aria2 批量保留路径工具
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bot | |
import org.apache.commons.codec.net.URLCodec | |
import java.io.FileReader | |
import java.io.FileWriter | |
import java.net.URL | |
fun main() { | |
// 输入为 find 命令的输出去掉首行 | |
val list = FileReader("\"C:\\Users\\iseki\\Desktop\\new2\"".removeSurrounding("\"")).readLines() | |
val baseUrl = | |
"https://***.***.***/tran/[mikudb] ☆VOCALOSSLESS ****************** [FLAC]" | |
val target = "G:\\MIKUDB\\" | |
val map = list | |
.map { it.split("/").toList() } | |
.map { it.filterIndexed { index, _ -> index != it.lastIndex } to it.last() } | |
val ll = map.map { (path, _) -> path.lastOrNull() }.toSet() | |
val map2 = map.filter { (_, name) -> !ll.contains(name) } | |
data class Item(val path: String, val url: String, val name: String) | |
map2.map { (path, name) -> | |
val s = path.map { URLCodec().encode(it) }.joinToString(separator = "/", prefix = "/", postfix = "/") | |
Item( | |
path = target + path.joinToString(separator = "\\"), | |
name = name, | |
url = (baseUrl + path.joinToString( | |
separator = "/", | |
postfix = "/", | |
prefix = "/" | |
) + name).let { URL(it).toString() } | |
) | |
}.map { | |
""" | |
|${it.url} | |
| dir=${it.path} | |
| split=2 | |
| file-allocation=falloc | |
| max-connection-per-server=2 | |
| stream-piece-selector=inorder | |
""".trimMargin("|") | |
}.joinToString(separator = "\n") | |
.let { txt -> FileWriter("C:\\Users\\iseki\\Desktop\\aria2.session").use { it.write(txt) } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment