Feature: add comments for artwork page (currently limited to 30)

This commit is contained in:
VnPower
2023-06-04 21:59:51 +07:00
parent 696eb47501
commit f8f08342bb
6 changed files with 137 additions and 46 deletions
+24 -1
View File
@@ -26,7 +26,8 @@ const (
ArtworkInformationURL = "https://www.pixiv.net/ajax/illust/%s"
ArtworkImagesURL = "https://www.pixiv.net/ajax/illust/%s/pages"
ArtworkRelatedURL = "https://www.pixiv.net/ajax/illust/%s/recommend/init?limit=%d"
ArtworkNewestURL = "https://www.pixiv.net/ajax/illust/new?limit=200&type=%s&r18=%s&lastId=%s"
ArtworkCommentsURL = "https://www.pixiv.net/ajax/illusts/comments/roots?illust_id=%s&limit=100"
ArtworkNewestURL = "https://www.pixiv.net/ajax/illust/new?limit=30&type=%s&r18=%s&lastId=%s"
ArtworkRankingURL = "https://www.pixiv.net/ranking.php?format=json&mode=%s&content=%s&p=%s"
SearchTagURL = "https://www.pixiv.net/ajax/search/tags/%s"
SearchArtworksURL = "https://www.pixiv.net/ajax/search/%s/%s?order=%s&mode=%s&p=%s"
@@ -197,6 +198,28 @@ func (p *PixivClient) GetArtworkByID(id string) (*models.Illust, error) {
return illust.Illust, nil
}
func (p *PixivClient) GetArtworkComments(id string) ([]models.Comment, error) {
var pr models.PixivResponse
var body struct {
Comments []models.Comment `json:"comments"`
}
s, _ := p.TextRequest(fmt.Sprintf(ArtworkCommentsURL, id))
err := json.Unmarshal([]byte(s), &pr)
if err != nil {
return nil, errors.New(fmt.Sprintf("Failed to extract data from JSON response from server. %s", err))
}
if pr.Error {
return nil, errors.New(pr.Message)
}
err = json.Unmarshal([]byte(pr.Body), &body)
return body.Comments, nil
}
func (p *PixivClient) GetUserArtworksID(id string, page int) (*string, error) {
s, _ := p.TextRequest(fmt.Sprintf(UserArtworksURL, id))