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 { |
| 13 | 13 | |
| 14 | 14 | Total int |
| 15 | 15 | 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"` |
| 19 | 19 | |
| 20 | | Desctiption string |
| 20 | Posted time |
| 21 | Author bool `json:"isAuthorHighlited"` |
| 21 | 22 | |
| 22 | | // упрощение структуры с комментами |
| 23 | | Comment string |
| 23 | Desctiption string |
| 24 | Comment string |
| 24 | 25 | |
| 25 | | TextContent struct { |
| 26 | | Html struct { |
| 27 | | Markup string |
| 28 | | } |
| 29 | | } |
| 26 | TextContent text |
| 30 | 27 | |
| 31 | 28 | User struct { |
| 32 | 29 | Username string |
| 33 | | IsBanned bool |
| 30 | Banned bool `json:"isBanned"` |
| 34 | 31 | } |
| 35 | 32 | } |
| 36 | 33 | } |
deviantion.go
+12 −7
| @@ -21,10 +21,14 @@ func (t *time) UnmarshalJSON(b []byte) (err error) { |
| 21 | 21 | |
| 22 | 22 | // самая главная структура для поста |
| 23 | 23 | type 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 { |
| 28 | 32 | Username string |
| 29 | 33 | } |
| 30 | 34 | Stats struct { |
| @@ -54,11 +58,13 @@ type media struct { |
| 54 | 58 | } |
| 55 | 59 | |
| 56 | 60 | type text struct { |
| 57 | | Html struct { |
| 61 | Excerpt string |
| 62 | Html struct { |
| 58 | 63 | Markup, Type string |
| 59 | 64 | } |
| 60 | 65 | } |
| 61 | 66 | |
| 67 | // структура поста |
| 62 | 68 | type Deviantion struct { |
| 63 | 69 | Deviation deviantion |
| 64 | 70 | Comments struct { |
| @@ -73,7 +79,6 @@ type Deviantion struct { |
| 73 | 79 | } |
| 74 | 80 | |
| 75 | 81 | IMG, Desctiption string |
| 76 | | Recomendations []deviantion |
| 77 | 82 | } |
| 78 | 83 | |
| 79 | 84 | // для работы функции нужно ID поста и имя пользователя. |
| @@ -98,7 +103,7 @@ func Deviation(id string, user string) Deviantion { |
| 98 | 103 | |
| 99 | 104 | // базовая обработка описания |
| 100 | 105 | txt := st.Deviation.TextContent.Html.Markup |
| 101 | | if len(txt) > 0 && txt[0:1] == "{" { |
| 106 | if len(txt) > 0 && txt[1] == 125 { |
| 102 | 107 | var description struct { |
| 103 | 108 | Blocks []struct { |
| 104 | 109 | Text string |
examples/post.go
deleted
−25
| @@ -1,25 +0,0 @@ |
| 1 | | package main |
| 2 | | |
| 3 | | import ( |
| 4 | | "git.macaw.me/skunky/devianter" |
| 5 | | ) |
| 6 | | |
| 7 | | func 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 @@ |
| 2 | 2 | - emojis |
| 3 | 3 | - deviantions |
| 4 | 4 | - comments |
| 5 | - search (including gallery search) |
| 6 | - users (with gallery) |
misc.go
+35 −14
| @@ -3,11 +3,11 @@ package devianter |
| 3 | 3 | import ( |
| 4 | 4 | "encoding/json" |
| 5 | 5 | "errors" |
| 6 | | "fmt" |
| 7 | 6 | "io" |
| 8 | 7 | "log" |
| 9 | 8 | "math" |
| 10 | 9 | "net/http" |
| 10 | "strconv" |
| 11 | 11 | "strings" |
| 12 | 12 | ) |
| 13 | 13 | |
| @@ -117,27 +117,44 @@ func AEmedia(name string, t rune) (string, error) { |
| 117 | 117 | |
| 118 | 118 | /* SEARCH */ |
| 119 | 119 | type 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"` |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | | func Search(query, page string, scope rune) (ss search) { |
| 125 | func Search(query string, page int, scope rune, user ...string) (ss search, e error) { |
| 126 | 126 | var url strings.Builder |
| 127 | e = nil |
| 127 | 128 | |
| 128 | 129 | // о5 построение ссылок. |
| 129 | 130 | switch scope { |
| 130 | | case 'a': |
| 131 | case 'a': // поиск артов по названию |
| 131 | 132 | url.WriteString("dabrowse/search/all?q=") |
| 132 | | case 't': |
| 133 | case 't': // поиск артов по тегам |
| 133 | 134 | 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 | } |
| 134 | 146 | 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.") |
| 136 | 148 | } |
| 137 | 149 | |
| 138 | 150 | 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)) |
| 141 | 158 | |
| 142 | 159 | ujson(url.String(), &ss) |
| 143 | 160 | |
| @@ -184,10 +201,14 @@ func puppy(data string) (string, error) { |
| 184 | 201 | } |
| 185 | 202 | } |
| 186 | 203 | |
| 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) |
| 191 | 212 | |
| 192 | 213 | // если код ответа не 200, возвращается ошибка |
| 193 | 214 | 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 @@ |
| 1 | package devianter |
| 2 | |
| 3 | import ( |
| 4 | "strconv" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // структура группы или пользователя |
| 9 | type 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 | |
| 75 | func UGroup(name string) (g Group) { |
| 76 | ujson("dauserprofile/init/about?username="+name, &g) |
| 77 | |
| 78 | return |
| 79 | } |
| 80 | |
| 81 | // гарелея пользователя или группы |
| 82 | func 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 | } |