mirror of
https://github.com/Eyre-S/sekai-scores.git
synced 2024-11-24 12:07:40 +08:00
complete sekai-master-db song(music) parse
- added charset param in database import command - moved PostgresConfig to sekai-db proj - added dependency gson - added data_tool/sekai_master_db with a Music which can parse sekai-master-db musics.json and convert it to the Song object
This commit is contained in:
parent
21dbb194fd
commit
944b57c012
@ -1,7 +1,7 @@
|
||||
## Project Configurations
|
||||
|
||||
# Proj Metadata
|
||||
projVersion = 0.6
|
||||
projVersion = 0.7
|
||||
|
||||
|
||||
# Dependencies
|
||||
|
@ -16,8 +16,10 @@ dependencies {
|
||||
|
||||
implementation rootProject
|
||||
implementation project(":sekai-meta")
|
||||
implementation project(":sekai-database")
|
||||
|
||||
implementation "org.postgresql:postgresql:${lib_postgres_driver}"
|
||||
implementation "com.google.code.gson:gson:${lib_gson}"
|
||||
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:${lib_junit_v}"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${lib_junit_v}"
|
||||
|
@ -1,7 +1,8 @@
|
||||
## Project Configurations
|
||||
|
||||
# Proj Metadata
|
||||
moduleVersion = 0.5.2
|
||||
moduleVersion = 0.5.3
|
||||
|
||||
# dependencies
|
||||
lib_postgres_driver = 42.5.1
|
||||
lib_gson = 2.10
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cc.sukazyo.sekai_cli;
|
||||
|
||||
import cc.sukazyo.sekai_cli.db.PostgresConfig;
|
||||
import cc.sukazyo.sekai_db.PostgresConfig;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -29,7 +29,7 @@ public class Config {
|
||||
|
||||
private PostgresConfig db = null;
|
||||
public PostgresConfig db () {
|
||||
if (db == null) db = new PostgresConfig(this);
|
||||
if (db == null) db = new PostgresConfig(db_host, db_name, db_schema, db_auth_user, db_auth_pwd);
|
||||
return db;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,17 @@
|
||||
package cc.sukazyo.sekai_cli.client;
|
||||
|
||||
import cc.sukazyo.sekai_cli.data_tool.sekai_master_db.Music;
|
||||
import cc.sukazyo.sekai_scores.Song;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.IllegalCharsetNameException;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static cc.sukazyo.sekai_cli.Log._debug;
|
||||
@ -12,11 +21,29 @@ public class Database {
|
||||
|
||||
public static void main (String[] args) {
|
||||
|
||||
final List<String> $args = Arrays.asList(args);
|
||||
final List<String> $args = new ArrayList<>(List.of(args));
|
||||
|
||||
final String subcommand = $args.remove(0);
|
||||
if (subcommand.equals("import")) {
|
||||
if ($args.isEmpty()) {
|
||||
|
||||
int ii;
|
||||
Charset charset = Charset.defaultCharset();
|
||||
if ((ii = $args.indexOf("--charset")) != -1) {
|
||||
$args.remove(ii);
|
||||
try { charset = Charset.forName($args.remove(ii)); }
|
||||
catch (IllegalCharsetNameException e) {
|
||||
_user("db_import: unknown/illegal charset " + e.getCharsetName());
|
||||
_debug(e);
|
||||
return;
|
||||
} catch (UnsupportedCharsetException e) {
|
||||
_user("db_import: unsupported charset by jvm: charset " + e.getCharsetName());
|
||||
_debug(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_debug("db_import: will use charset " + charset.displayName());
|
||||
|
||||
if ($args.size() != 2) {
|
||||
System.out.println("""
|
||||
database import: <type> <file-path>
|
||||
currently available types:
|
||||
@ -29,16 +56,24 @@ public class Database {
|
||||
catch (IndexOutOfBoundsException e) {
|
||||
_user("database import: need a file path.");
|
||||
_debug(e);
|
||||
return;
|
||||
}
|
||||
switch ($args.remove(0)) {
|
||||
case "song" ->
|
||||
_user("type song: WIP");
|
||||
case "song" -> {
|
||||
try {
|
||||
final Song[] songs = Music.toSongArray(Music.readFrom(file.toFile(), charset));
|
||||
} catch (IOException | JsonIOException | JsonSyntaxException e) {
|
||||
_user("error while parsing song file: " + e.getMessage());
|
||||
_debug(e);
|
||||
}
|
||||
}
|
||||
case "song-difficulty" ->
|
||||
_user("type song-difficulty: WIP");
|
||||
default ->
|
||||
_user("unavailable type.\ncurrently available types:\n song\n song-difficulty");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package cc.sukazyo.sekai_cli.data_tool.sekai_master_db;
|
||||
|
||||
import cc.sukazyo.sekai_scores.DifficultiesEmpty;
|
||||
import cc.sukazyo.sekai_scores.Song;
|
||||
import cc.sukazyo.sekai_scores.SongUnit;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Music {
|
||||
|
||||
public int id;
|
||||
public int seq;
|
||||
public int releaseConditionId;
|
||||
public String[] categories;
|
||||
public String title;
|
||||
public String pronunciation;
|
||||
public String lyricist;
|
||||
public String composer;
|
||||
public String arranger;
|
||||
public int dancerCount;
|
||||
public int selfDancerPosition;
|
||||
public String assetbundleName;
|
||||
public String liveTalkBackgroundAssetbundleName;
|
||||
public long publishedAt;
|
||||
public int liveStageId;
|
||||
public int filterSec;
|
||||
|
||||
public static Music[] readFrom (File sekaiMusicsFile, Charset charset) throws IOException, JsonIOException, JsonSyntaxException {
|
||||
return new Gson().fromJson(new FileReader(sekaiMusicsFile, charset), Music[].class);
|
||||
}
|
||||
|
||||
public SongUnit getUnit () {
|
||||
return SongUnit.getBySeq((seq/100000) % 10);
|
||||
}
|
||||
|
||||
public Song toSong () {
|
||||
return new Song(
|
||||
id, title, getUnit(), new DifficultiesEmpty(),
|
||||
null, getOrNull(arranger), getOrNull(composer), getOrNull(lyricist),
|
||||
null, null,
|
||||
ZonedDateTime.ofInstant(Instant.ofEpochMilli(publishedAt), ZoneOffset.UTC),
|
||||
new String[]{}
|
||||
);
|
||||
}
|
||||
|
||||
public static Song[] toSongArray (Music... musics) {
|
||||
final List<Song> songs = new ArrayList<>();
|
||||
for (Music i : musics) songs.add(i.toSong());
|
||||
return songs.toArray(new Song[0]);
|
||||
}
|
||||
|
||||
private String getOrNull (String name) {
|
||||
return name.equals("-") ? null : name;
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +1,48 @@
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group 'cc.sukazyo'
|
||||
version projVersion
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
compileOnly "com.github.spotbugs:spotbugs-annotations:${lib_spotbugs_v}"
|
||||
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:${lib_junit_v}"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${lib_junit_v}"
|
||||
|
||||
}
|
||||
|
||||
final JavaVersion proj_java = JavaVersion.VERSION_17
|
||||
final Charset proj_source_encoding = StandardCharsets.UTF_8
|
||||
|
||||
group 'cc.sukazyo'
|
||||
version projVersion
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
|
||||
sourceCompatibility proj_java
|
||||
targetCompatibility proj_java
|
||||
|
||||
withSourcesJar()
|
||||
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = proj_source_encoding.name()
|
||||
}
|
||||
|
||||
tasks.withType(Javadoc) {
|
||||
options.encoding = proj_source_encoding.name()
|
||||
options.docEncoding = proj_source_encoding.name()
|
||||
options.charSet = proj_source_encoding.name()
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
package cc.sukazyo.sekai_cli.db;
|
||||
|
||||
import cc.sukazyo.sekai_cli.Config;
|
||||
package cc.sukazyo.sekai_db;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -12,36 +10,32 @@ public class PostgresConfig {
|
||||
|
||||
@Nonnull public final String host;
|
||||
@Nonnull public final String database;
|
||||
@Nullable public final String struct;
|
||||
@Nullable public final String schema;
|
||||
@Nonnull public final String user;
|
||||
@Nonnull public final String token;
|
||||
|
||||
public PostgresConfig (
|
||||
@Nonnull String host, @Nonnull String database, @Nullable String struct,
|
||||
@Nonnull String host, @Nonnull String database, @Nullable String schema,
|
||||
@Nonnull String user, @Nonnull String token
|
||||
) {
|
||||
this.host = host;
|
||||
this.database = database;
|
||||
this.struct = struct;
|
||||
this.schema = schema;
|
||||
this.user = user;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public PostgresConfig (Config global) {
|
||||
this(global.db_host, global.db_name, global.db_schema, global.db_auth_user, global.db_auth_pwd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString () {
|
||||
return String.format("jdbc:postgresql://%s/%s", host, database);
|
||||
}
|
||||
|
||||
public String struct() {
|
||||
return struct;
|
||||
public String schema () {
|
||||
return schema;
|
||||
}
|
||||
|
||||
public String table (String table) {
|
||||
return (struct == null ? "" : '"' + struct() + '"' + ".") + '"' + table + '"';
|
||||
return (schema == null ? "" : '"' + schema() + '"' + ".") + '"' + table + '"';
|
||||
}
|
||||
|
||||
public Connection connect () throws SQLException {
|
16
src/main/java/cc/sukazyo/sekai_scores/DifficultiesEmpty.java
Normal file
16
src/main/java/cc/sukazyo/sekai_scores/DifficultiesEmpty.java
Normal file
@ -0,0 +1,16 @@
|
||||
package cc.sukazyo.sekai_scores;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class DifficultiesEmpty implements Difficulties{
|
||||
|
||||
@Override
|
||||
public Difficulty[] getAll () {
|
||||
return new Difficulty[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach (@Nonnull Consumer<Difficulty> action) {}
|
||||
|
||||
}
|
@ -30,7 +30,7 @@ public enum SongUnit {
|
||||
_X(-1, "セカイ")
|
||||
;
|
||||
|
||||
public SongUnit getBySeq(int seq) {
|
||||
public static SongUnit getBySeq(int seq) {
|
||||
return switch (seq) {
|
||||
case 1 -> PIAPRO;
|
||||
case 2 -> LIGHT_SOUND;
|
||||
|
Loading…
Reference in New Issue
Block a user