Skip to content

LinuxUser255/url-sanitizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

url-sanitizer

sanitize-your-youtube-links-scaled-image.jpg


url-sanitizer is a Rust command-line tool designed to process and sanitize URLs, removing unwanted parameters or formatting them for safe use. This tool is lightweight, fast, and built for reliability.

Features

  • Redirect URL Detection: Automatically detects and follows redirect URLs from platforms like YouTube, Google, Facebook, and Twitter
  • Smart URL Extraction: Extracts the actual destination URL from redirect parameters (e.g., q, url, dest)
  • Tracking Parameter Removal: Removes common tracking parameters including:
    • UTM parameters (utm_source, utm_medium, utm_campaign, etc.)
    • Social media trackers (fbclid, gclid, msclkid)
    • Platform-specific trackers (si for YouTube, ref, source, etc.)
  • Recursive Processing: Handles nested redirects and sanitizes extracted URLs
  • Fast execution with Rust's performance
  • Portable, statically linked binary for easy distribution

Prerequisites - be Sure to have musl-tools

To build and install url-sanitizer on a Debian system, ensure the following are installed:

  • Rust and Cargo: The Rust toolchain.
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    source $HOME/.cargo/env
  • musl-tools: For static linking with the musl target.
    sudo apt update
    sudo apt install musl-tools
  • Git: To clone the repository (optional if you have the local codebase).
    sudo apt install git

Verify installations:

rustc --version && cargo --version && git --version

Building a Standalone Binary

Follow these steps to build a statically linked binary, which can run on any x86_64 Linux system without external library dependencies.

  1. Clone the repository:
 # http git clone
 git clone https://github.com/LinuxUser255/url-sanitizer.git

 cd url-sanitizer

  1. Add the musl Target:
    rustup target add x86_64-unknown-linux-musl

  1. Build the Static Binary: Compile in release mode for an optimized, standalone binary:
    cargo build --release --target x86_64-unknown-linux-musl
    The binary will be at target/x86_64-unknown-linux-musl/release/url-sanitizer.

  1. Verify Static Linking: Ensure the binary has no dynamic dependencies:
    ldd target/x86_64-unknown-linux-musl/release/url-sanitizer
    Expected output: statically linked or not a dynamic executable.

  1. Optional: Strip the Binary: Reduce binary size by removing debug symbols:
    strip target/x86_64-unknown-linux-musl/release/url-sanitizer

  1. Install Globally: Move the binary to /usr/local/bin for system-wide access:
    sudo mv target/x86_64-unknown-linux-musl/release/url-sanitizer /usr/local/bin/
    Verify it’s accessible:
    which url-sanitizer

  1. Test the Binary: Run the tool to ensure it works:
    url-sanitizer --help
    (Replace --help with appropriate arguments if your CLI requires them.)

Usage

~ url-sanitizer -h
Usage: url-sanitizer --url <URL>

Options:
  -u, --url <URL>
  -h, --help       Print help
  -V, --version    Print version

Examples:

Simple YouTube link with tracking:

url-sanitizer --url https://youtu.be/gW464nWLdAs\?si\=TAZ3qCA1503uB__t
Sanitized URL: https://youtu.be/gW464nWLdAs

Complex YouTube redirect:

url-sanitizer --url 'https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhq...&q=https%3A%2F%2Fopenart.ai%2Fhome%3Fref%3Daitanalopez&v=fxiDS2C9XYA'
# Output: https://openart.ai/home
# (Extracts the actual URL from the redirect and removes the 'ref' tracking parameter)

URL with UTM parameters:

url-sanitizer --url 'https://example.com/page?utm_source=newsletter&utm_medium=email&id=123'
# Output: https://example.com/page?id=123
# (Preserves the 'id' parameter while removing UTM tracking)

About

A CLI tool in Rust to sanitize your YouTube links. Removes user device tracking.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages