-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Stridsvagn69420/danbooru
Add support for Danbooru Fix missing newline on output Change file name format
- Loading branch information
Showing
9 changed files
with
60 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use super::{quick_get, Downloader, DownloaderResult, Urls}; | ||
use reqwest::blocking::Client; | ||
use serde::Deserialize; | ||
use url::Url; | ||
|
||
#[derive(Deserialize)] | ||
pub struct DanbooruApi { | ||
id: u32, | ||
file_url: Url | ||
} | ||
|
||
pub struct Danbooru { | ||
id: String, | ||
file_url: Url | ||
} | ||
|
||
impl From<DanbooruApi> for Danbooru { | ||
fn from(value: DanbooruApi) -> Danbooru { | ||
Danbooru { | ||
file_url: value.file_url, | ||
id: value.id.to_string() | ||
} | ||
} | ||
} | ||
|
||
#[allow(refining_impl_trait)] | ||
impl Downloader for Danbooru { | ||
fn new(client: &Client, mut url: Url) -> DownloaderResult<Self> { | ||
// Append .json extension | ||
let newpath = format!("{}.json", url.path()); | ||
url.set_path(&newpath); | ||
|
||
// Make API Request | ||
let api_res = quick_get(client, url)?.json::<DanbooruApi>()?; | ||
Ok(api_res.into()) | ||
} | ||
fn image_id(&self) -> &str { | ||
&self.id | ||
} | ||
fn image_url(&self) -> DownloaderResult<Urls> { | ||
Ok(self.file_url.clone().into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters