zoukankan      html  css  js  c++  java
  • 网易云音乐本地数据库的歌单列表导出,一个不丢,支持1000首以上

    主要代码,kotlin写的

    package fuck
    
    import com.google.gson.Gson
    import java.io.File
    import java.sql.Connection
    import java.sql.DriverManager
    import java.sql.Statement
    
    fun main(args: Array<String>) {
        if (args.size < 2) {
            println("Usage: java -jar xxx.jar dbFilePath outputPath")
            return
        }
    
        val dbFilePath = args[0]
        val savePath = args[1]
    
        initDB(dbFilePath)
    
        getPlayLists()?.forEach { playLists ->
            getSonsByPid("${playLists.id}")?.forEach {
                val fromJson = Gson().fromJson<JsonRootBean>(it, JsonRootBean::class.java)
                var arts = ""
                for (line in fromJson.artists) {
                    arts += line.name + ","
                }
                val path = "$savePath${playLists.name.replace("/", "-")}.txt"
                File(savePath).mkdirs()
                File(path).appendText(fromJson.name + " - " + arts + "
    ")
            }
        }
    
        closeDB()
        println("导出完毕")
    }
    
    var c: Connection? = null
    var stmt: Statement? = null
    
    fun initDB(dbFilePath: String) {
        Class.forName("org.sqlite.JDBC")
        c = DriverManager.getConnection("jdbc:sqlite:$dbFilePath")
        stmt = c?.createStatement()
        println("Opened database successfully")
    }
    
    fun getPlayLists(): List<PlayListBean>? {
        val rs = stmt?.executeQuery("SELECT playlist FROM web_playlist;") ?: return null
    
        val pids = mutableListOf<PlayListBean>()
        while (rs.next()) {
            pids.add(Gson().fromJson(rs.getString(1), PlayListBean::class.java))
        }
        return pids
    }
    
    fun getSonsByPid(pid: String): List<String>? {
        val sql = "SELECT track from web_track WHERE tid in " +
                "(SELECT tid from web_playlist_track WHERE pid = '$pid');"
        val songs = mutableListOf<String>()
        val rs = stmt?.executeQuery(sql) ?: return null
        while (rs.next()) {
            songs.add(rs.getString(1))
        }
        return songs
    }
    
    fun closeDB() {
        stmt?.close()
        c?.close()
    }

    仓库地址

    https://github.com/xirtam-ch/NeteaseMusicDBExport

  • 相关阅读:
    Struts2中Date日期转换的问题
    IE SEESION共享的问题
    ORA-12518,TNS:listener could not hand off client connection
    TypeError: validator.settings[("on" + event.type)].call is not a function
    org.apache.ibatis.reflection.ReflectionException
    java.lang.IllegalArgumentException
    那些年,我追过的绘图工具
    spring使用rssfeed
    RSS Feeds with Spring Boot
    highcharts 动态生成x轴和折线图
  • 原文地址:https://www.cnblogs.com/xirtam/p/12564109.html
Copyright © 2011-2022 走看看