Skip to content

Commit

Permalink
Merge pull request #12 from Stridsvagn69420/standalone-downloader
Browse files Browse the repository at this point in the history
Standalone downloader
  • Loading branch information
Stridsvagn69420 authored May 18, 2024
2 parents 9f53895 + 268f725 commit afa73b1
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 971 deletions.
323 changes: 74 additions & 249 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wallpaper-dl"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
license = "EUPL-1.2"
readme = "README.md"
Expand All @@ -15,12 +15,9 @@ publish = true
[dependencies]
apputils = "0.1"
url = "2.5"
toml = "0.8"
serde = { version = "1.0", features = ["derive"] }
reqwest = { version = "0.12", features = ["blocking", "rustls-tls-native-roots", "deflate", "gzip", "brotli", "json", "charset", "multipart"], default-features = false }
reqwest = { version = "0.12", features = ["blocking", "rustls-tls-native-roots", "deflate", "gzip", "brotli", "json", "charset"], default-features = false }
scraper = "0.19"
blake3 = { version = "1.5", features = ["serde", "neon"] }
mailparse = "0.14"

[profile.release]
strip = true
Expand Down
21 changes: 3 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,13 @@ Wallpaper downloader for various websites
- Alphacoders ([Wallpaper Abyss](https://wall.alphacoders.com/), [Art Abyss](https://art.alphacoders.com/), [Image Abyss](https://pics.alphacoders.com/))
- [ArtStation](https://www.artstation.com/)

Note: Alphacoder's Abyss websites tend to block the downloader, so it does not work all the time.

## Usage
Downloading wallpapers:
```bash
wallpaper-dl <URLs>
```

Setting the current wallpaper:
```bash
wallpaper-dl current <URL/Path>
```

Getting the current wallpaper path:
```bash
wallpaper-dl current
```

## Contributing
Want to add a feature, enhance website support or report a bug? Just open a new issue on [GitHub][github]!

#### Ideas for version 0.2.0
It's a hobby project of mine, so I can't just work on it 24/7, but here are some things that I want to implement:
- Removing missing files from database
- Tokio multithreaded and async/await
- Buffered IO for downloading (requires async due to streams)
- [indicatif](https://github.com/console-rs/indicatif) for cleaner status output
Want to add a feature, enhance website support or report a bug? Just open a new issue on [GitHub][github]!
135 changes: 0 additions & 135 deletions src/config.rs

This file was deleted.

36 changes: 8 additions & 28 deletions src/downloaders/alphacoders.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{quick_get, Downloader, DownloaderError, DownloaderResult, ScraperWrapper, SelectAttr, Urls};
use reqwest::blocking::Client;
use scraper::{Html, Selector};
use scraper::Html;
use url::Url;

/// Alphacoders Core
Expand All @@ -25,12 +25,11 @@ impl Alphacoders {
fn new(
client: &Client,
url: Url,
delay: u64,
id: String,
service_css: &str,
title_css: &str
) -> DownloaderResult<Self> {
let html = quick_get(client, url, delay)?.text()?;
let html = quick_get(client, url)?.text()?;
let download_css = format!("a#{}_{}_download_button", service_css, id);
let download = SelectAttr::parse(&download_css, "href")?;
Ok(Self {
Expand All @@ -51,16 +50,6 @@ impl Alphacoders {
fn image_title(&self) -> DownloaderResult<String> {
ScraperWrapper::image_title(&self.html, &self.title)
}

/// Image Tags wrapper
///
/// Image tags are the inner text of A-Tags inside a Div with class "well".
fn image_tags(&self) -> DownloaderResult<Vec<String>> {
Ok(self.html.select(&Selector::parse("div.well a")?)
.flat_map(|x| x.text())
.map(|y| y.trim().to_string())
.collect())
}
}

/// Wallpaper Abyss
Expand All @@ -69,12 +58,12 @@ impl Alphacoders {
pub struct WallpaperAbyss(Alphacoders);

impl Downloader for WallpaperAbyss {
fn new(client: &Client, url: Url, delay: u64) -> DownloaderResult<Self> {
fn new(client: &Client, url: Url) -> DownloaderResult<Self> {
let id = match url.query() {
Some(x) => x.replace("i=", ""),
None => return Err(DownloaderError::ParseError("URL Query did not match pattern".to_string()))
};
let inner = Alphacoders::new(client, url, delay, id, "wallpaper", "img#main-content")?;
let inner = Alphacoders::new(client, url, id, "wallpaper", "img#main-content")?;
Ok(Self(inner))
}

Expand All @@ -87,9 +76,6 @@ impl Downloader for WallpaperAbyss {
fn image_title(&self) -> DownloaderResult<String> {
self.0.image_title()
}
fn image_tags(&self) -> DownloaderResult<Vec<String>> {
self.0.image_tags()
}
}

/// Art Abyss
Expand All @@ -98,9 +84,9 @@ impl Downloader for WallpaperAbyss {
pub struct ArtAbyss(Alphacoders);

impl Downloader for ArtAbyss {
fn new(client: &Client, url: Url, delay: u64) -> DownloaderResult<Self> {
fn new(client: &Client, url: Url) -> DownloaderResult<Self> {
let id = url.path().replace("/arts/view/", "");
let inner = Alphacoders::new(client, url, delay, id, "art", "img.img-responsive")?;
let inner = Alphacoders::new(client, url, id, "art", "img.img-responsive")?;
Ok(Self(inner))
}

Expand All @@ -113,9 +99,6 @@ impl Downloader for ArtAbyss {
fn image_title(&self) -> DownloaderResult<String> {
self.0.image_title()
}
fn image_tags(&self) -> DownloaderResult<Vec<String>> {
self.0.image_tags()
}
}

/// Image Abyss
Expand All @@ -124,9 +107,9 @@ impl Downloader for ArtAbyss {
pub struct ImageAbyss(Alphacoders);

impl Downloader for ImageAbyss {
fn new(client: &Client, url: Url, delay: u64) -> DownloaderResult<Self> {
fn new(client: &Client, url: Url) -> DownloaderResult<Self> {
let id = url.path().replace("/pictures/view/", "");
let inner = Alphacoders::new(client, url, delay, id, "picture", "img.img-responsive")?;
let inner = Alphacoders::new(client, url, id, "picture", "img.img-responsive")?;
Ok(Self(inner))
}

Expand All @@ -139,7 +122,4 @@ impl Downloader for ImageAbyss {
fn image_title(&self) -> DownloaderResult<String> {
self.0.image_title()
}
fn image_tags(&self) -> DownloaderResult<Vec<String>> {
self.0.image_tags()
}
}
10 changes: 3 additions & 7 deletions src/downloaders/artstation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ use url::Url;
pub struct ArtStation {
hash_id: String,
title: String,
assets: Vec<Asset>,
tags: Vec<String>
assets: Vec<Asset>
}

impl Downloader for ArtStation {
fn new(client: &Client, mut url: Url, delay: u64) -> DownloaderResult<Self> {
fn new(client: &Client, mut url: Url) -> DownloaderResult<Self> {
let id_path = url.path().replace("/artwork/", "/projects/");
let api_path = format!("{}.json", id_path);
url.set_path(&api_path);
Ok(quick_get(client, url, delay)?.json::<Self>()?)
Ok(quick_get(client, url)?.json::<Self>()?)
}

fn image_id(&self) -> &str {
Expand All @@ -42,9 +41,6 @@ impl Downloader for ArtStation {
fn image_title(&self) -> DownloaderResult<String> {
Ok(self.title.clone())
}
fn image_tags(&self) -> DownloaderResult<Vec<String>> {
Ok(self.tags.clone())
}
}
/// ArtStation Post Asset
#[derive(Deserialize)]
Expand Down
Loading

0 comments on commit afa73b1

Please sign in to comment.