Commit 9b85088665

9b850886656bb2ecf192e6d9df63ea07d175de06

parent: 66ab740d7f

Unsigned

lost+skunk <skunky@macaw.me> · 2024-06-05 11:32 UTC

User implementation and particaly groups

Layout: unified · split

comments.go +9 −12
@@ -13,24 +13,21 @@ type comments struct {
1313
1414 Total int
1515 Thread []struct {
16 CommentId, ParentId, Replies, Likes int
17 Posted time
18 IsAuthorHighlited bool
16 Replies, Likes int
17 ID int `json:"commentId"`
18 Parent int `json:"ParrentId"`
1919
20 Desctiption string
20 Posted time
21 Author bool `json:"isAuthorHighlited"`
2122
22 // упрощение структуры с комментами
23 Comment string
23 Desctiption string
24 Comment string
2425
25 TextContent struct {
26 Html struct {
27 Markup string
28 }
29 }
26 TextContent text
3027
3128 User struct {
3229 Username string
33 IsBanned bool
30 Banned bool `json:"isBanned"`
3431 }
3532 }
3633}
deviantion.go +12 −7
@@ -21,10 +21,14 @@ func (t *time) UnmarshalJSON(b []byte) (err error) {
2121
2222// самая главная структура для поста
2323type deviantion struct {
24 Title, Url, License string
25 PublishedTime time
26 IsMature, IsAiGenerated, IsDailyDeviation bool
27 Author struct {
24 Title, Url, License string
25 PublishedTime time
26
27 NSFW bool `json:"isMature"`
28 AI bool `json:"isAiGenerated"`
29 DD bool `json:"isDailyDeviation"`
30
31 Author struct {
2832 Username string
2933 }
3034 Stats struct {
@@ -54,11 +58,13 @@ type media struct {
5458}
5559
5660type text struct {
57 Html struct {
61 Excerpt string
62 Html struct {
5863 Markup, Type string
5964 }
6065}
6166
67// структура поста
6268type Deviantion struct {
6369 Deviation deviantion
6470 Comments struct {
@@ -73,7 +79,6 @@ type Deviantion struct {
7379 }
7480
7581 IMG, Desctiption string
76 Recomendations []deviantion
7782}
7883
7984// для работы функции нужно ID поста и имя пользователя.
@@ -98,7 +103,7 @@ func Deviation(id string, user string) Deviantion {
98103
99104 // базовая обработка описания
100105 txt := st.Deviation.TextContent.Html.Markup
101 if len(txt) > 0 && txt[0:1] == "{" {
106 if len(txt) > 0 && txt[1] == 125 {
102107 var description struct {
103108 Blocks []struct {
104109 Text string
examples/post.go deleted −25
@@ -1,25 +0,0 @@
1package main
2
3import (
4 "git.macaw.me/skunky/devianter"
5)
6
7func main() {
8 id := "973578309"
9 d := devianter.Deviation(id, "Thrumyeye")
10
11 println("Post Name:", d.Deviation.Title, "\nIMG url:", d.IMG)
12
13 c := devianter.Comments(id, "", 0, 1)
14 println("\n\nPost Comments:", c.Total)
15
16 for _, a := range c.Thread {
17 if a.User.IsBanned {
18 a.User.Username += " [v bane]"
19 }
20 println(a.User.Username+":", a.Comment)
21 }
22
23 search := devianter.Search("skunk", "2", 'a')
24 println(search.Total, search.Pages)
25}
implementation.md +2
@@ -2,3 +2,5 @@
22- emojis
33- deviantions
44- comments
5- search (including gallery search)
6- users (with gallery)
misc.go +35 −14
@@ -3,11 +3,11 @@ package devianter
33import (
44 "encoding/json"
55 "errors"
6 "fmt"
76 "io"
87 "log"
98 "math"
109 "net/http"
10 "strconv"
1111 "strings"
1212)
1313
@@ -117,27 +117,44 @@ func AEmedia(name string, t rune) (string, error) {
117117
118118/* SEARCH */
119119type search struct {
120 Total int `json:"estTotal"`
121 Pages int // only for 'a' scope.
122 Deviations []deviantion
120 Total int `json:"estTotal"`
121 Pages int // only for 'a' and 'g' scope.
122 Results []deviantion `json:"deviations,results"`
123123}
124124
125func Search(query, page string, scope rune) (ss search) {
125func Search(query string, page int, scope rune, user ...string) (ss search, e error) {
126126 var url strings.Builder
127 e = nil
127128
128129 // о5 построение ссылок.
129130 switch scope {
130 case 'a':
131 case 'a': // поиск артов по названию
131132 url.WriteString("dabrowse/search/all?q=")
132 case 't':
133 case 't': // поиск артов по тегам
133134 url.WriteString("dabrowse/networkbar/tag/deviations?tag=")
135 case 'g': // поиск артов пользователя или группы
136 if user != nil {
137 url.WriteString("dashared/gallection/search?username=")
138 for _, a := range user {
139 url.WriteString(a)
140 }
141 url.WriteString("&type=gallery&order=most-recent&init=true&limit=50&q=")
142 } else {
143 e = errors.New("Missing username (last argument)")
144 return
145 }
134146 default:
135 log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag.")
147 log.Fatalln("Invalid type.\n- 'a' -- all;\n- 't' -- tag;\n- 'g' - gallery.")
136148 }
137149
138150 url.WriteString(query)
139 url.WriteString("&page=")
140 url.WriteString(page)
151 if scope != 'g' { // если область поиска не равна поиску по группам, то активируется этот код
152 url.WriteString("&page=")
153 } else { // иначе вместо страницы будет оффсет и страница умножится на 50
154 url.WriteString("&offset=")
155 page = 50 * page
156 }
157 url.WriteString(strconv.Itoa(page))
141158
142159 ujson(url.String(), &ss)
143160
@@ -184,10 +201,14 @@ func puppy(data string) (string, error) {
184201 }
185202 }
186203
187 body := request(
188 fmt.Sprintf("https://www.deviantart.com/_puppy/%s&csrf_token=%s&da_minor_version=20230710", data, token),
189 cookie,
190 )
204 var url strings.Builder
205 url.WriteString("https://www.deviantart.com/_puppy/")
206 url.WriteString(data)
207 url.WriteString("&csrf_token=")
208 url.WriteString(token)
209 url.WriteString("&da_minor_version=20230710")
210
211 body := request(url.String(), cookie)
191212
192213 // если код ответа не 200, возвращается ошибка
193214 if body.Status != 200 {
todo.md +2 −3
@@ -1,3 +1,2 @@
1- ~~users~~
2- ~~groups~~
3- ~~images in comments~~
\ No newline at end of file
1- groups
2- images in comments
\ No newline at end of file
user-group.go added +92
@@ -0,0 +1,92 @@
1package devianter
2
3import (
4 "strconv"
5 "strings"
6)
7
8// структура группы или пользователя
9type Group struct {
10 ErrorDescription string
11 Owner struct {
12 Group bool `json:"isGroup"`
13 Username string
14 }
15 Gruser struct {
16 ID int `json:"gruserId"`
17 Page struct {
18 Modules []struct {
19 Name string
20 ModuleData struct {
21 About struct {
22 Country, Website, WebsiteLabel, Gender, Tagline string
23 DeviantFor int64
24 SocialLinks []struct {
25 Value string
26 }
27 TextContent text
28 Interests []struct {
29 Label, Value string
30 }
31 }
32 CoverDeviation struct {
33 Deviation deviantion `json:"coverDeviation"`
34 }
35
36 // группы
37 GroupAbout struct {
38 Tagline string
39 CreatinDate time `json:"foundationTs"`
40 Description text
41 }
42 GroupAdmins struct {
43 Results []struct {
44 Username string
45 }
46 }
47 Folders struct {
48 Results []struct {
49 FolderId int
50 Name string
51 }
52 }
53
54 // галерея
55 ModuleData struct {
56 Folder struct {
57 Username string
58 Pages int `json:"totalPageCount"`
59 Deviations []deviantion
60 } `json:"folderDeviations"`
61 }
62 }
63 }
64 }
65 }
66 PageExtraData struct {
67 GruserTagline string
68 Stats struct {
69 Deviations, Watchers, Watching, Pageviews, CommentsMade, Favourites, Friends int
70 FeedComments int `json:"commentsReceivedProfile"`
71 }
72 }
73}
74
75func UGroup(name string) (g Group) {
76 ujson("dauserprofile/init/about?username="+name, &g)
77
78 return
79}
80
81// гарелея пользователя или группы
82func Gallery(name string, page int) (g Group) {
83 var url strings.Builder
84 url.WriteString("dauserprofile/init/gallery?username=")
85 url.WriteString(name)
86 url.WriteString("&page=")
87 url.WriteString(strconv.Itoa(page))
88 url.WriteString("&deviations_limit=50&with_subfolders=false")
89
90 ujson(url.String(), &g)
91 return
92}