Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

Commit f5982fe

Browse files
committed
Gif support added to html export
1 parent 65381f7 commit f5982fe

File tree

8 files changed

+64
-33
lines changed

8 files changed

+64
-33
lines changed

components/main.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (theme *Theme) LoadTheme(themeName string, DW_MEDIA bool) {
6565
theme.IMG = theme.parseComponent("img")
6666
theme.STICKER = theme.parseComponent("sticker")
6767
theme.REPLY = theme.parseComponent("reply")
68+
theme.GIF = theme.parseComponent("gifs")
6869
theme.DownloadMedia = DW_MEDIA
6970
}
7071

@@ -93,6 +94,21 @@ func (theme Theme) MessageComponent(msg discord.Message, previousMsg discord.Mes
9394
panic(attach.ContentType)
9495
}
9596
}
97+
98+
gifContents := ""
99+
100+
for _, embed := range msg.Embeds {
101+
if embed.Type == discord.EMBED_GIF {
102+
gifContents += tools.ParseTemplate(theme.GIF, map[string]string{
103+
"VIDEO_URL": embed.Url,
104+
"WIDTH": fmt.Sprint(float64(embed.Thumbnail.Width)*0.7),
105+
"HEIGHT": fmt.Sprint(float64(embed.Thumbnail.Height)*0.7),
106+
})
107+
if msg.Content == embed.GifContentUrl {
108+
content = ""
109+
}
110+
}
111+
}
96112

97113
stickerContent := ""
98114

@@ -121,14 +137,16 @@ func (theme Theme) MessageComponent(msg discord.Message, previousMsg discord.Mes
121137
"ID": msg.ID,
122138
"REPLY_CONTENT": replyContent,
123139
"STICKER_CONTENT": stickerContent,
140+
"GIFS": gifContents,
124141
})
125142
} else {
126143
return tools.ParseTemplate(theme.MSG, map[string]string{
127-
"DATE": discord.TimestampToTime(msg.Timestamp).Format("15:04:05"),
144+
"DATE": discord.TimestampToTime(msg.Timestamp).Format("15:04"),
128145
"CONTENT": content,
129146
"ATTACH_CONTENT": attachContent,
130147
"ID": msg.ID,
131148
"STICKER_CONTENT": stickerContent,
149+
"GIFS": gifContents,
132150
})
133151
}
134152
}

components/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Theme struct {
1616
START_DM,
1717
REPLY,
1818
STICKER,
19+
GIF,
1920
IMG string
2021
DownloadMedia bool
2122
}

discord/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Embed struct {
1616
Description string
1717
Color string
1818
Thumbnail EmbedImageThumbnail
19+
GifContentUrl string
1920
}
2021

2122
type EmbedVideo struct {

discord/unmarshler.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,17 @@ func (embed *Embed) UnmarshalJSON(b []byte) error {
154154
switch key {
155155
case "type":
156156
case "url":
157-
if embed.Type == EMBED_GIF {
158-
continue
159-
}
160157

161158
parsed := ""
162159

163160
err = json.Unmarshal(value, &parsed)
164161
tools.PanicIfErr(err)
165-
166-
embed.Url = parsed
162+
163+
if embed.Type == EMBED_GIF {
164+
embed.GifContentUrl = parsed
165+
} else {
166+
embed.Url = parsed
167+
}
167168
case "title":
168169
parsed := ""
169170

@@ -191,9 +192,6 @@ func (embed *Embed) UnmarshalJSON(b []byte) error {
191192

192193
embed.Url = parsed.Url
193194
case "thumbnail":
194-
if embed.Type != EMBED_IMAGE {
195-
continue
196-
}
197195
parsed := EmbedImageThumbnail{}
198196

199197
err = json.Unmarshal(value, &parsed)

fetcher/main.go

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func (conf ConfigType) FetchMain() {
4040
conf.checkToken()
4141

4242
ParsedMessages := map[string]JSONMetaData{}
43-
NumLeft := conf.Filter.NumMax
4443

4544
maxTime := conf.Filter.MaxTime
4645
minTime := conf.Filter.MinTime
@@ -150,21 +149,27 @@ func (conf ConfigType) FetchMain() {
150149
}
151150
}
152151

153-
if maxTime > maxMsg.Timestamp && maxMsg.Timestamp != 0 {
152+
if (maxTime > maxMsg.Timestamp && maxMsg.Timestamp != 0) || (maxTime == 0 && maxMsg.Timestamp != 0) {
154153
maxTime = maxMsg.Timestamp
155154
}
156155

157-
if minTime < minMsg.Timestamp {
156+
if (minTime < minMsg.Timestamp && maxMsg.Timestamp != 0 )|| (minTime == 0 && minMsg.Timestamp != 0) {
158157
minTime = minMsg.Timestamp
159158
}
160159

160+
if maxTime == 0 {
161+
maxTime = 9999999999999999
162+
}
163+
161164
for _, channel := range conf.Ids {
162-
NumLeft = conf.Filter.NumMax
165+
NumLeft := conf.Filter.NumMax
163166

164167
outputDir := tools.ParseTemplate(conf.ExportLocation, map[string]string{
165168
"CHANNEL_ID": channel,
166169
})
167170

171+
os.RemoveAll(outputDir)
172+
168173
os.Mkdir(outputDir, 0755)
169174

170175
mediaDir := ""
@@ -255,26 +260,24 @@ func (conf ConfigType) FetchMain() {
255260
} // TODO: Add other channel types
256261
}
257262

263+
lastID := fmt.Sprint(discord.TimestampToID(minTime))
264+
265+
if len(lastID) == 0 {
266+
lastID = "0"
267+
}
268+
258269
prevMsg := discord.Message{}
259270

260271
for {
261272
fin := false
262-
263-
msgQSuffix := "&after=" + prevMsg.ID
264-
if len(prevMsg.ID) == 0 {
265-
if minTime != 0 {
266-
msgQSuffix += discord.TimestampToID(maxTime)
267-
} else {
268-
msgQSuffix = ""
269-
}
270-
}
271-
272273
resp := []byte{}
273-
err := conf.discordFetch(fmt.Sprintf("/channels/%v/messages?limit=%v%v", channel, limit, msgQSuffix), &resp)
274+
msgUrl := fmt.Sprintf("/channels/%v/messages?limit=%v&after=%v", channel, limit, lastID)
275+
fmt.Println(msgUrl)
276+
err := conf.discordFetch(msgUrl, &resp)
274277
tools.PanicIfErr(err)
275278
allMsgs := []discord.Message{}
276279
json.Unmarshal(resp, &allMsgs)
277-
280+
278281
if len(allMsgs) != limit {
279282
fin = true // don't break because you still need proccessing
280283
}
@@ -284,11 +287,20 @@ func (conf ConfigType) FetchMain() {
284287
allMsgs[i], allMsgs[j] = allMsgs[j], allMsgs[i]
285288
}
286289

290+
lastID = allMsgs[len(allMsgs)-1].ID
291+
287292
for _, msg := range allMsgs {
288293
if NumLeft == 0 {
294+
fin = true
289295
break
290296
}
291297

298+
if msg.Timestamp > maxTime {
299+
break
300+
}
301+
302+
// fmt.Println(msg.Content)
303+
292304
for _, embed := range msg.Embeds {
293305
if embed.Type == discord.EMBED_IMAGE {
294306
msg.Attachments = append(msg.Attachments, discord.Attachment{
@@ -342,16 +354,10 @@ func (conf ConfigType) FetchMain() {
342354
case config.EXPORT_TYPE_HTML:
343355
msgTimestamp := discord.TimestampToTime(msg.Timestamp)
344356
sameDate := tools.SameDate(msgTimestamp, discord.TimestampToTime(prevMsg.Timestamp))
345-
346357
if !sameDate {
347358
file.WriteString(theme.DateSeperator(msgTimestamp))
348359
}
349-
350360
file.WriteString(theme.MessageComponent(msg, prevMsg, prevMsg.Author.ID != msg.Author.ID || !sameDate || msg.IsReply))
351-
352-
prevMsg = msg
353-
fin = true
354-
355361
case config.EXPORT_TYPE_JSON:
356362
newChanInfo := ParsedMessages[channel]
357363

@@ -364,15 +370,16 @@ func (conf ConfigType) FetchMain() {
364370
Attachment: attachRaw,
365371
AuthorID: msg.Author.ID,
366372
}
367-
373+
368374
newChanInfo.AttachList = append(newChanInfo.AttachList, attachment)
369375
newChanInfo.AttachIDToIndex[attachment.ID] = len(newChanInfo.AttachIDToIndex) - 1
370376
newChanInfo.AttachByAuthor[msg.Author.ID] = append(newChanInfo.AttachByAuthor[msg.Author.ID], attachment.ID)
371377
}
372-
378+
373379
ParsedMessages[channel] = newChanInfo
374380
}
375381

382+
prevMsg = msg
376383
NumLeft--
377384
}
378385

themes/base/components/gifs.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<video style="width: {{%WIDTH}}px; height: {{%HEIGHT}}px" autoplay muted loop>
2+
<source src="{{%VIDEO_URL}}" type="video/mp4">
3+
Update your browser, idiot!
4+
</video>

themes/base/components/msgStarter.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ <h3 class="msg-username sel">{{%USERNAME}}</h3>
99
</div>
1010
<p class="msg-content sel">{{%CONTENT}}</p>
1111
{{%ATTACH_CONTENT}}
12+
{{%GIFS}}
1213
{{%STICKER_CONTENT}}
1314
</div>
1415
</div>

themes/base/components/normalMsg.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<div class="msg-content-wrapper">
66
<p class="msg-content sel">{{%CONTENT}}</p>
77
{{%ATTACH_CONTENT}}
8+
{{%GIFS}}
89
{{%STICKER_CONTENT}}
910
</div>
1011
</div>

0 commit comments

Comments
 (0)