Skip to content

Commit

Permalink
lofty picture bug reproduction
Browse files Browse the repository at this point in the history
  • Loading branch information
probablykasper committed Apr 21, 2024
1 parent a4f9455 commit e411ddf
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
Binary file added examples/3000.jpg
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 added examples/bugged.opus
Binary file not shown.
48 changes: 48 additions & 0 deletions examples/repro.rs
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 added examples/song.opus
Binary file not shown.
5 changes: 5 additions & 0 deletions src/components/TrackInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,17 @@
replaceCover(result.filePaths[0])
}
}
console.log('x')
function replaceCover(filePath: string) {
console.log('setImage')
methods.setImage(image?.index || 0, filePath)
imageEdited = true
loadImage(image?.index || 0)
}
function replaceCoverData(data: ArrayBuffer, mimeType: string) {
console.log('setImageData')
methods.setImageData(image?.index || 0, data, mimeType)
imageEdited = true
loadImage(image?.index || 0)
Expand Down

0 comments on commit e411ddf

Please sign in to comment.