* hash_all.sh

#!/bin/bash

WORKDIR=$(pwd)
# Directories containing shared files
SHARED_DIRS=("${HOME}/.aMule/Incoming" "${HOME}/Downloads")

# Function to URL encode filenames
url_encode() {
  local string="$1"
  local strlen=${#string}
  local encoded=""
  local pos c o

  for (( pos=0 ; pos<strlen ; pos++ )); do
    c=${string:$pos:1}
    case "$c" in
      [a-zA-Z0-9.~_-]) o="$c" ;;
      *)               printf -v o '%%%02X' "'$c" ;;
    esac
    encoded+="$o"
  done
  echo "$encoded"
}

# Function to generate ed2k links for all files in a directory
generate_ed2k_links() {
  local dir="$1"
  cd "$dir" || exit

  for file in *; do
    if [ -f "$file" ]; then
	  # https://github.com/aMule-Project/aMule/archive/refs/tags/2.3.3.tar.gz
      ed2k_output=$(ed2k_hash "$file")
      file_size=$(stat -c%s "$file")
      ed2k_link=$(echo "$ed2k_output" | awk -F'|' '{print $5}')
      url_encoded_filename=$(url_encode "$file")
      echo "ed2k://|file|$url_encoded_filename|$file_size|$ed2k_link|/"
    fi
  done
}

# Iterate over each directory and generate ed2k links
for dir in "${SHARED_DIRS[@]}"; do
  generate_ed2k_links "$dir"
done

cd ${WORKDIR}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.

执行后的结果:

ed2k://|file|a_complete_handbook_of_tailoring_and_shop_management_1920.pdf|5509745|eb901e87afbe9135eb468453b8fc542d|/
ed2k://|file|Advanced_Platform_Development_with_Kubernetes_-_Enabling_Data_Management%2C_the_Internet_of_Things%2C_Blockchain%2C_and_Machine_Learning.pdf|9689069|7fe57fd59cf68277cbe7286c2304416a|/
ed2k://|file|Artificial%20Intelligence%20%282001%29%20-%20720x404%20Eng.mp4|709221728|09a895a1986e9d943ed5c4a0928307a9|/
ed2k://|file|Banking.On.Bitcoin.2016.ENG.SUB.ITA.720p.WEBRip.x264-Event.mkv|1764561465|141fbf85b20bf9f05de83ba941b0861e|/
  • 1.
  • 2.
  • 3.
  • 4.