Skip to content

Commit

Permalink
Version 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDing committed Oct 14, 2024
1 parent 2494bd8 commit 58b1913
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 52 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
steps:
- uses: actions/checkout@v3

- if: contains(matrix.target, 'x86')
uses: ilammy/setup-nasm@v1

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
Expand All @@ -48,6 +51,18 @@ jobs:

- uses: Swatinem/rust-cache@v1

- name: Install dependencies for aws-lc-rs
shell: bash
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
echo 'LIBCLANG_PATH="C:\Program Files\LLVM\bin"' >> $GITHUB_ENV
echo 'AWS_LC_SYS_PREBUILT_NASM=1' >> $GITHUB_ENV
cargo install --force --locked bindgen-cli
elif [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
sudo apt-get install -y build-essential cmake golang libclang1 libclang-dev
cargo install --force --locked bindgen-cli
fi
- name: Build
if: matrix.target != 'aarch64-apple-darwin'
run: cargo build --verbose
Expand Down
58 changes: 39 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,46 +61,54 @@ jobs:
fail-fast: false
matrix:
include:
- build: linux
- build: linux-x86_64-musl
os: ubuntu-latest
rust: nightly
rust: stable
target: x86_64-unknown-linux-musl
strip: x86_64-linux-musl-strip
- build: stable-aarch64

- build: linux-x86_64-gnu
os: ubuntu-latest
rust: stable
target: aarch64-unknown-linux-gnu
strip: aarch64-linux-gnu-strip
qemu: qemu-aarch64
- build: stable-powerpc64
target: x86_64-unknown-linux-gnu
strip: strip

- build: stable-aarch64-musl
os: ubuntu-latest
rust: stable
target: powerpc64-unknown-linux-gnu
strip: powerpc64-linux-gnu-strip
qemu: qemu-ppc64
- build: stable-s390x
target: aarch64-unknown-linux-musl
strip: aarch64-linux-musl-strip
qemu: qemu-aarch64

- build: stable-aarch64-gnu
os: ubuntu-latest
rust: stable
target: s390x-unknown-linux-gnu
strip: s390x-linux-gnu-strip
qemu: qemu-s390x
target: aarch64-unknown-linux-gnu
strip: aarch64-linux-gnu-strip
qemu: qemu-aarch64

- build: macos
os: macos-latest
rust: nightly
rust: stable
target: x86_64-apple-darwin

- build: win-msvc
os: windows-latest
rust: nightly
rust: stable
target: x86_64-pc-windows-msvc

- build: win-gnu
os: windows-latest
rust: nightly-x86_64-gnu
rust: stable-x86_64-gnu
target: x86_64-pc-windows-gnu

steps:
- name: Checkout repository
uses: actions/checkout@v4

- if: contains(matrix.target, 'x86')
uses: ilammy/setup-nasm@v1

- name: Install packages (Ubuntu)
if: matrix.os == 'ubuntu-latest'
shell: bash
Expand Down Expand Up @@ -141,6 +149,18 @@ jobs:
echo "target flag is: ${{ env.TARGET_FLAGS }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Install dependencies for aws-lc-rs
shell: bash
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
echo 'LIBCLANG_PATH="C:\Program Files\LLVM\bin"' >> $GITHUB_ENV
echo 'AWS_LC_SYS_PREBUILT_NASM=1' >> $GITHUB_ENV
cargo install --force --locked bindgen-cli
elif [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
sudo apt-get install -y build-essential cmake golang libclang1 libclang-dev
cargo install --force --locked bindgen-cli
fi
- name: Build release binary
shell: bash
run: |
Expand Down Expand Up @@ -181,17 +201,17 @@ jobs:
cp {README.md,LICENSE-APACHE,LICENSE-MIT} "$ARCHIVE"/
- name: Build archive (Windows)
shell: bash
if: matrix.os == 'windows-latest'
shell: bash
run: |
7z a "$ARCHIVE.zip" "$ARCHIVE"
certutil -hashfile "$ARCHIVE.zip" SHA256 > "$ARCHIVE.zip.sha256"
echo "ASSET=$ARCHIVE.zip" >> $GITHUB_ENV
echo "ASSET_SUM=$ARCHIVE.zip.sha256" >> $GITHUB_ENV
- name: Build archive (Unix)
shell: bash
if: matrix.os != 'windows-latest'
shell: bash
run: |
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
shasum -a 256 "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
Expand Down
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aget-rs"
version = "0.5.1"
version = "0.6.0"
authors = ["PeterDing <[email protected]>"]
homepage = "https://github.com/PeterDing/aget-rs"
description="Aget-rs - Fast Asynchronous Downloader with Rust 🦀"
Expand Down Expand Up @@ -41,7 +41,6 @@ thiserror = "1.0"
# for crypto
aes = "0.8"
cbc = { version = "0.1", features = ["alloc", "block-padding"] }
md-5 = "0.10"

# utilities
term_size = "0.3"
Expand All @@ -57,7 +56,7 @@ dirs = "5.0"
m3u8-rs = "6"

# for torrent
librqbit = { git = "https://github.com/ikatson/rqbit.git", branch = "main" }
librqbit = { git = "https://github.com/ikatson/rqbit.git", branch = "main", features = ["rust-tls"], default-features = false }

# for tracing
tracing = "0.1"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Following is the results of using `curl` and `aget-rs`. (For more details, you c
- Download a torrent or magnet link
Warning: The `/path/to/outdir` directory below command must NOT exist. It will be created automatically.
```shell
ag "magnet:..." -o /path/to/outdir
ag "/path/to/torrent" -o /path/to/outdir
Expand Down
40 changes: 10 additions & 30 deletions src/app/core/bt.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::{path::PathBuf, sync::Arc, time::Duration};

use librqbit::{
api::TorrentIdOrHash, AddTorrent, AddTorrentOptions, AddTorrentResponse, Api, PeerConnectionOptions, Session,
SessionOptions, SessionPersistenceConfig,
api::TorrentIdOrHash, dht::PersistentDhtConfig, AddTorrent, AddTorrentOptions, AddTorrentResponse, Api,
PeerConnectionOptions, Session, SessionOptions, SessionPersistenceConfig,
};
use md5::Digest;
use url::Url;

use crate::{
Expand Down Expand Up @@ -34,37 +33,14 @@ impl BtHandler {
}
}

fn task_key(&self) -> Result<String> {
let torrent_or_magnet = &self.torrent_or_magnet;
if torrent_or_magnet.scheme() == "magnet" {
for (key, value) in torrent_or_magnet.query_pairs() {
match key.as_ref() {
"xt" => {
if let Some(ih) = value.as_ref().strip_prefix("urn:btih:") {
return Ok(ih.to_lowercase().to_string());
} else if let Some(ih) = value.as_ref().strip_prefix("urn:btmh:1220") {
return Ok(ih.to_lowercase().to_string());
} else {
}
}
_ => {}
}
}
return Err(Error::BitTorrentError("magnet link missing no info hash".to_string()));
} else {
let mut hasher = md5::Md5::new();
hasher.update(torrent_or_magnet.as_str());
let hash = hasher.finalize();
Ok(format!("{:x}", hash).to_lowercase())
}
}

async fn start(self) -> Result<()> {
tracing::debug!("BtHandler::start");

let output_dir = &self.output;
let task_key = self.task_key()?;
let persistence_dir = output_dir.join(task_key + ".bt.aget");
let persistence_dir = output_dir
.join("..")
.join(output_dir.file_name().unwrap().to_string_lossy().to_string() + ".bt.aget");
let dht_config_filename = persistence_dir.join("dht.json");

// 0. Check whether task is completed
tracing::debug!("BtHandler: check whether task is completed");
Expand All @@ -77,6 +53,10 @@ impl BtHandler {
let sopts = SessionOptions {
disable_dht: false,
disable_dht_persistence: false,
dht_config: Some(PersistentDhtConfig {
config_filename: Some(dht_config_filename),
..Default::default()
}),
peer_id: None,
peer_opts: Some(PeerConnectionOptions {
connect_timeout: Some(Duration::from_secs(10)),
Expand Down

0 comments on commit 58b1913

Please sign in to comment.