Fix Instagram API
Instagram API working again, in question is for how long...
This commit is contained in:
parent
ee82fdf57e
commit
d1b91fcee3
160
instagram/api.go
160
instagram/api.go
|
@ -17,56 +17,144 @@ import (
|
||||||
|
|
||||||
type InstagramListResponse struct {
|
type InstagramListResponse struct {
|
||||||
Tag struct {
|
Tag struct {
|
||||||
Media struct {
|
Name string `json:"name"`
|
||||||
|
ContentAdvisory interface{} `json:"content_advisory"`
|
||||||
|
Media struct {
|
||||||
Nodes []struct {
|
Nodes []struct {
|
||||||
ID string `json:"id"`
|
CommentsDisabled bool `json:"comments_disabled"`
|
||||||
Caption string `json:"caption"`
|
ID string `json:"id"`
|
||||||
DisplaySrc string `json:"display_src"`
|
Dimensions struct {
|
||||||
IsVideo bool `json:"is_video"`
|
Height int `json:"height"`
|
||||||
Owner struct {
|
Width int `json:"width"`
|
||||||
|
} `json:"dimensions"`
|
||||||
|
Owner struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
} `json:"owner"`
|
} `json:"owner"`
|
||||||
ThumbnailSrc string `json:"thumbnail_src"`
|
ThumbnailSrc string `json:"thumbnail_src"`
|
||||||
|
IsVideo bool `json:"is_video"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Date int `json:"date"`
|
Date int `json:"date"`
|
||||||
|
DisplaySrc string `json:"display_src"`
|
||||||
|
Caption string `json:"caption"`
|
||||||
|
Comments struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
} `json:"comments"`
|
||||||
|
Likes struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
} `json:"likes"`
|
||||||
} `json:"nodes"`
|
} `json:"nodes"`
|
||||||
|
Count int `json:"count"`
|
||||||
PageInfo struct {
|
PageInfo struct {
|
||||||
EndCursor string `json:"end_cursor"`
|
HasNextPage bool `json:"has_next_page"`
|
||||||
HasNextPage bool `json:"has_next_page"`
|
EndCursor string `json:"end_cursor"`
|
||||||
StartCursor string `json:"start_cursor"`
|
|
||||||
HasPreviousPage bool `json:"has_previous_page"`
|
|
||||||
} `json:"page_info"`
|
} `json:"page_info"`
|
||||||
Count int `json:"count"`
|
|
||||||
} `json:"media"`
|
} `json:"media"`
|
||||||
|
TopPosts struct {
|
||||||
|
Nodes []struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Dimensions struct {
|
||||||
|
Height int `json:"height"`
|
||||||
|
Width int `json:"width"`
|
||||||
|
} `json:"dimensions"`
|
||||||
|
Owner struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
} `json:"owner"`
|
||||||
|
ThumbnailSrc string `json:"thumbnail_src"`
|
||||||
|
IsVideo bool `json:"is_video"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
Date int `json:"date"`
|
||||||
|
DisplaySrc string `json:"display_src"`
|
||||||
|
Caption string `json:"caption"`
|
||||||
|
Comments struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
} `json:"comments"`
|
||||||
|
Likes struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
} `json:"likes"`
|
||||||
|
} `json:"nodes"`
|
||||||
|
} `json:"top_posts"`
|
||||||
} `json:"tag"`
|
} `json:"tag"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InstagramPostResponse struct {
|
type InstagramPostResponse struct {
|
||||||
Media struct {
|
Graphql struct {
|
||||||
Owner struct {
|
ShortcodeMedia struct {
|
||||||
ProfilePicURL string `json:"profile_pic_url"`
|
Typename string `json:"__typename"`
|
||||||
HasBlockedViewer bool `json:"has_blocked_viewer"`
|
ID string `json:"id"`
|
||||||
Username string `json:"username"`
|
Shortcode string `json:"shortcode"`
|
||||||
FullName string `json:"full_name"`
|
Dimensions struct {
|
||||||
RequestedByViewer bool `json:"requested_by_viewer"`
|
Height int `json:"height"`
|
||||||
FollowedByViewer bool `json:"followed_by_viewer"`
|
Width int `json:"width"`
|
||||||
IsPrivate bool `json:"is_private"`
|
} `json:"dimensions"`
|
||||||
ID string `json:"id"`
|
DisplayURL string `json:"display_url"`
|
||||||
BlockedByViewer bool `json:"blocked_by_viewer"`
|
VideoURL string `json:"video_url"`
|
||||||
IsUnpublished bool `json:"is_unpublished"`
|
VideoViewCount int `json:"video_view_count"`
|
||||||
} `json:"owner"`
|
IsVideo bool `json:"is_video"`
|
||||||
CaptionIsEdited bool `json:"caption_is_edited"`
|
EdgeMediaToTaggedUser struct {
|
||||||
VideoURL string `json:"video_url"`
|
Edges []interface{} `json:"edges"`
|
||||||
DisplaySrc string `json:"display_src"`
|
} `json:"edge_media_to_tagged_user"`
|
||||||
CommentsDisabled bool `json:"comments_disabled"`
|
EdgeMediaToCaption struct {
|
||||||
Code string `json:"code"`
|
Edges []struct {
|
||||||
IsAd bool `json:"is_ad"`
|
Node struct {
|
||||||
IsVideo bool `json:"is_video"`
|
Text string `json:"text"`
|
||||||
Caption string `json:"caption"`
|
} `json:"node"`
|
||||||
ID string `json:"id"`
|
} `json:"edges"`
|
||||||
Date int `json:"date"`
|
} `json:"edge_media_to_caption"`
|
||||||
VideoViews int `json:"video_views"`
|
CaptionIsEdited bool `json:"caption_is_edited"`
|
||||||
} `json:"media"`
|
EdgeMediaToComment struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
PageInfo struct {
|
||||||
|
HasNextPage bool `json:"has_next_page"`
|
||||||
|
EndCursor string `json:"end_cursor"`
|
||||||
|
} `json:"page_info"`
|
||||||
|
Edges []struct {
|
||||||
|
Node struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Text string `json:"text"`
|
||||||
|
CreatedAt int `json:"created_at"`
|
||||||
|
Owner struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
ProfilePicURL string `json:"profile_pic_url"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
} `json:"owner"`
|
||||||
|
} `json:"node"`
|
||||||
|
} `json:"edges"`
|
||||||
|
} `json:"edge_media_to_comment"`
|
||||||
|
CommentsDisabled bool `json:"comments_disabled"`
|
||||||
|
TakenAtTimestamp int `json:"taken_at_timestamp"`
|
||||||
|
EdgeMediaPreviewLike struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
Edges []struct {
|
||||||
|
Node struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
ProfilePicURL string `json:"profile_pic_url"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
} `json:"node"`
|
||||||
|
} `json:"edges"`
|
||||||
|
} `json:"edge_media_preview_like"`
|
||||||
|
EdgeMediaToSponsorUser struct {
|
||||||
|
Edges []interface{} `json:"edges"`
|
||||||
|
} `json:"edge_media_to_sponsor_user"`
|
||||||
|
Location interface{} `json:"location"`
|
||||||
|
ViewerHasLiked bool `json:"viewer_has_liked"`
|
||||||
|
Owner struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
ProfilePicURL string `json:"profile_pic_url"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
FollowedByViewer bool `json:"followed_by_viewer"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
IsPrivate bool `json:"is_private"`
|
||||||
|
RequestedByViewer bool `json:"requested_by_viewer"`
|
||||||
|
IsUnpublished bool `json:"is_unpublished"`
|
||||||
|
BlockedByViewer bool `json:"blocked_by_viewer"`
|
||||||
|
HasBlockedViewer bool `json:"has_blocked_viewer"`
|
||||||
|
} `json:"owner"`
|
||||||
|
IsAd bool `json:"is_ad"`
|
||||||
|
EdgeWebMediaToRelatedMedia struct {
|
||||||
|
Edges []interface{} `json:"edges"`
|
||||||
|
} `json:"edge_web_media_to_related_media"`
|
||||||
|
} `json:"shortcode_media"`
|
||||||
|
} `json:"graphql"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadList(token string) (*InstagramListResponse, error) {
|
func LoadList(token string) (*InstagramListResponse, error) {
|
||||||
|
|
|
@ -46,32 +46,32 @@ func iterList(list *InstagramListResponse) string {
|
||||||
log.Printf("Can't load Instagram post %s: %+v", image.Code, err)
|
log.Printf("Can't load Instagram post %s: %+v", image.Code, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if post.Media.IsAd {
|
if post.Graphql.ShortcodeMedia.IsAd {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var US database.User
|
var US database.User
|
||||||
if database.Db.Model(database.User{}).Where("name = ? AND service = ?", post.Media.Owner.Username, database.Instagram).First(&US).Count(&count); count == 0 {
|
if database.Db.Model(database.User{}).Where("name = ? AND service = ?", post.Graphql.ShortcodeMedia.Owner.Username, database.Instagram).First(&US).Count(&count); count == 0 {
|
||||||
US.DisplayName = post.Media.Owner.FullName
|
US.DisplayName = post.Graphql.ShortcodeMedia.Owner.FullName
|
||||||
US.Name = post.Media.Owner.Username
|
US.Name = post.Graphql.ShortcodeMedia.Owner.Username
|
||||||
US.Service = database.Instagram
|
US.Service = database.Instagram
|
||||||
US.Blocked = false
|
US.Blocked = false
|
||||||
database.Db.Create(&US)
|
database.Db.Create(&US)
|
||||||
}
|
}
|
||||||
if post.Media.IsVideo {
|
if post.Graphql.ShortcodeMedia.IsVideo {
|
||||||
log.Printf("Found video %s from %s", post.Media.Code, post.Media.Owner.Username)
|
log.Printf("Found video %s from %s", post.Graphql.ShortcodeMedia.Shortcode, post.Graphql.ShortcodeMedia.Owner.Username)
|
||||||
name, uname := ImageNameGenerator(post.Media.Code)
|
name, uname := ImageNameGenerator(post.Graphql.ShortcodeMedia.Shortcode)
|
||||||
res, err := GetHTTPResource(post.Media.VideoURL)
|
res, err := GetHTTPResource(post.Graphql.ShortcodeMedia.VideoURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Can't load video %s: %+v", post.Media.Code, err)
|
log.Printf("Can't load video %s: %+v", post.Graphql.ShortcodeMedia.Shortcode, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
ext, err := DownloadMedia(res.Body, name, true)
|
ext, err := DownloadMedia(res.Body, name, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Can't load video %s: %+v", post.Media.Code, err)
|
log.Printf("Can't load video %s: %+v", post.Graphql.ShortcodeMedia.Shortcode, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("Loaded video %s, location %s!", post.Media.Code, uname+ext)
|
log.Printf("Loaded video %s, location %s!", post.Graphql.ShortcodeMedia.Shortcode, uname+ext)
|
||||||
var IT database.Item
|
var IT database.Item
|
||||||
IT.UserID = US.ID
|
IT.UserID = US.ID
|
||||||
IT.Service = database.Instagram
|
IT.Service = database.Instagram
|
||||||
|
@ -82,23 +82,23 @@ func iterList(list *InstagramListResponse) string {
|
||||||
}
|
}
|
||||||
IT.IsVideo = true
|
IT.IsVideo = true
|
||||||
IT.Path = uname + ext
|
IT.Path = uname + ext
|
||||||
IT.OriginalID = post.Media.Code
|
IT.OriginalID = post.Graphql.ShortcodeMedia.Shortcode
|
||||||
database.Db.Create(&IT)
|
database.Db.Create(&IT)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Found picture %s from %s", post.Media.Code, post.Media.Owner.Username)
|
log.Printf("Found picture %s from %s", post.Graphql.ShortcodeMedia.Shortcode, post.Graphql.ShortcodeMedia.Owner.Username)
|
||||||
name, uname := ImageNameGenerator(post.Media.Code)
|
name, uname := ImageNameGenerator(post.Graphql.ShortcodeMedia.Shortcode)
|
||||||
res, err := GetHTTPResource(post.Media.DisplaySrc)
|
res, err := GetHTTPResource(post.Graphql.ShortcodeMedia.DisplayURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Can't load picture %s: %+v", post.Media.Code, err)
|
log.Printf("Can't load picture %s: %+v", post.Graphql.ShortcodeMedia.Shortcode, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
ext, err := DownloadMedia(res.Body, name, false)
|
ext, err := DownloadMedia(res.Body, name, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Can't load picture %s: %+v", post.Media.Code, err)
|
log.Printf("Can't load picture %s: %+v", post.Graphql.ShortcodeMedia.Shortcode, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("Loaded picture %s, location %s!", post.Media.Code, uname+ext)
|
log.Printf("Loaded picture %s, location %s!", post.Graphql.ShortcodeMedia.Shortcode, uname+ext)
|
||||||
var IT database.Item
|
var IT database.Item
|
||||||
IT.UserID = US.ID
|
IT.UserID = US.ID
|
||||||
IT.Service = database.Instagram
|
IT.Service = database.Instagram
|
||||||
|
@ -109,7 +109,7 @@ func iterList(list *InstagramListResponse) string {
|
||||||
}
|
}
|
||||||
IT.IsVideo = false
|
IT.IsVideo = false
|
||||||
IT.Path = uname + ext
|
IT.Path = uname + ext
|
||||||
IT.OriginalID = post.Media.Code
|
IT.OriginalID = post.Graphql.ShortcodeMedia.Shortcode
|
||||||
database.Db.Create(&IT)
|
database.Db.Create(&IT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue