示例#1
0
func (this *baiduMusicPlayer) parserMusicLinkList(js *simplejson.Json, musicList *map[string]*element.MusicInfo) {
	data := js.Get("data").MustMap()
	if songList, ok := data["songList"].([]interface{}); ok {
		for _, info := range songList {
			musicInfo := info.(map[string]interface{})
			id := musicInfo["songId"].(json.Number).String()
			if _, ok := (*musicList)[id]; !ok {
				fmt.Println("Key Not Found")
				continue
			}

			var music *element.MusicInfo = (*musicList)[id]
			if musicInfo["showLink"] == nil {
				delete(*musicList, id)
				continue
			}
			music.MusicPath = musicInfo["showLink"].(string)
			if musicInfo["lrcLink"] == nil {
				delete(*musicList, id)
				continue
			}
			music.LyricPath = baiduMusicHost + musicInfo["lrcLink"].(string)
			if musicInfo["time"] == nil {
				delete(*musicList, id)
				continue
			}
			musicTime, _ := musicInfo["time"].(json.Number).Int64()
			music.MusicTime = int(musicTime)
			music.MusicFormat = "mp3"
		}
	} else {
		musicList = nil
	}
}
示例#2
0
文件: music.go 项目: zero2012/music
func (this *musicModel) QueryMusicById(musicId int) (*element.MusicInfo, error) {
	if DatabaseInstance().Open() != nil {
		return nil, errors.New("打开数据库失败")
	}
	defer DatabaseInstance().Close()
	rows, err := DatabaseInstance().DB.Query("select musicname, authorname, albumname, time, type from music where musicId = ?", musicId)
	if err != nil {
		fmt.Println(err)
		return nil, errors.New("查询失败")
	}
	if rows.Next() {
		var musicInfo *element.MusicInfo = &element.MusicInfo{}
		rows.Scan(&musicInfo.MusicName, &musicInfo.MusicAuthor, &musicInfo.AlbumName, &musicInfo.MusicTime, &musicInfo.SourceType)
		musicInfo.MusicId = musicId
		switch musicInfo.SourceType {
		case element.BaiduMusicSourceType:
			err = BaiduMusicModelInstance().FetchMusicInfo(musicInfo)
		case element.LocalMusicSourceType:
			err = MyMusicModelInstance().FetchMusicInfo(musicInfo)
		default:
			return nil, errors.New("SourceType Error!")
		}
		return musicInfo, err
	}
	return nil, errors.New("查询失败")
}
示例#3
0
文件: music.go 项目: zero2012/music
func (this *musicModel) SaveMusic(musicInfo *element.MusicInfo) (int, error) {
	if musicInfo == nil && musicInfo.SourceType != element.BaiduMusicSourceType &&
		musicInfo.SourceType != element.LocalMusicSourceType {
		return 0, errors.New("参数错误")
	}
	if DatabaseInstance().Open() != nil {
		return 0, errors.New("打开数据库失败")
	}
	defer DatabaseInstance().Close()
	stmt, err := DatabaseInstance().DB.Prepare("insert INTO music(musicname, authorname, albumname, time, type) VALUES(?, ?, ?, ?, ?)")
	if err != nil {
		return 0, err
	}
	result, err := stmt.Exec(musicInfo.MusicName, musicInfo.MusicAuthor, musicInfo.AlbumName, musicInfo.MusicTime, musicInfo.SourceType)
	if err != nil {
		return 0, err
	}
	musicId, err := result.LastInsertId()
	musicInfo.MusicId = int(musicId)
	switch musicInfo.SourceType {
	case element.BaiduMusicSourceType:
		return BaiduMusicModelInstance().InsertMusic(musicInfo)
	case element.LocalMusicSourceType:
		return MyMusicModelInstance().InsertMusic(musicInfo)
	default:
		return 0, errors.New("SourceType Error")
	}
}
示例#4
0
func (this *baiduMusicPlayer) checkMusicIsValid(musicInfo *element.MusicInfo) bool {
	// 非http://yinyueshiting.baidu.com个歌曲屏蔽
	if strings.HasPrefix(musicInfo.MusicPath, "http://yinyueshiting.baidu.com") {
		if musicInfo.LyricPath == "http://fm.baidu.com" {
			// 将歌词不对的,直接将歌词赋值空
			musicInfo.LyricPath = ""
		}
		return true
	}
	return false
}
示例#5
0
func (this *baiduMusicPlayer) parserMusicInfoList(js *simplejson.Json, musicList *map[string]*element.MusicInfo) {
	data := js.Get("data").MustMap()
	if songList, ok := data["songList"].([]interface{}); ok {
		for _, info := range songList {
			musicInfo := info.(map[string]interface{})
			id := musicInfo["songId"].(string)
			var music *element.MusicInfo = &element.MusicInfo{}
			var err error
			music.NetMusicId, err = strconv.Atoi(id)
			if err != nil {
				continue
			}
			music.MusicName = musicInfo["songName"].(string)
			music.MusicAuthor = musicInfo["artistName"].(string)
			music.SmallCoverImagePath = musicInfo["songPicSmall"].(string)
			music.BigCoverImagePath = musicInfo["songPicBig"].(string)
			music.AlbumName = musicInfo["albumName"].(string)
			music.SourceType = element.BaiduMusicSourceType
			(*musicList)[id] = music
		}
	}
}