feat: Add Spotify URI as tag data (#90)
Co-authored-by: 0xnf <0xnf@winetech.com>
This commit is contained in:
parent
669dbb18e1
commit
d91b5dd5ad
5 changed files with 28 additions and 4 deletions
|
|
@ -21,7 +21,7 @@ log = "0.4"
|
|||
url = "2.2"
|
||||
protobuf = "3.1"
|
||||
base64 = "0.22.0"
|
||||
id3 = "1.3"
|
||||
id3 = "1.14"
|
||||
dirs = "5.0.0"
|
||||
chrono = "0.4"
|
||||
lewton = "0.10"
|
||||
|
|
|
|||
|
|
@ -416,7 +416,15 @@ impl DownloaderInternal {
|
|||
// Write tags
|
||||
let config = config.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
DownloaderInternal::write_tags(path, format, tags, date, cover, config)
|
||||
DownloaderInternal::write_tags(
|
||||
path,
|
||||
job.track_id.to_string(),
|
||||
format,
|
||||
tags,
|
||||
date,
|
||||
cover,
|
||||
config,
|
||||
)
|
||||
})
|
||||
.await??;
|
||||
|
||||
|
|
@ -445,6 +453,7 @@ impl DownloaderInternal {
|
|||
/// Write tags to file ( BLOCKING )
|
||||
fn write_tags(
|
||||
path: impl AsRef<Path>,
|
||||
track_id: String,
|
||||
format: AudioFormat,
|
||||
tags: Vec<(Field, Vec<String>)>,
|
||||
date: NaiveDate,
|
||||
|
|
@ -467,6 +476,8 @@ impl DownloaderInternal {
|
|||
if let Some((mime, data)) = cover {
|
||||
tag.add_cover(&mime, data);
|
||||
}
|
||||
// UFID spotify track id
|
||||
tag.add_unique_file_identifier(&track_id);
|
||||
tag.save()?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use chrono::{Datelike, NaiveDate};
|
||||
use id3::frame::{Picture, PictureType, Timestamp};
|
||||
use id3::frame::{Picture, PictureType, Timestamp, UniqueFileIdentifier};
|
||||
use id3::{Tag, TagLike, Version};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
|
|
@ -82,4 +82,11 @@ impl super::Tag for ID3Tag {
|
|||
second: None,
|
||||
})
|
||||
}
|
||||
|
||||
fn add_unique_file_identifier(&mut self, track_id: &str) {
|
||||
self.tag.add_frame(UniqueFileIdentifier {
|
||||
owner_identifier: "spotify.com".to_string(),
|
||||
identifier: track_id.into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,12 +36,14 @@ impl TagWrap {
|
|||
}
|
||||
|
||||
pub trait Tag {
|
||||
// Set tag values separator
|
||||
/// Set tag values separator
|
||||
fn set_separator(&mut self, separator: &str);
|
||||
fn set_raw(&mut self, tag: &str, value: Vec<String>);
|
||||
fn set_field(&mut self, field: Field, value: Vec<String>);
|
||||
fn set_release_date(&mut self, date: NaiveDate);
|
||||
fn add_cover(&mut self, mime: &str, data: Vec<u8>);
|
||||
/// Adds the file identifier of the track
|
||||
fn add_unique_file_identifier(&mut self, track_id: &str);
|
||||
fn save(&mut self) -> Result<(), SpotifyError>;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,4 +89,8 @@ impl super::Tag for OggTag {
|
|||
&format!("{}-{:02}-{:02}", date.year(), date.month(), date.day()),
|
||||
)
|
||||
}
|
||||
|
||||
fn add_unique_file_identifier(&mut self, track_id: &str) {
|
||||
self.tag.add_tag_single("SPOTIFY.COM_TRACKID", track_id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue