Skip to content

Instantly share code, notes, and snippets.

@rdar-lab
Forked from greird/slack-files-downloader.sh
Last active August 10, 2024 15:21
Show Gist options
  • Select an option

  • Save rdar-lab/ace9b579781e498b21a5011d42a65adc to your computer and use it in GitHub Desktop.

Select an option

Save rdar-lab/ace9b579781e498b21a5011d42a65adc to your computer and use it in GitHub Desktop.
Download all files from a Slack workspace export folder.
echo "What file type do you want to export ? (e.g. mp3, binary, mp4)"
echo "Leave empty for any."
read usertype
echo "Channel to look into (leave empty for all):"
read userchannel
for channel in $(cat channels.json | jq -rc '.[].name')
do
if [[ $channel == $userchannel ]] || [[ -z $userchannel ]]
then
echo ""
echo "============================================"
echo "Looking into #$channel..."
echo "============================================"
for file in "$channel"/*.json
do
for a in $(cat $file | jq -c '.[].files[0] | [.title, .url_private_download, .filetype] | del(..|nulls)' | sed 's/ //g')
do
filetype=$(echo $a | jq -r '.[2]')
if [[ $filetype == $usertype ]] || [[ -z $usertype ]] || [[ -z $filetype ]]
then
filename=$(echo $a | jq -r '.[0]')
if [[ ! -z $filename ]] && [ ! -f "export/$channel/$filename" ]
then
echo "Downloading $filename..."
mkdir -p export/$channel
filename=$(echo $filename | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
filename=$(echo $filename | sed 's/ //g')
url=$(echo $a | jq -rc '.[1]')
curl -s $url -o "export/$channel/$filename"
fi
fi
done
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment