Browse Source

feat: save

gemercheung 1 year ago
parent
commit
d8d08f3658
5 changed files with 161 additions and 149 deletions
  1. 4 0
      build-window.bat
  2. 18 18
      cmd/download.go
  3. 7 7
      utils/getScenes.go
  4. 8 3
      utils/localizeMainJson.go
  5. 124 121
      utils/somedataType.go

+ 4 - 0
build-window.bat

@@ -0,0 +1,4 @@
+SET CGO_ENABLED=0
+SET GOOS=windows
+SET GOARCH=amd64
+go build -o downloadQJ.exe main.go

+ 18 - 18
cmd/download.go

@@ -35,16 +35,22 @@ func RunCmd(cmd *cobra.Command, args []string) {
 	timeUnix := time.Now().Unix()
 	var mainTourUrl string
 	var mainJsonUrl string
+	var ossUrl string
+	var bucket string
 	code = args[0]
 	dest := args[1]
 
 	if isProduction {
 		mainJsonUrl = "https://4dkk.4dage.com/720yun_fd_manage/" + code + "/someData.json?rnd=" + strconv.FormatInt(timeUnix, 10)
 		mainTourUrl = "https://4dkk.4dage.com/720yun_fd_manage/" + code + "/tour.xml?rnd=" + strconv.FormatInt(timeUnix, 10)
+		ossUrl = "https://4dkk.4dage.com/"
+		bucket = "oss://4dkankan"
 
 	} else {
 		mainJsonUrl = "https://ossxiaoan.4dage.com/720yun_fd_manage/" + code + "/someData.json?rnd=" + strconv.FormatInt(timeUnix, 10)
-		mainTourUrl = "\nhttps://ossxiaoan.4dage.com/720yun_fd_manage/" + code + "/tour.xml?rnd=" + strconv.FormatInt(timeUnix, 10)
+		mainTourUrl = "https://ossxiaoan.4dage.com/720yun_fd_manage/" + code + "/tour.xml?rnd=" + strconv.FormatInt(timeUnix, 10)
+		ossUrl = "https://ossxiaoan.4dage.com/"
+		bucket = "oss://oss-xiaoan"
 	}
 
 	data := &utils.ScenesDataType{}
@@ -54,18 +60,12 @@ func RunCmd(cmd *cobra.Command, args []string) {
 	}
 
 	err := utils.GetJson(mainJsonUrl, data)
-	//err = utils.GetXml(mainTourUrl, data)
 	err = utils.DownloadMainXml(mainTourUrl, dest+"/tour/")
-
-	if err != nil {
-		log.Error("Error: ", "type", err)
-
-	}
-	//dataFile := dest + "/someData.json"
-	err = utils.CovertJsonAndDownload("https://4dkk.4dage.com/720yun_fd_manage/WK1792459279224066048/someData.json?_=0.08240579686447669", dest)
+	err = utils.CovertJsonAndDownload(mainJsonUrl, dest, ossUrl)
 
 	if err != nil {
 		fmt.Println("Error: ", err)
+		return
 
 	}
 	excludeArray := []string{"*.exe", "tour_testingserver_macos", "tour.html", "*.js", "vtourskin*.xml", "webvr.xml", "combobox.xml", "vtourskin*.png", "vtourskin.png", "rotate_device.png"}
@@ -78,13 +78,13 @@ func RunCmd(cmd *cobra.Command, args []string) {
 			if v.Type == "pano" {
 				// 主Tiles图
 				if utils.IsCommandAvailable("ossutil") {
-					runMainTileDownload(v.SceneCode, dest, exclString)
+					runMainTileDownload(v.SceneCode, dest, exclString, bucket)
 				}
 
 				// 场景封面图
 				if len(v.Icon) > 0 {
 					log.Info("Downloading Scenes-cover", "url", fmt.Sprintf("%s", v.Icon))
-					url := utils.DetectSource(v.Icon, dest)
+					url := utils.DetectSource(v.Icon, dest, ossUrl)
 					err = utils.DownloadFile(url, v.Icon)
 					log.Info("Save Scenes-cover", "url", fmt.Sprintf("%s", url))
 
@@ -97,7 +97,7 @@ func RunCmd(cmd *cobra.Command, args []string) {
 						// 热点封面图
 						if len(Hotspot.Secne.Icon) > 0 {
 							log.Info("Downloading Hotspots-cover", "url", fmt.Sprintf("%s", Hotspot.Secne.Icon))
-							url := utils.DetectSource(Hotspot.Secne.Icon, dest)
+							url := utils.DetectSource(Hotspot.Secne.Icon, dest, ossUrl)
 							err = utils.DownloadFile(url, Hotspot.Secne.Icon)
 							log.Info("Save Hotspots-cover", "url", fmt.Sprintf("%s", url))
 						}
@@ -106,7 +106,7 @@ func RunCmd(cmd *cobra.Command, args []string) {
 						if len(Hotspot.ImageTextInfo.ImageList) > 0 {
 							for _, img := range Hotspot.ImageTextInfo.ImageList {
 								log.Info("Downloading Hotspots-ImageList", "url", fmt.Sprintf("%s", img.OssPath))
-								url := utils.DetectSource(img.OssPath, dest)
+								url := utils.DetectSource(img.OssPath, dest, ossUrl)
 								err = utils.DownloadFile(url, img.OssPath)
 								log.Info("Save Hotspots-ImageList", "url", fmt.Sprintf("%s", url))
 							}
@@ -114,7 +114,7 @@ func RunCmd(cmd *cobra.Command, args []string) {
 						// customIconInfo
 						if len(Hotspot.CustomIconInfo.Img) > 0 {
 							log.Info("Downloading Hotspots-CustomIconInfo", "url", fmt.Sprintf("%s", Hotspot.CustomIconInfo.Img))
-							url := utils.DetectSource(Hotspot.CustomIconInfo.Img, dest)
+							url := utils.DetectSource(Hotspot.CustomIconInfo.Img, dest, ossUrl)
 							err = utils.DownloadFile(url, Hotspot.CustomIconInfo.Img)
 							log.Info("Save Hotspots-CustomIconInfo", "url", fmt.Sprintf("%s", url))
 
@@ -124,14 +124,14 @@ func RunCmd(cmd *cobra.Command, args []string) {
 
 				if len(v.CustomMask.Sky.Icon) > 0 {
 					log.Info("Downloading CustomMask Sky", "url", fmt.Sprintf("%s", v.CustomMask.Sky.Icon))
-					url := utils.DetectSource(v.CustomMask.Sky.Icon, dest)
+					url := utils.DetectSource(v.CustomMask.Sky.Icon, dest, ossUrl)
 					err = utils.DownloadFile(url, v.CustomMask.Sky.Icon)
 					log.Info("Save CustomMask Sky", "url", fmt.Sprintf("%s", url))
 				}
 
 				if len(v.CustomMask.Earth.Icon) > 0 {
 					log.Info("Downloading CustomMask Earth", "url", fmt.Sprintf("%s", v.CustomMask.Earth.Icon))
-					url := utils.DetectSource(v.CustomMask.Earth.Icon, dest)
+					url := utils.DetectSource(v.CustomMask.Earth.Icon, dest, ossUrl)
 					err = utils.DownloadFile(url, v.CustomMask.Earth.Icon)
 					log.Info("Save CustomMask Earth", "url", fmt.Sprintf("%s", url))
 				}
@@ -141,10 +141,10 @@ func RunCmd(cmd *cobra.Command, args []string) {
 	}
 
 }
-func runMainTileDownload(sceneCode string, dest string, exclString string) {
+func runMainTileDownload(sceneCode string, dest string, exclString string, bucket string) {
 
 	log.Info("Downloading Scenes", "code", fmt.Sprintf("%s", sceneCode))
-	command := "ossutil cp -r -f oss://4dkankan/720yun_fd_manage/" + sceneCode + " " + dest + " " + exclString
+	command := "ossutil cp -r -f " + bucket + "/720yun_fd_manage/" + sceneCode + " " + dest + " " + exclString
 
 	var cmd *exec.Cmd
 

+ 7 - 7
utils/getScenes.go

@@ -88,16 +88,16 @@ func IsCommandAvailable(name string) bool {
 	return true
 }
 
-func DetectSource(path string, dest string) (url string) {
+func DetectSource(path string, dest string, ossUrl string) (url string) {
 	saveP := strings.Split(path, "?")[0]
 
-	if strings.Contains(saveP, "https://4dkk.4dage.com/720yun_fd_manage") {
-		p := strings.ReplaceAll(saveP, "https://4dkk.4dage.com/720yun_fd_manage", "")
-		url = dest + p
+	if strings.Contains(saveP, ossUrl+"720yun_fd_manage/") {
+		p := strings.ReplaceAll(saveP, ossUrl+"720yun_fd_manage/", "")
+		url = dest + "/" + p
 	}
-	if strings.Contains(saveP, "https://4dkk.4dage.com/scene_edit_data") {
-		p := strings.ReplaceAll(saveP, "https://4dkk.4dage.com", "")
-		url = dest + p
+	if strings.Contains(saveP, ossUrl+"scene_edit_data/") {
+		p := strings.ReplaceAll(saveP, ossUrl, "")
+		url = dest + "/" + p
 	}
 
 	return url

+ 8 - 3
utils/localizeMainJson.go

@@ -11,7 +11,9 @@ import (
 	"strings"
 )
 
-func CovertJsonAndDownload(path string, dest string) (err error) {
+func CovertJsonAndDownload(path string, dest string, ossUrl string) (err error) {
+
+	log.Info("CovertJsonAndDownload", "url", fmt.Sprintf("%s", path))
 
 	dataFile := dest + "/someData.json"
 
@@ -26,10 +28,10 @@ func CovertJsonAndDownload(path string, dest string) (err error) {
 
 	content := string(bodyBytes)
 	//以字串过滤所有url到本地
-	if strings.Contains(content, "https://4dkk.4dage.com/720yun_fd_manage/") {
+	if strings.Contains(content, ossUrl+"/720yun_fd_manage/") {
 		content = strings.ReplaceAll(content, "https://4dkk.4dage.com/720yun_fd_manage/", "data/")
 	}
-	if strings.Contains(content, "https://4dkk.4dage.com/scene_edit_data") {
+	if strings.Contains(content, ossUrl+"/scene_edit_data/") {
 		content = strings.ReplaceAll(content, "https://4dkk.4dage.com/", "data/")
 	}
 
@@ -56,6 +58,9 @@ func CovertJsonAndDownload(path string, dest string) (err error) {
 	}
 
 	file, err := json.Marshal(target)
+	if err != nil {
+		panic(err)
+	}
 
 	//log.Info("data json:", string(file))
 

+ 124 - 121
utils/somedataType.go

@@ -2,8 +2,130 @@ package utils
 
 import "encoding/json"
 
+type FirstSceneType struct {
+	Category   interface{} `json:"category"`
+	CustomMask struct {
+		Earth struct {
+			Antidistorted bool   `json:"antidistorted"`
+			FodderID      string `json:"fodderId"`
+			Icon          string `json:"icon"`
+			IsShow        bool   `json:"isShow"`
+			Scale         int64  `json:"scale"`
+		} `json:"earth"`
+		Sky struct {
+			Antidistorted bool   `json:"antidistorted"`
+			FodderID      string `json:"fodderId"`
+			Icon          string `json:"icon"`
+			IsShow        bool   `json:"isShow"`
+			Scale         int64  `json:"scale"`
+		} `json:"sky"`
+	} `json:"customMask"`
+	Icon       string `json:"icon"`
+	ID         string `json:"id"`
+	InitVisual struct {
+		Hlookat json.Number `json:"hlookat"`
+		Vlookat json.Number `json:"vlookat"`
+	} `json:"initVisual"`
+	MaterialType string `json:"materialType"`
+	SceneCode    string `json:"sceneCode"`
+	SceneTitle   string `json:"sceneTitle"`
+	SomeData     struct {
+		Hotspots []*struct {
+			ArticleInfo struct {
+				HTML string `json:"html"`
+			} `json:"articleInfo"`
+			Ath            interface{} `json:"ath"`
+			Atv            interface{} `json:"atv"`
+			Audio          string      `json:"audio"`
+			CustomIconInfo struct {
+				Img string `json:"img"`
+			} `json:"customIconInfo"`
+			FodderID        []interface{} `json:"fodderId"`
+			FontSize        int64         `json:"fontSize"`
+			HotspotIconType string        `json:"hotspotIconType"`
+			HotspotTitle    string        `json:"hotspotTitle"`
+			HotspotType     string        `json:"hotspotType"`
+			Hyperlink       string        `json:"hyperlink"`
+			Icontype        string        `json:"icontype"`
+			Image           []interface{} `json:"image"`
+			ImageTextInfo   struct {
+				Audio        struct{}      `json:"audio"`
+				ImageList    []interface{} `json:"imageList"`
+				IsApplyToAll bool          `json:"isApplyToAll"`
+				Text         string        `json:"text"`
+			} `json:"imageTextInfo"`
+			Img     string `json:"img"`
+			Link    string `json:"link"`
+			Name    string `json:"name"`
+			PdfInfo struct {
+				Name string `json:"name"`
+				URL  string `json:"url"`
+			} `json:"pdfInfo"`
+			PersonalizedTagInfo struct {
+				BorderColor    string `json:"borderColor"`
+				FillColor      string `json:"fillColor"`
+				IsShowLine     bool   `json:"isShowLine"`
+				IsTextWrap     bool   `json:"isTextWrap"`
+				LineDirection  string `json:"lineDirection"`
+				TextColor      string `json:"textColor"`
+				TextDirection  string `json:"textDirection"`
+				TextNumPerLine int64  `json:"textNumPerLine"`
+			} `json:"personalizedTagInfo"`
+			PhoneInfo struct {
+				Phone string `json:"phone"`
+			} `json:"phoneInfo"`
+			Secne struct {
+				Category   interface{} `json:"category"`
+				CustomMask struct {
+					Earth struct {
+						Antidistorted bool   `json:"antidistorted"`
+						FodderID      string `json:"fodderId"`
+						Icon          string `json:"icon"`
+						IsShow        bool   `json:"isShow"`
+						Scale         int64  `json:"scale"`
+					} `json:"earth"`
+					Sky struct {
+						Antidistorted bool   `json:"antidistorted"`
+						FodderID      string `json:"fodderId"`
+						Icon          string `json:"icon"`
+						IsShow        bool   `json:"isShow"`
+						Scale         int64  `json:"scale"`
+					} `json:"sky"`
+				} `json:"customMask"`
+				Icon       string `json:"icon"`
+				ID         string `json:"id"`
+				InitVisual struct {
+					Hlookat    json.Number `json:"hlookat"`
+					Vlookat    json.Number `json:"vlookat"`
+					Vlookatmax json.Number `json:"vlookatmax"`
+					Vlookatmin json.Number `json:"vlookatmin"`
+				} `json:"initVisual"`
+				MaterialType string   `json:"materialType"`
+				SceneCode    string   `json:"sceneCode"`
+				SceneTitle   string   `json:"sceneTitle"`
+				SomeData     struct{} `json:"someData"`
+				Type         string   `json:"type"`
+				Version      string   `json:"version"`
+			} `json:"secne"`
+			SerialFrameInfo struct {
+				Duration    int64  `json:"duration"`
+				FrameNumber int64  `json:"frameNumber"`
+				Img         string `json:"img"`
+			} `json:"serialFrameInfo"`
+			Size             json.Number `json:"size"`
+			Textarea         string      `json:"textarea"`
+			TitleDisplayMode string      `json:"titleDisplayMode"`
+			TitlePosition    string      `json:"titlePosition"`
+			Type             string      `json:"type"`
+			Video            string      `json:"video"`
+		} `json:"hotspots"`
+	} `json:"someData"`
+	Type string `json:"type"`
+}
+
 type ScenesDataType struct {
-	AppIcon         string `json:"appIcon"`
+	FirstScene      *FirstSceneType `json:"firstScenes,string,omitempty"`
+	AppIcon         string          `json:"appIcon"`
 	BackgroundMusic struct {
 		ID      string `json:"id"`
 		Name    string `json:"name"`
@@ -58,126 +180,7 @@ type ScenesDataType struct {
 		OpenByDefault bool   `json:"openByDefault"`
 		Repeat        bool   `json:"repeat"`
 	} `json:"explanation"`
-	FirstScene struct {
-		Category   interface{} `json:"category"`
-		CustomMask struct {
-			Earth struct {
-				Antidistorted bool   `json:"antidistorted"`
-				FodderID      string `json:"fodderId"`
-				Icon          string `json:"icon"`
-				IsShow        bool   `json:"isShow"`
-				Scale         int64  `json:"scale"`
-			} `json:"earth"`
-			Sky struct {
-				Antidistorted bool   `json:"antidistorted"`
-				FodderID      string `json:"fodderId"`
-				Icon          string `json:"icon"`
-				IsShow        bool   `json:"isShow"`
-				Scale         int64  `json:"scale"`
-			} `json:"sky"`
-		} `json:"customMask"`
-		Icon       string `json:"icon"`
-		ID         string `json:"id"`
-		InitVisual struct {
-			Hlookat json.Number `json:"hlookat"`
-			Vlookat json.Number `json:"vlookat"`
-		} `json:"initVisual"`
-		MaterialType string `json:"materialType"`
-		SceneCode    string `json:"sceneCode"`
-		SceneTitle   string `json:"sceneTitle"`
-		SomeData     struct {
-			Hotspots []*struct {
-				ArticleInfo struct {
-					HTML string `json:"html"`
-				} `json:"articleInfo"`
-				Ath            interface{} `json:"ath"`
-				Atv            interface{} `json:"atv"`
-				Audio          string      `json:"audio"`
-				CustomIconInfo struct {
-					Img string `json:"img"`
-				} `json:"customIconInfo"`
-				FodderID        []interface{} `json:"fodderId"`
-				FontSize        int64         `json:"fontSize"`
-				HotspotIconType string        `json:"hotspotIconType"`
-				HotspotTitle    string        `json:"hotspotTitle"`
-				HotspotType     string        `json:"hotspotType"`
-				Hyperlink       string        `json:"hyperlink"`
-				Icontype        string        `json:"icontype"`
-				Image           []interface{} `json:"image"`
-				ImageTextInfo   struct {
-					Audio        struct{}      `json:"audio"`
-					ImageList    []interface{} `json:"imageList"`
-					IsApplyToAll bool          `json:"isApplyToAll"`
-					Text         string        `json:"text"`
-				} `json:"imageTextInfo"`
-				Img     string `json:"img"`
-				Link    string `json:"link"`
-				Name    string `json:"name"`
-				PdfInfo struct {
-					Name string `json:"name"`
-					URL  string `json:"url"`
-				} `json:"pdfInfo"`
-				PersonalizedTagInfo struct {
-					BorderColor    string `json:"borderColor"`
-					FillColor      string `json:"fillColor"`
-					IsShowLine     bool   `json:"isShowLine"`
-					IsTextWrap     bool   `json:"isTextWrap"`
-					LineDirection  string `json:"lineDirection"`
-					TextColor      string `json:"textColor"`
-					TextDirection  string `json:"textDirection"`
-					TextNumPerLine int64  `json:"textNumPerLine"`
-				} `json:"personalizedTagInfo"`
-				PhoneInfo struct {
-					Phone string `json:"phone"`
-				} `json:"phoneInfo"`
-				Secne struct {
-					Category   interface{} `json:"category"`
-					CustomMask struct {
-						Earth struct {
-							Antidistorted bool   `json:"antidistorted"`
-							FodderID      string `json:"fodderId"`
-							Icon          string `json:"icon"`
-							IsShow        bool   `json:"isShow"`
-							Scale         int64  `json:"scale"`
-						} `json:"earth"`
-						Sky struct {
-							Antidistorted bool   `json:"antidistorted"`
-							FodderID      string `json:"fodderId"`
-							Icon          string `json:"icon"`
-							IsShow        bool   `json:"isShow"`
-							Scale         int64  `json:"scale"`
-						} `json:"sky"`
-					} `json:"customMask"`
-					Icon       string `json:"icon"`
-					ID         string `json:"id"`
-					InitVisual struct {
-						Hlookat    json.Number `json:"hlookat"`
-						Vlookat    json.Number `json:"vlookat"`
-						Vlookatmax json.Number `json:"vlookatmax"`
-						Vlookatmin json.Number `json:"vlookatmin"`
-					} `json:"initVisual"`
-					MaterialType string   `json:"materialType"`
-					SceneCode    string   `json:"sceneCode"`
-					SceneTitle   string   `json:"sceneTitle"`
-					SomeData     struct{} `json:"someData"`
-					Type         string   `json:"type"`
-					Version      string   `json:"version"`
-				} `json:"secne"`
-				SerialFrameInfo struct {
-					Duration    int64  `json:"duration"`
-					FrameNumber int64  `json:"frameNumber"`
-					Img         string `json:"img"`
-				} `json:"serialFrameInfo"`
-				Size             json.Number `json:"size"`
-				Textarea         string      `json:"textarea"`
-				TitleDisplayMode string      `json:"titleDisplayMode"`
-				TitlePosition    string      `json:"titlePosition"`
-				Type             string      `json:"type"`
-				Video            string      `json:"video"`
-			} `json:"hotspots"`
-		} `json:"someData"`
-		Type string `json:"type"`
-	} `json:"firstScene"`
+
 	Icon                   string `json:"icon"`
 	ID                     string `json:"id"`
 	IsAuto                 int64  `json:"isAuto"`