Пример #1
0
func (this *MessageController) handleGetRequest(w http.ResponseWriter, r *http.Request) {
	action := r.Form.Get("action")
	switch action {
	case "getMusicList":
		music.MusicManagerInstance().FetchMusicList()
		NormalResponse(w, OK)
	case "downloadMusic":
		musicId, err := strconv.Atoi(r.Form.Get("musicId"))
		if err != nil {
			NormalResponse(w, InvalidParam)
		} else {
			fmt.Println("downloadMusic: ", musicId)
			w.Header().Set("Content-Type", "audio/mpeg")
			this.writeStream(musicId, music.MusicManagerInstance().DownloadMusic, w)
		}
	case "downloadBigCover":
		musicId, err := strconv.Atoi(r.Form.Get("musicId"))
		if err != nil {
			NormalResponse(w, InvalidParam)
		} else {
			fmt.Println("downloadBigCover: ", musicId)
			this.writeStream(musicId, music.MusicManagerInstance().DownloadBigCoverImage, w)
		}
	case "downloadSmallCover":
		musicId, err := strconv.Atoi(r.Form.Get("musicId"))
		if err != nil {
			NormalResponse(w, InvalidParam)
		} else {
			fmt.Println("downloadSmallCover: ", musicId)
			this.writeStream(musicId, music.MusicManagerInstance().DownloadSmallCoverImage, w)
		}
	case "downloadLyric":
		musicId, err := strconv.Atoi(r.Form.Get("musicId"))
		if err != nil {
			NormalResponse(w, InvalidParam)
		} else {
			fmt.Println("downloadLyric: ", musicId)
			this.writeStream(musicId, music.MusicManagerInstance().DownloadLyric, w)
		}
	}
}
Пример #2
0
func (this *MusicController) MusicAction(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	tokenCookie, err := r.Cookie("token")
	if err != nil {
		fmt.Println("cookie Error: ", err)
		NormalResponse(w, InvalidToken)
	} else if len(tokenCookie.Value) == 0 {
		NormalResponse(w, EmptyToken)
	} else {
		ret, userId := token.TokenManagerInstance().CheckTokenExist(tokenCookie.Value)
		if ret == false {
			fmt.Println("search Token Error: ", err)
			NormalResponse(w, InvalidToken)
		} else {
			fmt.Println("userId: ", userId)
			action := r.Form.Get("action")
			fmt.Println(action)
			switch action {
			case "fetchRandomList":
				music.MusicManagerInstance().SetPlayer(music.BaiduPlayer)
				this.fetchRandomList(w, r)
			case "fetchLoveList":
				this.fetchLoveList(userId, w, r)
			case "fetchListenedList":
				this.fetchListenedList(userId, w, r)
			case "loveMusic":
				this.loveMusic(userId, w, r)
			case "listenMusic":
				this.listenMusic(userId, w, r)
			case "searchMusic":
				this.searchMusic(w, r)
			case "musicProxy":
				// 先测试请求某一首歌
				// action="musicProxy&player=baidu&type=fetchList&"
				var musicURL string = "http://yinyueshiting.baidu.com/data2/music/134380410/5963228158400128.mp3?xcode=55a3d05c2c746155f1962d1d1690fc93"
				this.fetchMusicWithProxy(musicURL, w, r)
			}
		}
	}
}
Пример #3
0
func (this *MusicController) fetchRandomList(w http.ResponseWriter, r *http.Request) {
	musicList := music.MusicManagerInstance().FetchMusicList()
	if len(musicList) != 0 {
		this.writeMusicInfo(musicList, w)
	}
}