aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariot Tsitoara <[email protected]>2021-01-02 01:23:38 +0100
committerMariot Tsitoara <[email protected]>2021-01-02 01:23:38 +0100
commit104236fb078f391cbf852d3c444de8ed7368aa24 (patch)
tree1ea09a5467c1ef463ebdba65f5661f647a60a28e
parentBump version (diff)
downloadchan-downloader-104236fb078f391cbf852d3c444de8ed7368aa24.tar.xz
chan-downloader-104236fb078f391cbf852d3c444de8ed7368aa24.zip
Add lib examples to README
-rw-r--r--Cargo.toml2
-rw-r--r--README.md62
-rw-r--r--src/cli.yml2
3 files changed, 64 insertions, 2 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 68fc4fa..9b55de8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "chan-downloader"
description = "CLI to download all images/webms of a 4chan thread"
-version = "0.1.3"
+version = "0.1.4"
authors = ["Mariot Tsitoara <[email protected]>"]
edition = "2018"
license = "MIT"
diff --git a/README.md b/README.md
index 48d9475..c044ccc 100644
--- a/README.md
+++ b/README.md
@@ -12,5 +12,67 @@ FLAGS:
-V, --version Prints version information
OPTIONS:
+ -o, --output <output> Output directory (Default is 'downloads')
-t, --thread <thread> URL of the thread
```
+
+chan_downloader
+===============
+You can also use chan_downloader, the library used
+
+## save_image
+Saves the image from the url to the given path. Returns the path on success
+```
+use reqwest::Client;
+use std::env;
+use std::fs::remove_file;
+let client = Client::new();
+let workpath = env::current_dir().unwrap().join("1489266570954.jpg");
+let url = "https://i.4cdn.org/wg/1489266570954.jpg";
+let answer = chan_downloader::save_image(url, workpath.to_str().unwrap(), &client).unwrap();
+
+assert_eq!(workpath.to_str().unwrap(), answer);
+remove_file(answer).unwrap();
+```
+
+## get_page_content
+Returns the page content from the given url.
+```
+use reqwest::Client;
+let client = Client::new();
+let url = "https://boards.4chan.org/wg/thread/6872254";
+match chan_downloader::get_page_content(url, &client) {
+ Ok(page) => println!("Content: {}", page),
+ Err(err) => eprintln!("Error: {}", err),
+}
+```
+
+## get_thread_infos
+Returns the board name and thread id.
+```
+let url = "https://boards.4chan.org/wg/thread/6872254";
+let (board_name, thread_id) = chan_downloader::get_thread_infos(url);
+///
+assert_eq!(board_name, "wg");
+assert_eq!(thread_id, "6872254");
+```
+
+## get_image_links
+Returns the links and the number of links from a page. Note that the links are doubled.
+```
+use reqwest::Client;
+let client = Client::new();
+let url = "https://boards.4chan.org/wg/thread/6872254";
+match chan_downloader::get_page_content(url, &client) {
+ Ok(page_string) => {
+ let (links_iter, number_of_links) = chan_downloader::get_image_links(page_string.as_str());
+
+ assert_eq!(number_of_links, 4);
+
+ for cap in links_iter.step_by(2) {
+ println!("{} and {}", &cap[1], &cap[2]);
+ }
+ },
+ Err(err) => eprintln!("Error: {}", err),
+}
+```
diff --git a/src/cli.yml b/src/cli.yml
index a35fd06..1fb84d0 100644
--- a/src/cli.yml
+++ b/src/cli.yml
@@ -1,5 +1,5 @@
name: chan-downloader
-version: "0.1.3"
+version: "0.1.4"
author: "Mariot Tsitoara <[email protected]>"
about: CLI to download all images/webms of a 4chan thread
args: