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.

Revisions

  1. rdar-lab revised this gist Aug 10, 2024. 1 changed file with 33 additions and 26 deletions.
    59 changes: 33 additions & 26 deletions slack-files-downloader.sh
    Original file line number Diff line number Diff line change
    @@ -42,38 +42,45 @@ do
    then
    printf "\n============================================\nLooking into $channel...\n============================================\n"

    for file in "$channel"/*.json
    for message in "$channel"/*.json
    do
    for a in $(cat $file | jq -c '.[].files[0] | [.id, .name, .url_private_download] | del(..|nulls)' | sed 's/ //g')
    do
    if [[ $a != [] ]]
    files=$(cat $message | jq -c '.[].files | del(..|nulls)' | sed 's/ //g')
    for file_entry in $files
    do
    if [[ $file_entry != "null" ]]
    then
    file_id=$(echo $a | jq -r '.[0]')
    file_title=$(echo $a | jq -r '.[1]')
    url=$(echo $a | jq -rc '.[2]')

    if [[ $url != "null" ]]
    then
    filename_raw="${file_id}_${file_title}"

    filename=$(echo $filename_raw | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
    filename="${filename##*/}"

    if [ -f "files/$channel/$filename" ] && [[ $overwrite != true ]]
    for file in $(echo $file_entry | jq -c '.[] | [.id, .name, .url_private_download] | del(..|nulls)' | sed 's/ //g')
    do
    if [[ $file != [] ]]
    then
    if [[ $silent != true ]]
    file_id=$(echo $file | jq -r '.[0]')
    file_title=$(echo $file | jq -r '.[1]')
    url=$(echo $file | jq -rc '.[2]')

    if [[ $url != "null" ]]
    then
    printf "$filename already exists in destination folder. ignoring it!\n"
    filename_raw="${file_id}_${file_title}"

    filename=$(echo $filename_raw | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
    filename="${filename##*/}"

    if [ -f "files/$channel/$filename" ] && [[ $overwrite != true ]]
    then
    if [[ $silent != true ]]
    then
    printf "$filename already exists in destination folder. ignoring it!\n"
    fi
    continue
    fi

    printf "Downloading $filename... from URL $url\n"

    mkdir -p files/$channel

    curl --progress-bar $url -o "files/$channel/$filename"
    fi
    continue
    fi

    printf "Downloading $filename... from URL $url\n"

    mkdir -p files/$channel

    curl --progress-bar $url -o "files/$channel/$filename"
    fi
    done
    fi
    done
    done
  2. rdar-lab revised this gist Aug 10, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion slack-files-downloader.sh
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ do

    for file in "$channel"/*.json
    do
    for a in $(cat $file | jq -c '.[].files[0] | [.id, .title, .url_private_download] | del(..|nulls)' | sed 's/ //g')
    for a in $(cat $file | jq -c '.[].files[0] | [.id, .name, .url_private_download] | del(..|nulls)' | sed 's/ //g')
    do
    if [[ $a != [] ]]
    then
  3. rdar-lab revised this gist Aug 10, 2024. 1 changed file with 17 additions and 25 deletions.
    42 changes: 17 additions & 25 deletions slack-files-downloader.sh
    Original file line number Diff line number Diff line change
    @@ -25,9 +25,6 @@ done
    echo Override=$overwrite
    echo Silent=$silent

    # printf "\nSelect one specific file type to download or leave empty for any (e.g. mp3, binary, jpg, png):\n"
    # read usertype

    # printf "\nSelect a channel to look into or leave empty for all channels:\n"
    # read userchannel

    @@ -47,40 +44,35 @@ do

    for file in "$channel"/*.json
    do
    for a in $(cat $file | jq -c '.[].files[0] | [.id, .title, .url_private_download, .filetype] | del(..|nulls)' | sed 's/ //g')
    for a in $(cat $file | jq -c '.[].files[0] | [.id, .title, .url_private_download] | del(..|nulls)' | sed 's/ //g')
    do
    if [[ $a != [] ]]
    then
    file_id=$(echo $a | jq -r '.[0]')
    file_title=$(echo $a | jq -r '.[1]')
    url=$(echo $a | jq -rc '.[2]')
    filetype=$(echo $a | jq -r '.[3]')


    if [[ $url != "null" ]]
    then

    if [[ $filetype == $usertype ]] || [[ -z $usertype ]] || [[ -z $filetype ]]
    filename_raw="${file_id}_${file_title}"

    filename=$(echo $filename_raw | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
    filename="${filename##*/}"

    if [ -f "files/$channel/$filename" ] && [[ $overwrite != true ]]
    then
    filename_raw="${file_id}_${file_title}"

    filename=$(echo $filename_raw | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
    filename="${filename##*/}"

    if [ -f "files/$channel/$filename" ] && [[ $overwrite != true ]]
    if [[ $silent != true ]]
    then
    if [[ $silent != true ]]
    then
    printf "$filename already exists in destination folder. ignoring it!\n"
    fi
    continue
    printf "$filename already exists in destination folder. ignoring it!\n"
    fi

    printf "Downloading $filename... from URL $url\n"

    mkdir -p files/$channel

    curl --progress-bar $url -o "files/$channel/$filename"
    continue
    fi

    printf "Downloading $filename... from URL $url\n"

    mkdir -p files/$channel

    curl --progress-bar $url -o "files/$channel/$filename"
    fi
    fi
    done
  4. rdar-lab revised this gist Aug 10, 2024. 1 changed file with 30 additions and 21 deletions.
    51 changes: 30 additions & 21 deletions slack-files-downloader.sh
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,9 @@
    # HOW TO:
    # 1. As a Workspace admin, download an export of your Slack history (https://www.slack.com/services/export)
    # 2. Make sure you have jq installed (https://stedolan.github.io/jq/)
    # 3. Place this file at the root of your Slack export folder
    # 4. Run `bash slack-files-downloader.sh > download.log` in your terminal
    # 3. Make sure you have curl installed
    # 4. Place this file at the root of your Slack export folder
    # 5. Run `bash slack-files-downloader.sh > download.log` in your terminal
    #
    # OPTIONS
    # -o Overwrite files if they already exist in destination folder, otherwise skip them.
    @@ -30,7 +31,10 @@ echo Silent=$silent
    # printf "\nSelect a channel to look into or leave empty for all channels:\n"
    # read userchannel

    # This is only public channels
    #channels=$(cat channels.json | jq -rc '.[].name')

    # This is to use all subdirectories instead
    channels=$(find . -maxdepth 1 -type d ! -name "files" -printf "%P\n")

    echo Scanning: $channels
    @@ -47,31 +51,36 @@ do
    do
    if [[ $a != [] ]]
    then
    file_id=$(echo $a | jq -r '.[0]')
    file_title=$(echo $a | jq -r '.[1]')
    url=$(echo $a | jq -rc '.[2]')
    filetype=$(echo $a | jq -r '.[3]')

    if [[ $filetype == $usertype ]] || [[ -z $usertype ]] || [[ -z $filetype ]]
    if [[ $url != "null" ]]
    then
    filename_raw="$(echo $a | jq -r '.[0]')_$(echo $a | jq -r '.[1]')"

    filename=$(echo $filename_raw | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
    filename="${filename##*/}"

    if [ -f "files/$channel/$filename" ] && [[ $overwrite != true ]]

    if [[ $filetype == $usertype ]] || [[ -z $usertype ]] || [[ -z $filetype ]]
    then
    if [[ $silent != true ]]
    filename_raw="${file_id}_${file_title}"

    filename=$(echo $filename_raw | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
    filename="${filename##*/}"

    if [ -f "files/$channel/$filename" ] && [[ $overwrite != true ]]
    then
    printf "$filename already exists in destination folder. ignoring it!\n"
    if [[ $silent != true ]]
    then
    printf "$filename already exists in destination folder. ignoring it!\n"
    fi
    continue
    fi
    continue
    fi

    printf "Downloading $filename...\n"

    mkdir -p files/$channel

    url=$(echo $a | jq -rc '.[2]')

    curl --progress-bar $url -o "files/$channel/$filename"
    printf "Downloading $filename... from URL $url\n"

    mkdir -p files/$channel

    curl --progress-bar $url -o "files/$channel/$filename"
    fi
    fi
    fi
    done
  5. rdar-lab revised this gist Aug 10, 2024. 1 changed file with 24 additions and 38 deletions.
    62 changes: 24 additions & 38 deletions slack-files-downloader.sh
    Original file line number Diff line number Diff line change
    @@ -1,76 +1,62 @@
    #!/bin/bash
    #
    # This script will browse a Slack export folder and download all files in a new /export folder
    # This script will browse a Slack export folder and download all files in a new /files folder
    #
    # HOW TO:
    # 1. As a Workspace admin, download an export of your Slack history (https://www.slack.com/services/export)
    # 2. Make sure you have jq installed (https://stedolan.github.io/jq/)
    # 3. Place this file at the root of your Slack export folder, next to channels.json
    # 4. Run `bash slack-files-downloader.sh` in your terminal
    # 3. Place this file at the root of your Slack export folder
    # 4. Run `bash slack-files-downloader.sh > download.log` in your terminal
    #
    # OPTIONS
    # -o Overwrite files if they already exist in destination folder, otherwise skip them.
    # -r Random filename in case it exists
    # -s Do not show message when a file is skipped


    while getopts "osr" flag
    while getopts "os" flag
    do
    case $flag in
    o) overwrite=true;;
    s) silent=true;;
    r) random=true;;
    esac
    done

    echo Override=$overwrite
    echo Silent=$silent
    echo Random=$random

    printf "\nSelect one specific file type to download or leave empty for any (e.g. mp3, binary, jpg, png):\n"
    read usertype
    # printf "\nSelect one specific file type to download or leave empty for any (e.g. mp3, binary, jpg, png):\n"
    # read usertype

    printf "\nSelect a channel to look into or leave empty for all channels:\n"
    read userchannel
    # printf "\nSelect a channel to look into or leave empty for all channels:\n"
    # read userchannel

    #channels=$(cat channels.json | jq -rc '.[].name')
    channels=$(find . -maxdepth 1 -type d ! -name "export" -printf "%P\n")
    channels=$(find . -maxdepth 1 -type d ! -name "files" -printf "%P\n")

    echo Scanning: $channels

    for channel in $channels
    do
    if [[ $channel == $userchannel ]] || [[ -z $userchannel ]]
    then
    printf "\n============================================\nLooking into #$channel...\n============================================\n"
    printf "\n============================================\nLooking into $channel...\n============================================\n"

    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 ]]
    for a in $(cat $file | jq -c '.[].files[0] | [.id, .title, .url_private_download, .filetype] | del(..|nulls)' | sed 's/ //g')
    do
    if [[ $a != [] ]]
    then
    filename_raw=$(echo $a | jq -r '.[0]')

    filename=$(echo $filename_raw | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
    filename="${filename##*/}"

    if [[ ! -z $filename_raw ]] && [[ $filename_raw != "null" ]]
    filetype=$(echo $a | jq -r '.[3]')

    if [[ $filetype == $usertype ]] || [[ -z $usertype ]] || [[ -z $filetype ]]
    then
    filename_raw="$(echo $a | jq -r '.[0]')_$(echo $a | jq -r '.[1]')"

    if [ -f "export/$channel/$filename" ] && [[ $random == true ]]
    then
    if [[ $silent != true ]]
    then
    printf "$filename already exists in destination folder. renaming it!\n"
    fi
    prefix=$(printf "%04d" $((RANDOM % 10000)))
    filename="${prefix}_${filename}"
    fi

    if [ -f "export/$channel/$filename" ] && [[ $overwrite != true ]]
    filename=$(echo $filename_raw | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
    filename="${filename##*/}"

    if [ -f "files/$channel/$filename" ] && [[ $overwrite != true ]]
    then
    if [[ $silent != true ]]
    then
    @@ -81,11 +67,11 @@ do

    printf "Downloading $filename...\n"

    mkdir -p export/$channel
    mkdir -p files/$channel

    url=$(echo $a | jq -rc '.[1]')
    url=$(echo $a | jq -rc '.[2]')

    curl --progress-bar $url -o "export/$channel/$filename"
    curl --progress-bar $url -o "files/$channel/$filename"
    fi
    fi
    done
  6. rdar-lab revised this gist Aug 10, 2024. 1 changed file with 24 additions and 3 deletions.
    27 changes: 24 additions & 3 deletions slack-files-downloader.sh
    Original file line number Diff line number Diff line change
    @@ -10,24 +10,35 @@
    #
    # OPTIONS
    # -o Overwrite files if they already exist in destination folder, otherwise skip them.
    # -r Random filename in case it exists
    # -s Do not show message when a file is skipped


    while getopts "os" flag
    while getopts "osr" flag
    do
    case $flag in
    o) overwrite=true;;
    s) silent=true;;
    r) random=true;;
    esac
    done

    echo Override=$overwrite
    echo Silent=$silent
    echo Random=$random

    printf "\nSelect one specific file type to download or leave empty for any (e.g. mp3, binary, jpg, png):\n"
    read usertype

    printf "\nSelect a channel to look into or leave empty for all channels:\n"
    read userchannel

    for channel in $(cat channels.json | jq -rc '.[].name')
    #channels=$(cat channels.json | jq -rc '.[].name')
    channels=$(find . -maxdepth 1 -type d ! -name "export" -printf "%P\n")

    echo Scanning: $channels

    for channel in $channels
    do
    if [[ $channel == $userchannel ]] || [[ -z $userchannel ]]
    then
    @@ -49,11 +60,21 @@ do
    if [[ ! -z $filename_raw ]] && [[ $filename_raw != "null" ]]
    then

    if [ -f "export/$channel/$filename" ] && [[ $random == true ]]
    then
    if [[ $silent != true ]]
    then
    printf "$filename already exists in destination folder. renaming it!\n"
    fi
    prefix=$(printf "%04d" $((RANDOM % 10000)))
    filename="${prefix}_${filename}"
    fi

    if [ -f "export/$channel/$filename" ] && [[ $overwrite != true ]]
    then
    if [[ $silent != true ]]
    then
    printf "$filename already exists in destination folder. Skipping!\n"
    printf "$filename already exists in destination folder. ignoring it!\n"
    fi
    continue
    fi
  7. @greird greird revised this gist Feb 20, 2023. No changes.
  8. @greird greird revised this gist Nov 16, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions slack-files-downloader.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    #!/bin/bash
    #
    # This script will browse a Slack export folder and download all files in a new /export folder
    #
    # HOW TO:
  9. @greird greird revised this gist Nov 16, 2022. 1 changed file with 18 additions and 2 deletions.
    20 changes: 18 additions & 2 deletions slack-files-downloader.sh
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,24 @@
    # This script will browse a Slack export folder and download all files in a new /export folder
    #
    # HOW TO:
    # 1. As a Workspace admin, download an export of your Slack history (https://www.slack.com/services/export)
    # 2. Make sure you have jq installed (https://stedolan.github.io/jq/)
    # 3. Place this file at the root of your Slack export folder, next to channels.json
    # 4. Run `bash slack-files-downloader.sh` in your terminal
    #
    # OPTIONS
    # -o Overwrite files if they already exist in destination folder, otherwise skip them.
    # -s Do not show message when a file is skipped


    while getopts "os" flag
    do
    case $flag in
    o) overwrite=true;;
    s) silent=true;;
    esac
    done

    printf "\nSelect one specific file type to download or leave empty for any (e.g. mp3, binary, jpg, png):\n"
    read usertype

    @@ -34,9 +47,12 @@ do
    if [[ ! -z $filename_raw ]] && [[ $filename_raw != "null" ]]
    then

    if [ -f "export/$channel/$filename" ]
    if [ -f "export/$channel/$filename" ] && [[ $overwrite != true ]]
    then
    printf "Skipping $filename. It already exists in destination folder.\n"
    if [[ $silent != true ]]
    then
    printf "$filename already exists in destination folder. Skipping!\n"
    fi
    continue
    fi

  10. @greird greird revised this gist Nov 16, 2022. No changes.
  11. @greird greird revised this gist Nov 16, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion slack-files-downloader.sh
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@
    # 3. Place this file at the root of your Slack export folder, next to channels.json
    # 4. Run `bash slack-files-downloader.sh` in your terminal


    printf "\nSelect one specific file type to download or leave empty for any (e.g. mp3, binary, jpg, png):\n"
    read usertype

    @@ -28,7 +29,7 @@ do
    filename_raw=$(echo $a | jq -r '.[0]')

    filename=$(echo $filename_raw | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
    filename=$(echo $filename | sed 's/ //g')
    filename="${filename##*/}"

    if [[ ! -z $filename_raw ]] && [[ $filename_raw != "null" ]]
    then
  12. @greird greird revised this gist Nov 16, 2022. 2 changed files with 54 additions and 43 deletions.
    43 changes: 0 additions & 43 deletions slack-files-download.sh
    Original file line number Diff line number Diff line change
    @@ -1,43 +0,0 @@
    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
    54 changes: 54 additions & 0 deletions slack-files-downloader.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    # This script will browse a Slack export folder and download all files in a new /export folder
    # HOW TO:
    # 1. As a Workspace admin, download an export of your Slack history (https://www.slack.com/services/export)
    # 2. Make sure you have jq installed (https://stedolan.github.io/jq/)
    # 3. Place this file at the root of your Slack export folder, next to channels.json
    # 4. Run `bash slack-files-downloader.sh` in your terminal

    printf "\nSelect one specific file type to download or leave empty for any (e.g. mp3, binary, jpg, png):\n"
    read usertype

    printf "\nSelect a channel to look into or leave empty for all channels:\n"
    read userchannel

    for channel in $(cat channels.json | jq -rc '.[].name')
    do
    if [[ $channel == $userchannel ]] || [[ -z $userchannel ]]
    then
    printf "\n============================================\nLooking into #$channel...\n============================================\n"

    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_raw=$(echo $a | jq -r '.[0]')

    filename=$(echo $filename_raw | sed -e 'y/āáǎàçēéěèīíǐìōóǒòūúǔùǖǘǚǜüĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛÜ/aaaaceeeeiiiioooouuuuuuuuuAAAAEEEEIIIIOOOOUUUUUUUUU/')
    filename=$(echo $filename | sed 's/ //g')

    if [[ ! -z $filename_raw ]] && [[ $filename_raw != "null" ]]
    then

    if [ -f "export/$channel/$filename" ]
    then
    printf "Skipping $filename. It already exists in destination folder.\n"
    continue
    fi

    printf "Downloading $filename...\n"

    mkdir -p export/$channel

    url=$(echo $a | jq -rc '.[1]')

    curl --progress-bar $url -o "export/$channel/$filename"
    fi
    fi
    done
    done
    fi
    done
  13. @greird greird created this gist Nov 15, 2022.
    43 changes: 43 additions & 0 deletions slack-files-download.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    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