示例#1
0
func getStringifiedSongUrls(urls dna.StringArray) dna.String {
	var baseLink = dna.String("")
	songUrls := []SongUrl{}
	urls.ForEach(func(val dna.String, idx dna.Int) {
		// dna.Log(val)
		// Finding bitrate
		switch {
		case val.Match(`128kbps`) == true:
			songUrl := getSongUrl(val, "128kbps")
			baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
			songUrls = append(songUrls, *songUrl)
		case val.Match(`320kbps`) == true:
			songUrl := getSongUrl(val, "320kbps")
			baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
			songUrls = append(songUrls, *songUrl)
		case val.Match(`32kbps`) == true:
			songUrl := getSongUrl(val, "32kbps")
			baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
			songUrls = append(songUrls, *songUrl)
		case val.Match(`500kbps`) == true:
			songUrl := getSongUrl(val, "500kbps")
			songUrl.Link = baseLink + "m4a/file-name.m4a"
			songUrls = append(songUrls, *songUrl)
		case val.Match(`Lossless`) == true:
			songUrl := getSongUrl(val, "Lossless")
			songUrl.Link = baseLink + "flac/file-name.flac"
			songUrls = append(songUrls, *songUrl)
		}
	})
	// http://data.chiasenhac.com/downloads/1184/2/1183017-cfc5f7df/flac/file-name.flac
	// replace the link 500kps and lossless with available link,  apply for registered user only
	// and reduce the link length
	var ret = dna.StringArray{}
	for _, songUrl := range songUrls {
		var br dna.String
		if songUrl.Bitrate == "Lossless" {
			br = "1411"
		} else {
			br = songUrl.Bitrate.Replace("kbps", "")
		}
		t := `"(` + songUrl.Link + "," + songUrl.Type + "," + songUrl.Size.ToString() + "," + br + `)"`
		ret.Push(t)
	}
	// dna.Log(`{` + ret.Join(",") + `}`)
	return `{` + ret.Join(",") + `}`

}
示例#2
0
func getStringifiedVideoUrls(urls dna.StringArray) dna.String {
	var baseLink = dna.String("")
	videoUrls := []VideoUrl{}
	urls.ForEach(func(val dna.String, idx dna.Int) {
		// dna.Log(val)
		// Finding bitrate
		switch {
		case val.Match(`MV 360p`) == true:
			songUrl := getVideoUrl(val, "360p")
			baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
			videoUrls = append(videoUrls, *songUrl)
		case val.Match(`MV 480p`) == true:
			songUrl := getVideoUrl(val, "480p")
			baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
			videoUrls = append(videoUrls, *songUrl)
		case val.Match(`MV 180p`) == true:
			songUrl := getVideoUrl(val, "180p")
			baseLink = songUrl.Link.ReplaceWithRegexp(`[0-9]+/file-name.+`, "")
			videoUrls = append(videoUrls, *songUrl)
		case val.Match(`HD 720p`) == true:
			songUrl := getVideoUrl(val, "720p")
			songUrl.Link = baseLink + "m4a/file-name.mp4"
			videoUrls = append(videoUrls, *songUrl)
		case val.Match(`HD 1080p`) == true:
			songUrl := getVideoUrl(val, "1080p")
			songUrl.Link = baseLink + "flac/file-name.mp4"
			videoUrls = append(videoUrls, *songUrl)
		}
	})

	var ret = dna.StringArray{}
	for _, videoUrl := range videoUrls {
		t := `"(` + videoUrl.Link + "," + videoUrl.Type + "," + videoUrl.Size.ToString() + "," + videoUrl.Resolution.Replace("p", "") + `)"`
		ret.Push(t)
	}
	// dna.Log(`{` + ret.Join(",") + `}`)
	return `{` + ret.Join(",") + `}`
}