Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zoom-format #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ pub struct Arguments {
/// retrying partially failed downloads, or stitching the tiles with an external program.
#[arg(short = 'c', long = "tile-cache")]
pub tile_storage_folder: Option<PathBuf>,
/// A zoom_level image format suffix eg.default.png or default.jpg
#[arg(short = 'f', long = "zoom-format", default_value = "auto")]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type probably shouldn't be String if not all strings are valid. The documentation should explain precisely what this does.

pub zoom_format: String,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the option is specific to IIIF, then its name should probably reference it.

Maybe something like --iiif-tile-format=jpg

}

impl Default for Arguments {
Expand All @@ -140,6 +143,7 @@ impl Default for Arguments {
connect_timeout: Duration::from_secs(6),
logging: "warn".to_string(),
tile_storage_folder: None,
zoom_format: "".to_string(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ pub async fn dezoomify_level(
retries: args.retries,
retry_delay: args.retry_delay,
tile_storage_folder: args.tile_storage_folder.clone(),
zoom_format: args.zoom_format.clone(),
};
let mut throttler = throttler::Throttler::new(args.min_interval);
info!("Creating canvas");
Expand Down
16 changes: 15 additions & 1 deletion src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,27 @@ pub struct TileDownloader {
pub retries: usize,
pub retry_delay: Duration,
pub tile_storage_folder: Option<PathBuf>,
pub zoom_format: String,
}

impl TileDownloader {
pub async fn download_tile(
&self,
tile_reference: TileReference,
mut tile_reference: TileReference,
) -> Result<Tile, TileDownloadError> {
if !"auto".eq(&self.zoom_format) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not the right place to handle that. This option is specific to the iiif dezoomer, isn't it? If it is, then it should be handled in the dezoomer.

if let Ok(regx) = regex::Regex::new(r"default.*") {
let url = regx
.replace(
&tile_reference.url,
&format!("default.{}", self.zoom_format),
)
.to_string();

tile_reference.url = url
};
}

// The initial delay after which a failed request is retried depends on the position of the tile
// in order to avoid sending repeated "bursts" of requests to a server that is struggling
let n = 100;
Expand Down
Loading