Skip to content

Instantly share code, notes, and snippets.

@jchristgit
Last active June 28, 2023 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristgit/7f0082880cf12590cf0d11b9716afd14 to your computer and use it in GitHub Desktop.
Save jchristgit/7f0082880cf12590cf0d11b9716afd14 to your computer and use it in GitHub Desktop.
Download all attachments from a Discord data export via Python, awk & wget
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.
#!/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
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