From 669dbb18e105129fff4886ba3710596d54a5f33a Mon Sep 17 00:00:00 2001 From: IcyColdified <139003835+IcyColdified@users.noreply.github.com> Date: Wed, 1 May 2024 01:33:22 +0900 Subject: [PATCH] feat: Add album art to OGG files (#81) --- Cargo.lock | 9 ++++++++- Cargo.toml | 3 ++- src/tag/ogg.rs | 28 ++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51a24a3..18f0167 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -414,6 +414,12 @@ version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "bindgen" version = "0.69.1" @@ -820,11 +826,12 @@ dependencies = [ [[package]] name = "down_on_spot" -version = "0.2.5" +version = "0.3.0" dependencies = [ "aspotify", "async-std", "async-stream", + "base64 0.22.0", "chrono", "clap", "colored", diff --git a/Cargo.toml b/Cargo.toml index ba23a0e..743162b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ panic = "abort" [package] name = "down_on_spot" -version = "0.2.6" +version = "0.3.0" edition = "2021" authors = ["exttex", "oSumAtrIX"] build = "build.rs" @@ -20,6 +20,7 @@ clap = "4.2.1" log = "0.4" url = "2.2" protobuf = "3.1" +base64 = "0.22.0" id3 = "1.3" dirs = "5.0.0" chrono = "0.4" diff --git a/src/tag/ogg.rs b/src/tag/ogg.rs index 0a6b2b4..6364cd6 100644 --- a/src/tag/ogg.rs +++ b/src/tag/ogg.rs @@ -1,3 +1,4 @@ +use base64::Engine; use chrono::{Datelike, NaiveDate}; use oggvorbismeta::{read_comment_header, replace_comment_header, CommentHeader, VorbisComments}; use std::fs::File; @@ -40,8 +41,31 @@ impl super::Tag for OggTag { self.set_raw(tag, value); } - fn add_cover(&mut self, _mime: &str, _data: Vec) { - error!("ALBUM ART IN OGG NOT SUPPORTED!"); + fn add_cover(&mut self, mime: &str, data: Vec) { + let mut picture: Vec = Vec::new(); + + // MIME type + picture.extend(3u32.to_be_bytes().iter()); + picture.extend((mime.as_bytes().len() as u32).to_be_bytes().iter()); + picture.extend(mime.as_bytes()); + + // Description + picture.extend(0u32.to_be_bytes().iter()); + + // Width, height, depth, and number of colors + picture.extend(0u32.to_be_bytes().iter()); + picture.extend(0u32.to_be_bytes().iter()); + picture.extend(0u32.to_be_bytes().iter()); + picture.extend(0u32.to_be_bytes().iter()); + + // Image data + picture.extend((data.len() as u32).to_be_bytes().iter()); + picture.extend(data); + + self.tag.add_tag_single( + "METADATA_BLOCK_PICTURE", + &base64::engine::general_purpose::STANDARD.encode(picture), + ); } fn set_raw(&mut self, tag: &str, value: Vec) {