Last active
June 28, 2023 22:04
-
-
Save jchristgit/7f0082880cf12590cf0d11b9716afd14 to your computer and use it in GitHub Desktop.
Download all attachments from a Discord data export via Python, awk & wget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The above can be used to download all your attachments out of a Discord data export. | |
Attachments are downloaded one by one, and placed alongside the channels they were sent in. | |
The attachment filename is the message ID and the attachment filename, joined by an underscore. | |
It is safe to re-run the download script should it have been aborted, | |
though if aborted in the middle of a download that file may only be partial. | |
The script makes no attempt to re-download files that are already downloaded. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for dir in c*; do | |
mkdir -p "$dir/attachments" | |
for url in $(python3 print_attachment_urls.py < "$dir/messages.csv"); do | |
oname="$dir/attachments/$(echo "$url" | awk -F '/' '{ print $6 "_" $7 }')" | |
if [ ! -e "$oname" ]; then | |
wget -nv --user-agent="" "$url" -O "$oname" | |
fi | |
done | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import sys | |
for row in csv.reader(sys.stdin, delimiter=','): | |
if row[-1] and row[-1] != 'Attachments': | |
for url in row[-1].split(): | |
print(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment