added bit more verbose output and my build script.
also embedded demo of usage
This commit is contained in:
parent
4d5fc9c2a7
commit
6d2a4aa625
5 changed files with 18 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pixelfed_batch_uploader"
|
name = "pixelfed_batch_uploader"
|
||||||
version = "0.1.0"
|
version = "1.0.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
|
|
|
@ -5,3 +5,9 @@ The description of the post can be given via the config.json.
|
||||||
Two variables in the post description can be give (see the `config.json.example` ).
|
Two variables in the post description can be give (see the `config.json.example` ).
|
||||||
|
|
||||||
Usage: `./pixelfed_batch_uploader ../../Downloads/Instagram-Backup/media/posts/201406 --title "June 2014"`
|
Usage: `./pixelfed_batch_uploader ../../Downloads/Instagram-Backup/media/posts/201406 --title "June 2014"`
|
||||||
|
|
||||||
|
|
||||||
|
[![asciicast](https://asciinema.mxhdr.net/a/6.svg)](https://asciinema.mxhdr.net/a/6)
|
||||||
|
|
||||||
|
|
||||||
|
Check the package of this repo to get pre-compiled binaries for macOS (Apple Silicon), Linux x86_64, Windows ARM
|
||||||
|
|
4
build.sh
Executable file
4
build.sh
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash -x
|
||||||
|
|
||||||
|
cargo clean
|
||||||
|
cargo build --release --target $(rustc -vV | grep host | cut -d ' ' -f2)
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash -x
|
#!/bin/bash -x
|
||||||
|
|
||||||
RELEASE_VERSION="1.0.1"
|
RELEASE_VERSION="1.0.2"
|
||||||
|
|
||||||
curl --netrc \
|
curl --netrc \
|
||||||
--upload-file target/$(rustc -vV | grep host | cut -d ' ' -f2)/release/pixelfed_batch_uploader \
|
--upload-file target/$(rustc -vV | grep host | cut -d ' ' -f2)/release/pixelfed_batch_uploader \
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -1,6 +1,5 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use serde::Deserialize;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
@ -45,9 +44,10 @@ fn upload_images_batch(client: &Client, config: &Config, images: &[String], batc
|
||||||
let mut media_ids = Vec::new();
|
let mut media_ids = Vec::new();
|
||||||
|
|
||||||
for image_path in images {
|
for image_path in images {
|
||||||
|
println!("Uploading image {}", image_path.to_string());
|
||||||
let form = reqwest::blocking::multipart::Form::new()
|
let form = reqwest::blocking::multipart::Form::new()
|
||||||
.file("file", image_path)?;
|
.file("file", image_path)?;
|
||||||
|
|
||||||
let res = client.post(&url)
|
let res = client.post(&url)
|
||||||
.bearer_auth(&config.access_token)
|
.bearer_auth(&config.access_token)
|
||||||
.multipart(form)
|
.multipart(form)
|
||||||
|
@ -67,7 +67,8 @@ fn upload_images_batch(client: &Client, config: &Config, images: &[String], batc
|
||||||
"media_ids": media_ids,
|
"media_ids": media_ids,
|
||||||
"visibility": config.visibility,
|
"visibility": config.visibility,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
println!("Posting batch {} out of {}", batch_num, total_batches);
|
||||||
client.post(&post_url)
|
client.post(&post_url)
|
||||||
.bearer_auth(&config.access_token)
|
.bearer_auth(&config.access_token)
|
||||||
.json(&body)
|
.json(&body)
|
||||||
|
@ -95,7 +96,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let images = get_jpeg_files(&args[1]);
|
let images = get_jpeg_files(&args[1]);
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let total_batches = (images.len() + config.batch_size - 1) / config.batch_size;
|
let total_batches = (images.len() + config.batch_size - 1) / config.batch_size;
|
||||||
|
println!("Found a total of {} images to upload. Will take {} batches", images.len(), total_batches);
|
||||||
for (i, chunk) in images.chunks(config.batch_size).enumerate() {
|
for (i, chunk) in images.chunks(config.batch_size).enumerate() {
|
||||||
upload_images_batch(&client, &config, chunk, i + 1, total_batches, &title)?;
|
upload_images_batch(&client, &config, chunk, i + 1, total_batches, &title)?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue