110 lines
2.8 KiB
Go
110 lines
2.8 KiB
Go
package post
|
|
|
|
import (
|
|
"encoding/json"
|
|
"regexp"
|
|
"skunkyart/util"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type Post struct {
|
|
Deviation util.Deviation
|
|
Comments struct {
|
|
Total, Cursor int
|
|
}
|
|
}
|
|
|
|
var tmp struct {
|
|
Author, Postname, Img, Description, Time, Tags, Comments, License, Recomendations string
|
|
Views, FavsCount, Downloads int
|
|
Nsfw, Ai, DD bool
|
|
}
|
|
|
|
func _post(id []string, author string, url string, page int) string {
|
|
var j Post
|
|
|
|
if !strings.Contains(url, "journal/") {
|
|
url = "art/" + url
|
|
}
|
|
|
|
// парсинг
|
|
rawjson := util.Puppy("dadeviation/init?deviationid=" + id[len(id)-1] + "&username=" + author + "&type=art&include_session=false&expand=deviation.related&preload=true")
|
|
if strings.Contains(rawjson, "{") {
|
|
json.Unmarshal([]byte(rawjson), &j)
|
|
} else {
|
|
println("Something went wrong. Maybe, rate limit?")
|
|
}
|
|
|
|
tmp.Nsfw = j.Deviation.IsMature
|
|
if !util.Conf.Nsfw && j.Deviation.IsMature {
|
|
return "NSFW content has been disabled on this instance."
|
|
}
|
|
|
|
tmp.Author = j.Deviation.Author.Username
|
|
tmp.Postname = j.Deviation.Title
|
|
|
|
tmp.Img = util.Images(j.Deviation, j.Deviation.Media, true)
|
|
|
|
if j.Deviation.Extended.DescriptionText.Html.Markup != "" {
|
|
tmp.Description = util.ParseDescription(j.Deviation.Extended.DescriptionText)
|
|
} else {
|
|
tmp.Description = util.ParseDescription(j.Deviation.TextContent)
|
|
}
|
|
|
|
tmp.Time = j.Deviation.PublishedTime.UTC().String()
|
|
tmp.Views = j.Deviation.Stats.Views
|
|
tmp.FavsCount = j.Deviation.Stats.Favourites
|
|
|
|
tmp.Downloads = j.Deviation.Stats.Downloads
|
|
tmp.Ai = j.Deviation.IsAiGenerated
|
|
tmp.License = j.Deviation.License
|
|
tmp.DD = j.Deviation.IsDailyDeviation
|
|
|
|
tmp.Recomendations = ""
|
|
for _, a := range j.Deviation.Extended.RelatedContent {
|
|
for _, a := range a.Deviations {
|
|
tmp.Recomendations += util.Images(a, a.Media, false)
|
|
}
|
|
}
|
|
|
|
tmp.Tags = ""
|
|
for _, a := range j.Deviation.Extended.Tags {
|
|
tmp.Tags += "<a href=\"" + util.Conf.Base_uri + "search?q=" + a.Name + "&scope=tag\">#" + a.Name + "</a> "
|
|
}
|
|
|
|
tmp.Comments = ""
|
|
if j.Comments.Total > 0 {
|
|
tmp.Comments = *GetComments(url, strconv.Itoa(j.Comments.Cursor), page, 1, id)
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func Get(uri string, page int, output chan string) {
|
|
var url string
|
|
|
|
switch {
|
|
case strings.Contains(uri, "journal/"):
|
|
url = "https://www.deviantart.com/" + uri
|
|
default:
|
|
url = "https://www.deviantart.com/art/" + uri
|
|
}
|
|
|
|
id := regexp.MustCompile("[0-9]+").FindAllString(uri, -1)
|
|
|
|
body, status, _, _ := util.Request(url, "")
|
|
if status == 200 {
|
|
body = body[strings.Index(body, " by ")+4:]
|
|
err := _post(id, body[0:strings.Index(body, " ")], uri, page)
|
|
|
|
if err != "" {
|
|
output <- err
|
|
}
|
|
|
|
// темплейт
|
|
output <- util.TmpExec("templates/post.htm", &tmp)
|
|
} else {
|
|
output <- "Something went wrong. Status: " + strconv.Itoa(int(status))
|
|
}
|
|
}
|