mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Add new option download-multiple-posts and max-download-post-tasks
This commit is contained in:
@@ -16,6 +16,8 @@ lazy_static! {
|
||||
#[doc(hidden)]
|
||||
static ref TOTAL_DOWNLOAD_TASK_COUNT: Arc<Mutex<usize>> = Arc::new(Mutex::new(0));
|
||||
#[doc(hidden)]
|
||||
static ref TOTAL_POST_TASK_COUNT: Arc<Mutex<usize>> = Arc::new(Mutex::new(0));
|
||||
#[doc(hidden)]
|
||||
static ref PROGRESS_BAR: Arc<MultiProgress> = Arc::new(MultiProgress::new());
|
||||
}
|
||||
|
||||
@@ -63,6 +65,22 @@ impl GetMaxCount for MaxDownloadTasks {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MaxDownloadPostTasks {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
|
||||
impl MaxDownloadPostTasks {
|
||||
pub fn new() -> Self {
|
||||
MaxDownloadPostTasks { _unused: [] }
|
||||
}
|
||||
}
|
||||
|
||||
impl GetMaxCount for MaxDownloadPostTasks {
|
||||
fn get_max_count(&self) -> usize {
|
||||
get_helper().max_download_post_tasks()
|
||||
}
|
||||
}
|
||||
|
||||
/// Task manager
|
||||
pub struct TaskManager {
|
||||
/// Current running task
|
||||
@@ -71,12 +89,15 @@ pub struct TaskManager {
|
||||
finished_tasks: RwLock<Vec<Box<dyn IsFinishedAny + Send + Sync>>>,
|
||||
/// Total task count
|
||||
task_count: Arc<Mutex<usize>>,
|
||||
max_count: Box<dyn GetMaxCount>,
|
||||
max_count: Box<dyn GetMaxCount + Send + Sync>,
|
||||
}
|
||||
|
||||
impl TaskManager {
|
||||
/// Create a new instance
|
||||
pub fn new<T: GetMaxCount + 'static>(task_count: Arc<Mutex<usize>>, max_count: T) -> Self {
|
||||
pub fn new<T: GetMaxCount + Send + Sync + 'static>(
|
||||
task_count: Arc<Mutex<usize>>,
|
||||
max_count: T,
|
||||
) -> Self {
|
||||
Self {
|
||||
tasks: RwLock::new(Vec::new()),
|
||||
finished_tasks: RwLock::new(Vec::new()),
|
||||
@@ -85,6 +106,11 @@ impl TaskManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new instance with post max count
|
||||
pub fn new_post() -> Self {
|
||||
Self::new(get_total_post_task_count(), MaxDownloadPostTasks::new())
|
||||
}
|
||||
|
||||
/// Add a new task.
|
||||
pub async fn add_task<F>(&self, future: F)
|
||||
where
|
||||
@@ -161,6 +187,10 @@ pub fn get_total_download_task_count() -> Arc<Mutex<usize>> {
|
||||
Arc::clone(&TOTAL_DOWNLOAD_TASK_COUNT)
|
||||
}
|
||||
|
||||
pub fn get_total_post_task_count() -> Arc<Mutex<usize>> {
|
||||
Arc::clone(&TOTAL_POST_TASK_COUNT)
|
||||
}
|
||||
|
||||
impl Default for TaskManager {
|
||||
fn default() -> Self {
|
||||
Self::new(get_total_download_task_count(), MaxDownloadTasks::new())
|
||||
|
||||
Reference in New Issue
Block a user