Skip to content

Instantly share code, notes, and snippets.

@qls0ulp
Forked from lmarkus/README.MD
Created December 13, 2019 09:45
Show Gist options
  • Save qls0ulp/4f67bdc17be677e7b96841d23e14a52a to your computer and use it in GitHub Desktop.
Save qls0ulp/4f67bdc17be677e7b96841d23e14a52a to your computer and use it in GitHub Desktop.

Revisions

  1. Lenny Markus revised this gist Feb 2, 2019. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions download.sh
    Original file line number Diff line number Diff line change
    @@ -26,8 +26,6 @@ mkdir -p output;

    RAW_LIST=$(cat "${INPUT}" | tr ",{" "\\n" | sed -E 's/[\\"{}]//g')

    #echo "${RAW_LIST}"

    # Separate into Custom Emoji (Ignoring slack's default ones) and Aliases

    # Filter for custom emoji (ie: Anything on emoji.slack-edge.com), and remove the ":" separator
    @@ -36,8 +34,6 @@ EMOJI_LIST=$( echo "${RAW_LIST}" | grep "https://emoji.slack-edge.com" | sed 's/
    # Filter for the aliases, and remove the separator
    ALIAS_LIST=$( echo "${RAW_LIST}" | grep ":alias:" | sed 's/:alias:/ /' )

    #echo "${EMOJI_LIST}"


    # First download all the emoji
    echo "${EMOJI_LIST}" |
  2. Lenny Markus revised this gist Feb 2, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions README.MD
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,12 @@
    Slack doesn't provide an easy way to extract custom emoji from a team. (Especially teams with thousands of custom emoji)
    This Gist walks you through a relatively simple approach to get your emoji out.

    If you're an admin of your own team, you can get the list of emoji directly using this API: https://api.slack.com/methods/emoji.list. Once you have it, skip to Step 3

    **HOWEVER!** This gist is intended for people who don't have admin access, nor access tokens for using that list.

    Follow along...

    ## Step 1

    Open your Slack team **on your browser** (I used FireFox in this example)
  3. Lenny Markus revised this gist Feb 2, 2019. 3 changed files with 97 additions and 22 deletions.
    40 changes: 40 additions & 0 deletions README.MD
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # Extracting Emoji From Slack!

    Slack doesn't provide an easy way to extract custom emoji from a team. (Especially teams with thousands of custom emoji)
    This Gist walks you through a relatively simple approach to get your emoji out.

    ## Step 1

    Open your Slack team **on your browser** (I used FireFox in this example)

    Next, Open your developer tools, and go to the network tab. Look for a POST request on `/emoji.list`
    <img width="1074" alt="step1" src="https://user-images.githubusercontent.com/736932/52161452-d9e3e400-2679-11e9-9d4a-1c1bb317ab9a.png">

    ## Step 2

    Right Click on the request, and choose to open it in a new tab.
    <img width="429" alt="step2" src="https://user-images.githubusercontent.com/736932/52161454-e10af200-2679-11e9-9747-6b8b1b529f4e.png">

    This will cause the browser to replay the request, yielding a JSON file with all your emoji information.
    <img width="956" alt="step3" src="https://user-images.githubusercontent.com/736932/52161453-e10af200-2679-11e9-9c91-7dcaf6eb764f.png">

    Save this file somewhere as `emoji.json`

    ## Step 3

    Run download.sh on the file. (Make sure you `chmod +x` it to make it executable. Details on the `download.sh` file.

    ```bash
    ./download.sh emoji.json
    ```

    Sit back and wait. This will create a folder called `output` and will save all your emoji to it.

    ## Optional Step 4

    To bulk upload your emoji into a new team, use this chrome extension: https://chrome.google.com/webstore/detail/neutral-face-emoji-tools/anchoacphlfbdomdlomnbbfhcmcdmjej

    ## Notes

    1- This downloads files sequentially, one at a time. I didn't want to incurr Slack's rage by hammering their edge server with concurrent downloads.
    2- This will duplicate aliased emoji
    61 changes: 57 additions & 4 deletions download.sh
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,71 @@
    #!/usr/bin/env bash
    # Use:
    ######
    ## UPDATE for 2019: I completely changed my approach on how to obtain the emoji dump.
    ## The new approach results in a JSON file, so the processing is a bit diferent than
    ## with the previous version. This version will also take care of aliased emoji.

    # Use:
    # Make this file executable, and feed it the results from the Slack emoji URL dump. Files will be downloaded to `output`
    # chmod +x download.sh
    # ./download.sh emojiURLs.txt
    # ./download.sh emoji.json




    # Input File
    INPUT="$1"

    # Create output directory where downloaded emoji will be stored
    mkdir -p output;


    # Clean Up Source File:
    # Break up the file into individual lines for processing (Comma and { to NewLine)
    # Slack's emoji JSON brings an unwanted escape character "\". We need to remove it.
    # We'll also remove unwanted quote marks `"` and curly braces "{" "}"

    RAW_LIST=$(cat "${INPUT}" | tr ",{" "\\n" | sed -E 's/[\\"{}]//g')

    #echo "${RAW_LIST}"

    # Separate into Custom Emoji (Ignoring slack's default ones) and Aliases

    # Filter for custom emoji (ie: Anything on emoji.slack-edge.com), and remove the ":" separator
    EMOJI_LIST=$( echo "${RAW_LIST}" | grep "https://emoji.slack-edge.com" | sed 's/:https/ https/')

    # Filter for the aliases, and remove the separator
    ALIAS_LIST=$( echo "${RAW_LIST}" | grep ":alias:" | sed 's/:alias:/ /' )

    #echo "${EMOJI_LIST}"


    # First download all the emoji
    echo "${EMOJI_LIST}" |
    while read -r line || [[ -n "$line" ]]; do
    parts=($line)
    url=${parts[1]}
    name=${parts[0]}
    extension=${url##*.}

    echo "Downloading ${name}"
    echo "Downloading ${name}.${extension}"
    curl -s -o "output/${name}.${extension}" "${url}"

    done < "$1"
    done;

    # Now duplicate all the aliases
    echo "${ALIAS_LIST}" |
    while read -r line || [[ -n "$line" ]]; do
    parts=($line)
    alias=${parts[0]}
    source=${parts[1]}


    target=$(echo "${EMOJI_LIST}" | grep "${source} ")
    extension=${target##*.}


    echo "Looking for source of ${alias} in ${source} -> ${target}"
    echo "copying output/${source}.${extension} to output/${alias}.${extension}"
    cp "output/${source}.${extension}" "output/${alias}.${extension}"

    done;
    18 changes: 0 additions & 18 deletions extract.js
    Original file line number Diff line number Diff line change
    @@ -1,18 +0,0 @@
    // Login to your team through the browser. Run this on the browsers dev tools javascript console
    var url, name, emoji = [];

    $('#emoji_ul_slack span') // This is the emoji selector's Custom section.
    .each(function () {
    // Extract the name
    name = $(this)
    .html()
    .replace(/:/g, ''); // without the enclosing colons.

    // Extract the url from the background-image property.
    url = $(this)
    .css('background-image')
    .replace(/.*["'](.*)['"].*/, '$1'); // Remove the`url("` and `")` portions.

    // Dump to console, then copy and paste the results into a file (eg: emojiURLs.txt).
    console.log(name,url)
    });
  4. Lenny Markus revised this gist Dec 28, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion extract.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // Run this on the browsers dev console
    // Login to your team through the browser. Run this on the browsers dev tools javascript console
    var url, name, emoji = [];

    $('#emoji_ul_slack span') // This is the emoji selector's Custom section.
  5. Lenny Markus created this gist Dec 28, 2015.
    18 changes: 18 additions & 0 deletions download.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/usr/bin/env bash
    # Use:
    # Make this file executable, and feed it the results from the Slack emoji URL dump. Files will be downloaded to `output`
    # chmod +x download.sh
    # ./download.sh emojiURLs.txt

    mkdir -p output;

    while read -r line || [[ -n "$line" ]]; do
    parts=($line)
    url=${parts[1]}
    name=${parts[0]}
    extension=${url##*.}

    echo "Downloading ${name}"
    curl -s -o "output/${name}.${extension}" "${url}"

    done < "$1"
    18 changes: 18 additions & 0 deletions extract.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    // Run this on the browsers dev console
    var url, name, emoji = [];

    $('#emoji_ul_slack span') // This is the emoji selector's Custom section.
    .each(function () {
    // Extract the name
    name = $(this)
    .html()
    .replace(/:/g, ''); // without the enclosing colons.

    // Extract the url from the background-image property.
    url = $(this)
    .css('background-image')
    .replace(/.*["'](.*)['"].*/, '$1'); // Remove the`url("` and `")` portions.

    // Dump to console, then copy and paste the results into a file (eg: emojiURLs.txt).
    console.log(name,url)
    });