MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接

    Unsolved 想找一个b站视频下载转发到qq群的助手

    使用交流
    2
    3
    137
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kerwenard last edited by kerwenard

      在隔壁群看到的,但是无论怎么搜关键字都找不到类似的,有没有用过的大佬知道

      3647b18f-97f6-425a-979a-e29c79522b39-image.png

      1 Reply Last reply Reply Quote 0
      • Topic has been marked as a question  K kerwenard 
      • K
        kerwenard last edited by

        有大佬知道吗

        1 Reply Last reply Reply Quote 0
        • M
          Michael1015198808 last edited by Michael1015198808

          我有一个用you-get的方法,不过不是很优雅,抛砖引玉吧

          object YougetCommand: SimpleCommand(
              owner = PluginMain,
              "youget",
              "you-get",
              description = "you-get"
          ) {
              private var cnt = 0
              private var lock = Any()
              private fun getNo(): Int {
                  synchronized(lock) {
                      cnt += 1
                      return cnt
                  }
              }
              private fun get(process: Process): String {
                  return String(process.inputStream.readNBytes(process.inputStream.available()))
              }
              @Handler
              suspend fun CommandSenderOnMessage<GroupMessageEvent>.run(arg: String, refresh: Long? = null) {
                  val cookie =
                      if (arg.contains("bilibili")) {
                          "/home/michael/cookies/bilibili/youget.txt"
                      } else {
                          null
                      }
                  val no = getNo()
                  var cmdline = "you-get $arg -O /tmp/mirai-$no"
                  if (cookie != null) {
                      cmdline += " -c $cookie"
                  }
                  val f = File("/tmp/").listFiles { _, name -> name.contains("mirai-$no") }.firstOrNull()
                  if (f != null) {
                      f.delete()
                  }
                  val process = ProcessBuilder(cmdline.split(' ')).start()
                  var title = "untitled"
                  var s = ""
                  while (!process.waitFor(1, TimeUnit.SECONDS)) {
                      s += get(process)
                      if (s.contains("Downloading ")) {
                          fromEvent.subject.sendMessage(s.substring(0, s.lastIndexOf("\n")))
                          val titleLine = s.split("\n")[1]
                          title = titleLine.substring(titleLine.lastIndexOf(' ') + 1)
                          "\\/:*?\"<>|".forEach {
                              title = title.replace(it, '_')
                          }
                          s = s.substring(s.lastIndexOf("\n") + 1)
                      }
                  }
                  if (refresh != null) {
                      do {
                          s += get(process)
                          val pos = s.lastIndexOf('\r')
                          if (pos != -1) {
                              val sub = s.substring(0, pos)
                              val pos2 = sub.lastIndexOf('\r')
                              s = s.substring(pos2)
                              fromEvent.subject.sendMessage(sub.substring( pos2 + 1))
                          }
                      } while(!process.waitFor(refresh, TimeUnit.SECONDS))
                  } else {
                      while(!process.waitFor(1, TimeUnit.SECONDS));
                  }
                  val video = File("/tmp/").listFiles { _, name -> name.contains("mirai-$no") }.firstOrNull()
                  if (video != null) {
                      val ext = video.extension
                      // fromEvent.subject.sendMessage("Uploading ...")
                      println(video.length())
                      fromEvent.group.files.uploadNewFile(
                          "/$title.$ext",
                          video.toExternalResource(ext).toAutoCloseable(),
                          object : ProgressionCallback<AbsoluteFile, Long> {
                              var last = 0
                              val tot = video.length()
                          }
                      )
                      // video.delete()
                  } else {
                      fromEvent.subject.sendMessage("file not found!")
                  }
              }
          }
          
          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact