-
Notifications
You must be signed in to change notification settings - Fork 3
/
details.go
166 lines (146 loc) · 4.82 KB
/
details.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package facebook
import "github.com/tamboto2000/jsonextract/v3"
// NamePronunciation contains name pronunciation, include text and audio file URI
type NamePronunciation struct {
Text string `json:"text,omitempty"`
AudioURI string `json:"audioURI,omitempty"`
}
// OtherName contains user name and its type
type OtherName struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
}
// Details contains profile's detail information, such as "About You", nicknames, name pronunciation, etc.
type Details struct {
About string `json:"about,omitempty"`
NamePronunciation *NamePronunciation `json:"namePronunciation,omitempty"`
OtherNames []OtherName `json:"otherNames,omitempty"`
FavoriteQuotes string `json:"favoriteQuotes,omitempty"`
}
// SyncDetails retrieve profile's details info
func (about *About) SyncDetails() error {
jsons, err := about.profile.reqAboutCollection(aboutDetails)
if err != nil {
return err
}
for _, json := range jsons {
val, ok := json.Object()["label"]
if !ok {
continue
}
if val.String() == "ProfileCometAboutAppSectionQuery$defer$ProfileCometAboutAppSectionContent_appSection" {
details := extractDetails(json)
about.Details = details
break
}
}
return nil
}
func extractDetails(json *jsonextract.JSON) *Details {
details := new(Details)
if val, ok := json.Object()["data"]; ok {
if val, ok := val.Object()["activeCollections"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for _, node := range val.Array() {
if val, ok := node.Object()["style_renderer"]; ok {
if val, ok := val.Object()["profile_field_sections"]; ok {
for _, section := range val.Array() {
val, ok := section.Object()["field_section_type"]
if !ok {
continue
}
// extract about
if val.String() == "about_me" {
if val, ok := section.Object()["profile_fields"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for _, node := range val.Array() {
if val, ok := node.Object()["renderer"]; ok {
if val, ok := val.Object()["field"]; ok {
if val, ok := val.Object()["text_content"]; ok {
if val, ok := val.Object()["text"]; ok {
details.About = val.String()
}
}
}
}
}
}
}
}
// extract name pronunciation
if val.String() == "name_pronunciation" {
if val, ok := section.Object()["profile_fields"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for _, node := range val.Array() {
if val, ok := node.Object()["renderer"]; ok {
pronun := new(NamePronunciation)
if val, ok := val.Object()["audio_uri"]; ok {
pronun.AudioURI = val.String()
}
if val, ok := val.Object()["text_content"]; ok {
if val, ok := val.Object()["text"]; ok {
pronun.Text = val.String()
}
}
details.NamePronunciation = pronun
}
}
}
}
}
// extract nicknames
if val.String() == "nicknames" {
if val, ok := section.Object()["profile_fields"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for i, node := range val.Array() {
if i == 0 {
continue
}
nickname := OtherName{
Name: node.Object()["title"].Object()["text"].String(),
}
if val, ok := node.Object()["list_item_groups"]; ok {
for _, group := range val.Array() {
if val, ok := group.Object()["list_items"]; ok {
for _, item := range val.Array() {
if val, ok := item.Object()["text"]; ok {
if val, ok := val.Object()["text"]; ok {
nickname.Type = val.String()
}
}
}
}
}
}
details.OtherNames = append(details.OtherNames, nickname)
}
}
}
}
// extract quotes
if val.String() == "favorite_quotes" {
if val, ok := section.Object()["profile_fields"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for _, node := range val.Array() {
if val, ok := node.Object()["renderer"]; ok {
if val, ok := val.Object()["field"]; ok {
if val, ok := val.Object()["text_content"]; ok {
if val, ok := val.Object()["text"]; ok {
details.FavoriteQuotes = val.String()
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return details
}