feat: add the concept of tags
Tags are attached to all magnet links provided by a given source, and passed to actions. This allows for e.g. better categorization in Bitmagnet.
This commit is contained in:
parent
f19e02988f
commit
c3764c125a
13 changed files with 240 additions and 11 deletions
|
|
@ -37,12 +37,16 @@ impl Action for BitmagnetAction {
|
|||
let mut failed_magnets = Vec::new();
|
||||
|
||||
for magnet in unprocessed_magnets {
|
||||
let tags = db.get_tags_for_magnet(magnet.id)?;
|
||||
let tag_refs: Vec<&str> = tags.iter().map(|s| s.as_str()).collect();
|
||||
|
||||
match self
|
||||
.client
|
||||
.submit_magnet(
|
||||
&magnet.link,
|
||||
&magnet.published_at.and_utc(),
|
||||
&magnet.imdb_id,
|
||||
tag_refs,
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
|
@ -53,6 +57,9 @@ impl Action for BitmagnetAction {
|
|||
magnet.title
|
||||
);
|
||||
debug!("Magnet link: {}", magnet.link);
|
||||
if !tags.is_empty() {
|
||||
debug!("Tags: {:?}", tags);
|
||||
}
|
||||
db.mark_magnet_processed_for_table::<BitmagnetProcessedTable>(magnet.id)?;
|
||||
processed_magnets.push(magnet);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ impl BitmagnetClient {
|
|||
magnet: &str,
|
||||
published_at: &DateTime<Utc>,
|
||||
imdb_id: &Option<String>,
|
||||
tags: Vec<&str>,
|
||||
) -> Result<()> {
|
||||
let url = self
|
||||
.base_url
|
||||
|
|
@ -43,7 +44,6 @@ impl BitmagnetClient {
|
|||
let structured_magnet =
|
||||
Magnet::new(magnet).map_err(|e| eyre!("Invalid magnet link: {:?}", e))?;
|
||||
|
||||
// Create a JSON object with the required fields
|
||||
let mut json_body = json!({
|
||||
"publishedAt": published_at.to_rfc3339(),
|
||||
"source": "reddit-magnet",
|
||||
|
|
@ -71,6 +71,10 @@ impl BitmagnetClient {
|
|||
json_body["size"] = json!(size);
|
||||
}
|
||||
|
||||
if let Some(tag) = tags.first() {
|
||||
json_body["contentType"] = json!(tag);
|
||||
}
|
||||
|
||||
let response = self
|
||||
.client
|
||||
.post(url)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,10 @@ impl Action for TransmissionAction {
|
|||
let mut failed_magnets = Vec::new();
|
||||
|
||||
for magnet in unprocessed_magnets {
|
||||
match self.client.submit_magnet(&magnet.link).await {
|
||||
let tags = db.get_tags_for_magnet(magnet.id)?;
|
||||
let tag_refs: Vec<&str> = tags.iter().map(|s| s.as_str()).collect();
|
||||
|
||||
match self.client.submit_magnet(&magnet.link, tag_refs).await {
|
||||
Ok(_) => {
|
||||
debug!(
|
||||
"Successfully submitted magnet link to {}: {}",
|
||||
|
|
@ -45,6 +48,9 @@ impl Action for TransmissionAction {
|
|||
magnet.title
|
||||
);
|
||||
debug!("Magnet link: {}", magnet.link);
|
||||
if !tags.is_empty() {
|
||||
debug!("Tags: {:?}", tags);
|
||||
}
|
||||
db.mark_magnet_processed_for_table::<TransmissionProcessedTable>(magnet.id)?;
|
||||
processed_magnets.push(magnet);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,10 +36,11 @@ impl TransmissionClient {
|
|||
}
|
||||
|
||||
/// Submit a magnet link to Transmission
|
||||
pub async fn submit_magnet(&mut self, magnet: &str) -> Result<()> {
|
||||
pub async fn submit_magnet(&mut self, magnet: &str, tags: Vec<&str>) -> Result<()> {
|
||||
let args = TorrentAddArgs {
|
||||
filename: Some(magnet.to_string()),
|
||||
download_dir: Some(self.download_dir.clone()),
|
||||
labels: Some(tags.iter().map(|t| t.to_string()).collect()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue