當前位置: 首頁>>代碼示例>>Golang>>正文


Golang JsonQuery.Array方法代碼示例

本文整理匯總了Golang中github.com/jmoiron/jsonq.JsonQuery.Array方法的典型用法代碼示例。如果您正苦於以下問題:Golang JsonQuery.Array方法的具體用法?Golang JsonQuery.Array怎麽用?Golang JsonQuery.Array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/jmoiron/jsonq.JsonQuery的用法示例。


在下文中一共展示了JsonQuery.Array方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewPlaylist

// NewPlaylist gathers the metadata for a YouTube playlist and returns it.
func (yt YouTube) NewPlaylist(user *gumble.User, id string) ([]Song, error) {
	var apiResponse *jsonq.JsonQuery
	var songArray []Song
	var err error
	// Retrieve title of playlist
	url := fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=%s&key=%s", id, dj.conf.ServiceKeys.Youtube)
	if apiResponse, err = PerformGetRequest(url); err != nil {
		return nil, err
	}
	title, _ := apiResponse.String("items", "0", "snippet", "title")

	playlist := &AudioPlaylist{
		id:    id,
		title: title,
	}

	maxSongs := math.MaxInt32
	if dj.conf.General.MaxSongPerPlaylist > 0 {
		maxSongs = dj.conf.General.MaxSongPerPlaylist
	}
	pageToken := ""
	for len(songArray) < maxSongs { //Iterate over the pages

		// Retrieve items in this page of the playlist
		url = fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=%s&key=%s&pageToken=%s",
			id, dj.conf.ServiceKeys.Youtube, pageToken)
		if apiResponse, err = PerformGetRequest(url); err != nil {
			return nil, err
		}

		songs, _ := apiResponse.Array("items")
		for j := 0; j < len(songs) && len(songArray) < maxSongs; j++ {
			index := strconv.Itoa(j)
			videoID, _ := apiResponse.String("items", index, "snippet", "resourceId", "videoId")
			if song, err := yt.NewSong(user, videoID, "", playlist); err == nil {
				songArray = append(songArray, song)
			}
		}
		if pageToken, err = apiResponse.String("nextPageToken"); err != nil {
			break
		}
	}
	return songArray, nil
}
開發者ID:mpacella88,項目名稱:mumbledj,代碼行數:45,代碼來源:service_youtube.go


注:本文中的github.com/jmoiron/jsonq.JsonQuery.Array方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。