gemer 1 year ago
parent
commit
179612cde8
5 changed files with 25 additions and 29 deletions
  1. 6 0
      .idea/encodings.xml
  2. 2 1
      cmd/download.go
  3. 1 0
      someData.json
  4. 8 20
      utils/localizeMainJson.go
  5. 8 8
      utils/somedataType.go

+ 6 - 0
.idea/encodings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="file://$PROJECT_DIR$/someData.json" charset="UTF-8" />
+  </component>
+</project>

+ 2 - 1
cmd/download.go

@@ -39,7 +39,8 @@ func RunCmd(cmd *cobra.Command, args []string) {
 
 	//}
 
-	dest := "D:\\data"
+	//dest := "D:\\data"
+	dest := "./"
 	data := &utils.ScenesDataType{}
 
 	if _, err := os.Stat(dest); os.IsNotExist(err) {

File diff suppressed because it is too large
+ 1 - 0
someData.json


+ 8 - 20
utils/localizeMainJson.go

@@ -1,8 +1,6 @@
 package utils
 
 import (
-	"bytes"
-	"encoding/gob"
 	"encoding/json"
 	"fmt"
 	"io"
@@ -15,12 +13,6 @@ func CovertJsonAndDownload(path string, dest string) (err error) {
 
 	dataFile := dest + "/someData.json"
 
-	out, err := os.Create(dataFile)
-	if err != nil {
-		return err
-	}
-	defer out.Close()
-
 	// Get the data
 	resp, err := http.Get(path)
 	if err != nil {
@@ -37,26 +29,22 @@ func CovertJsonAndDownload(path string, dest string) (err error) {
 	}
 	if strings.Contains(content, "https://4dkk.4dage.com/scene_edit_data") {
 		content = strings.ReplaceAll(content, "https://4dkk.4dage.com/", "/data/")
-
 	}
 
-	filterContent, _ := json.Marshal(content)
+	target := &ScenesDataType{}
 
-	fmt.Println("data json:", string(filterContent))
+	err = json.NewDecoder(strings.NewReader(content)).Decode(&target)
 
-	buf := &bytes.Buffer{}
-	//err = json.NewEncoder(buf).Encode(&filterContent)
-	////err = json.NewDecoder(buf).Decode(&filterContent)
-	//if err != nil {
-	//	return err
-	//}
-	enc := gob.NewEncoder(buf)
-	err = enc.Encode(content)
 	if err != nil {
+		fmt.Println(err)
 		return err
 	}
+	file, err := json.Marshal(target)
+
+	fmt.Println("data json:", string(file))
+
 	// Writer the body to file
-	_, err = io.Copy(out, buf)
+	err = os.WriteFile(dataFile, file, 0644)
 
 	if err != nil {
 		return err

+ 8 - 8
utils/somedataType.go

@@ -10,13 +10,13 @@ type ScenesDataType struct {
 		OssPath string `json:"ossPath"`
 	} `json:"backgroundMusic"`
 	CatalogRoot []struct {
-		Children []any  `json:"children"`
-		ID       string `json:"id"`
-		Name     string `json:"name"`
+		Children []any       `json:"children"`
+		ID       interface{} `json:"id"`
+		Name     string      `json:"name"`
 	} `json:"catalogRoot"`
 	Catalogs []struct {
-		ID   string `json:"id"`
-		Name string `json:"name"`
+		ID   interface{} `json:"id"`
+		Name string      `json:"name"`
 	} `json:"catalogs"`
 	CoverInfo struct {
 		CoverImageInWay   int64  `json:"coverImageInWay"`
@@ -59,7 +59,7 @@ type ScenesDataType struct {
 		Repeat        bool   `json:"repeat"`
 	} `json:"explanation"`
 	FirstScene struct {
-		Category   int64 `json:"category"`
+		Category   interface{} `json:"category"`
 		CustomMask struct {
 			Earth struct {
 				Antidistorted bool   `json:"antidistorted"`
@@ -131,7 +131,7 @@ type ScenesDataType struct {
 					Phone string `json:"phone"`
 				} `json:"phoneInfo"`
 				Secne struct {
-					Category   string `json:"category"`
+					Category   interface{} `json:"category"`
 					CustomMask struct {
 						Earth struct {
 							Antidistorted bool   `json:"antidistorted"`
@@ -196,7 +196,7 @@ type ScenesDataType struct {
 	RemindTime             int64  `json:"remindTime"`
 	SceneIndex             string `json:"sceneIndex"`
 	Scenes                 []struct {
-		Category   string `json:"category"`
+		Category   interface{} `json:"category"`
 		CustomMask struct {
 			Earth struct {
 				Antidistorted bool   `json:"antidistorted"`