-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4f9455
commit e411ddf
Showing
6 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use lofty::file::TaggedFileExt; | ||
use lofty::picture::Picture; | ||
use lofty::probe::Probe; | ||
use lofty::tag::{TagExt, TagType}; | ||
use std::fs::{self, File}; | ||
use std::io::{BufReader, Cursor}; | ||
|
||
fn main() { | ||
let song_path = "examples/song.opus"; | ||
let bugged_song_path = "examples/bugged.opus"; | ||
let image_path = "examples/3000.jpg"; | ||
|
||
fs::copy(song_path, bugged_song_path).unwrap(); | ||
|
||
// Open | ||
let probe = probe_open(bugged_song_path); | ||
let mut tagged_file = probe.read().unwrap(); | ||
let tag = tagged_file.tag_mut(TagType::VorbisComments).unwrap(); | ||
|
||
// Add picture and save | ||
tag.set_picture(0, get_picture(image_path)); | ||
tag | ||
.save_to_path(bugged_song_path, lofty::config::WriteOptions::default()) | ||
.unwrap(); | ||
|
||
// Open again | ||
let probe = probe_open(bugged_song_path); | ||
if let Err(e) = probe.read() { | ||
eprintln!("ERROR: {:#?}", e.kind()); | ||
} | ||
} | ||
|
||
fn probe_open(path: &str) -> Probe<BufReader<File>> { | ||
let parse_options = lofty::config::ParseOptions::new() | ||
.read_properties(false) | ||
.parsing_mode(lofty::config::ParsingMode::Strict); | ||
let probe = lofty::probe::Probe::open(path) | ||
.unwrap() | ||
.options(parse_options.clone()); | ||
probe | ||
} | ||
|
||
fn get_picture(image_path: &str) -> Picture { | ||
let new_bytes = fs::read(image_path).unwrap(); | ||
let mut reader = Cursor::new(new_bytes); | ||
let picture = lofty::picture::Picture::from_reader(&mut reader).unwrap(); | ||
picture | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters