Closed vk22 closed 3 years ago
Hi thanks for reaching out!
I tried out your code (fudging in some values for your result object) and noticed a couple things:
pic
variable doesn't specify all the fields for the IPicture
interface (it's missing type [required], description and filename [not required])data
property of an IPicture
must be a ByteVector
object, you can easily create one that reads the file using ByteVector.fromPath(myFilePath)
Otherwise, it looks pretty good. I patched up your code a bit and ended up with (in typescript):
import * as fs from "fs";
import {ByteVector, File, PictureType} from "node-taglib-sharp";
const myFile = File.createFromPath("path_to_aif");
const pic = {
data: ByteVector.fromPath("path_to_img"),
mimeType: 'image/png',
type: PictureType.FrontCover,
filename: undefined, // not required
description: undefined // not required
}
myFile.tag.title = "title";
myFile.tag.album = "album";
myFile.tag.performers = ["foo", "bar", "baz"];
myFile.tag.pictures = [pic];
myFile.tag.genres = ["reggae"];
myFile.tag.year = 2021;
myFile.save();
myFile.dispose();
Alternatively, you can let the library construct an IPicture
object by doing Picture.fromPath("path_to_img");
This library mostly follows the paradigms from the original .NET implementation, including the (somewhat confusing) ByteVector class. If you have any suggestions for how I can better document or implement it to work better for node developers, please let me know!
Looks like that resolves your issue. Let me know if you have anymore issues, and thanks again for trying out node-taglib-sharp!
Hi! I'm sorry I didn't answer right away. Was away. Your answer helped me. Thank you very much! But I have a couple more questions, I'll write a little later today! Have a nice day!
Hey mate! Sorry, but i'm back)) I have some strange with saving file after adding tags.
My code:
const myFile = File.createFromPath(path);
const pic = {
data: ByteVector.fromPath(pathToPic),
mimeType: 'image/png',
type: PictureType.FrontCover,
filename: 'Cover.png',
description: 'Cover.png'
}
myFile.tag.pictures = [pic];
myFile.tag.title = tagsData.trackTitle;
myFile.tag.album = tagsData.releaseAlbum;
myFile.tag.performers = [tagsData.artists];
myFile.tag.albumArtists = [tagsData.albumArtists];
myFile.tag.genres = tagsData.styleAsString;
if (tagsData.year) {
myFile.tag.year = tagsData.year;
}
myFile.tag.track = tagsData.indexTrack;
myFile.tag.trackCount = tagsData.trackCount;
myFile.save();
myFile.dispose();
After saving i don't see cover and tags in finder or preview. - http://prntscr.com/26bi92t
They are present, I can see they in players (itunes) or tag editors (kid3, meta) - http://prntscr.com/26bi9er And then if I open this file in kid3 and save it - tags and cover will be visible in finder and preview - http://prntscr.com/26bia32
OS: Mac OS Files type: aiff
Can you help me? Regards!
Sorry, can get how to add cover to aiff file?
I try this:
But i get error: Argument null: data was not provided