clearurl

Crates.ioclearurl
lib.rsclearurl
version0.7.1
sourcesrc
created_at2022-02-18 15:12:42.677624
updated_at2024-02-14 01:49:59.900388
descriptionA rust implementation for ClearURL
homepage
repositoryhttps://github.com/Avimitin/clearurl
max_upload_size
id534745
size24,366
Jiongjia Lu (Avimitin)

documentation

https://docs.rs/clearurl/

README

clearurl

This is a Rust implementation of the ClearURL lib.

Features

  • Declarative configuration
  • Full regexp support
  • 302 redirect support
  • Batch apply configuration for sub domains
  • Post hook for rewriting URL

Usage

  • Library
# Cargo.toml

clearurl = { version = "0.6", features = ["hooks"] }
use clearurl::URLCleaner;

#[tokio::main]
async fn main() {
  std::fs::write("rules.toml", r#"
["b23.tv"]
redirect = true

["bilibili.com"]
sub = ["www", "live", "m"]
ban = [
  "-Arouter",
  "bbid",
  "buvid",
  "callback",
  "from.*",
  "is_story_h5",
  "mid",
  "msource",
  "plat_id",
  "refer_from",
  "seid",
  "share.*",
  "spm_id.*",
  "timestamp",
  "ts",
  "unique_k",
  "up_id",
  "vd_source",
]
post_hooks = [ "bv_to_av" ]
  "#).unwrap();
  let cleaner = URLCleaner::from_file("./rules.toml").unwrap();

  let url = cleaner.clear("https://b23.tv/Cj2HC2K").await.unwrap();
  assert_eq!(
      url.as_str(),
      "https://www.bilibili.com/video/av746592874/?p=1"
  );
}
Commit count: 154

cargo fmt