mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Add tags to json data file
This commit is contained in:
@@ -18,6 +18,8 @@ pub struct PixivData {
|
||||
/// The author
|
||||
pub author: Option<String>,
|
||||
pub description: Option<String>,
|
||||
/// Tags (Original, translated)
|
||||
pub tags: Option<Vec<(String, Option<String>)>>,
|
||||
}
|
||||
|
||||
impl PixivData {
|
||||
@@ -31,6 +33,7 @@ impl PixivData {
|
||||
title: None,
|
||||
author: None,
|
||||
description: None,
|
||||
tags: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -84,6 +87,19 @@ impl PixivData {
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut tags = Vec::new();
|
||||
for tag in value["tags"]["tags"].members() {
|
||||
if let Some(ori) = tag["tag"].as_str() {
|
||||
tags.push((
|
||||
ori.to_owned(),
|
||||
match tag["translation"]["en"].as_str() {
|
||||
Some(s) => Some(s.to_owned()),
|
||||
None => None,
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
self.tags.replace(tags);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,23 @@ impl From<&PixivData> for JSONDataFile {
|
||||
f.add("parsed_description", pd.unwrap()).unwrap();
|
||||
}
|
||||
}
|
||||
match p.tags.as_ref() {
|
||||
Some(tags) => {
|
||||
let mut t = JsonValue::new_array();
|
||||
for tag in tags {
|
||||
t.push(json::array![
|
||||
tag.0.as_str(),
|
||||
match &tag.1 {
|
||||
Some(s) => JsonValue::String(s.to_owned()),
|
||||
None => JsonValue::Null,
|
||||
}
|
||||
])
|
||||
.unwrap();
|
||||
}
|
||||
f.add("tags", t).unwrap();
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
f
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user