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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue