* create_link.sh

#!/usr/bin/env sh

# Function to display usage
usage() {
  echo "Usage: $0 /path/to/file"
  exit 1
}

# Check if the path is provided as an argument
if [ "$#" -ne 1 ]; then
  usage
fi

path="$1"

# Check if the provided path is valid
if [ ! -f "$path" ]; then
  echo "Error: File '$path' not found."
  usage
fi

file=$(basename "$path")

# 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"
}

# Assume ed2k_hash is a command that generates the ed2k hash for the file
ed2k_output=$(ed2k_hash "$path")
file_size=$(stat -c%s "$path")
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|/"
  • 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_hash