fix: simplify qbit action finish detect
This commit is contained in:
parent
05273e21ba
commit
01053da8d2
@ -118,9 +118,9 @@ impl QBittorrentDownloader {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn wait_some_torrents_until<F>(
|
pub async fn wait_torrents_until<F>(
|
||||||
&self,
|
&self,
|
||||||
hashes: Vec<String>,
|
arg: GetTorrentListArg,
|
||||||
stop_wait_fn: F,
|
stop_wait_fn: F,
|
||||||
timeout: Option<Duration>,
|
timeout: Option<Duration>,
|
||||||
) -> eyre::Result<()>
|
) -> eyre::Result<()>
|
||||||
@ -128,11 +128,7 @@ impl QBittorrentDownloader {
|
|||||||
F: FnMut(Vec<QbitTorrent>) -> bool,
|
F: FnMut(Vec<QbitTorrent>) -> bool,
|
||||||
{
|
{
|
||||||
self.wait_until(
|
self.wait_until(
|
||||||
|| {
|
|| arg,
|
||||||
GetTorrentListArg::builder()
|
|
||||||
.hashes(hashes.join("|"))
|
|
||||||
.build()
|
|
||||||
},
|
|
||||||
async move |client: Arc<Qbit>,
|
async move |client: Arc<Qbit>,
|
||||||
arg: GetTorrentListArg|
|
arg: GetTorrentListArg|
|
||||||
-> eyre::Result<Vec<QbitTorrent>> {
|
-> eyre::Result<Vec<QbitTorrent>> {
|
||||||
@ -251,28 +247,17 @@ impl TorrentDownloader for QBittorrentDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn delete_torrents(&self, hashes: Vec<String>) -> eyre::Result<()> {
|
async fn delete_torrents(&self, hashes: Vec<String>) -> eyre::Result<()> {
|
||||||
let existed_list = self
|
|
||||||
.client
|
|
||||||
.get_torrent_list(
|
|
||||||
GetTorrentListArg::builder()
|
|
||||||
.hashes(hashes.clone().join("|"))
|
|
||||||
.build(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
if !existed_list.is_empty() {
|
|
||||||
self.client
|
self.client
|
||||||
.delete_torrents(hashes.clone(), Some(true))
|
.delete_torrents(hashes.clone(), Some(true))
|
||||||
.await?;
|
.await?;
|
||||||
self.wait_sync_until(
|
self.wait_torrents_until(
|
||||||
|sync_data| -> bool {
|
GetTorrentListArg::builder()
|
||||||
sync_data
|
.hashes(hashes.join("|"))
|
||||||
.torrents
|
.build(),
|
||||||
.map_or(true, |t| hashes.iter().all(|h| !t.contains_key(h)))
|
|torrents| -> bool { torrents.is_empty() },
|
||||||
},
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,17 +285,16 @@ impl TorrentDownloader for QBittorrentDownloader {
|
|||||||
self.client
|
self.client
|
||||||
.set_torrent_location(hashes.clone(), new_path)
|
.set_torrent_location(hashes.clone(), new_path)
|
||||||
.await?;
|
.await?;
|
||||||
self.wait_sync_until(
|
self.wait_torrents_until(
|
||||||
|sync_data| -> bool {
|
GetTorrentListArg::builder()
|
||||||
hashes.iter().all(|hash| {
|
.hashes(hashes.join("|"))
|
||||||
sync_data.torrents.as_ref().map_or(false, |t| {
|
.build(),
|
||||||
t.get(hash).map_or(false, |t| {
|
|torrents| -> bool {
|
||||||
|
torrents.iter().all(|t| {
|
||||||
t.save_path
|
t.save_path
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |p| path_str_equals(p, new_path).unwrap_or(false))
|
.map_or(false, |p| path_str_equals(p, new_path).unwrap_or(false))
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@ -348,15 +332,14 @@ impl TorrentDownloader for QBittorrentDownloader {
|
|||||||
} else {
|
} else {
|
||||||
result?;
|
result?;
|
||||||
}
|
}
|
||||||
self.wait_sync_until(
|
self.wait_torrents_until(
|
||||||
|sync_data| {
|
GetTorrentListArg::builder()
|
||||||
sync_data.torrents.map_or(false, |ts| {
|
.hashes(hashes.join("|"))
|
||||||
hashes.iter().all(|h| {
|
.build(),
|
||||||
ts.get(h).map_or(false, |t| {
|
|torrents| {
|
||||||
t.category.as_ref().map_or(false, |c| c == category)
|
torrents
|
||||||
})
|
.iter()
|
||||||
})
|
.all(|t| t.category.as_ref().map_or(false, |c| c == category))
|
||||||
})
|
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@ -372,11 +355,12 @@ impl TorrentDownloader for QBittorrentDownloader {
|
|||||||
.add_torrent_tags(hashes.clone(), tags.clone())
|
.add_torrent_tags(hashes.clone(), tags.clone())
|
||||||
.await?;
|
.await?;
|
||||||
let tag_sets = tags.iter().map(|s| s.as_str()).collect::<HashSet<&str>>();
|
let tag_sets = tags.iter().map(|s| s.as_str()).collect::<HashSet<&str>>();
|
||||||
self.wait_sync_until(
|
self.wait_torrents_until(
|
||||||
|sync_data| {
|
GetTorrentListArg::builder()
|
||||||
sync_data.torrents.map_or(false, |ts| {
|
.hashes(hashes.join("|"))
|
||||||
hashes.iter().all(|h| {
|
.build(),
|
||||||
ts.get(h).map_or(false, |t| {
|
|torrents| {
|
||||||
|
torrents.iter().all(|t| {
|
||||||
t.tags.as_ref().map_or(false, |t| {
|
t.tags.as_ref().map_or(false, |t| {
|
||||||
t.split(',')
|
t.split(',')
|
||||||
.map(|s| s.trim())
|
.map(|s| s.trim())
|
||||||
@ -385,8 +369,6 @@ impl TorrentDownloader for QBittorrentDownloader {
|
|||||||
.is_superset(&tag_sets)
|
.is_superset(&tag_sets)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user