Coder Social home page Coder Social logo

How to add pictures? about node-taglib-sharp HOT 4 CLOSED

benrr101 avatar benrr101 commented on September 26, 2024
How to add pictures?

from node-taglib-sharp.

Comments (4)

benrr101 avatar benrr101 commented on September 26, 2024

Hi thanks for reaching out!

I tried out your code (fudging in some values for your result object) and noticed a couple things:

  • Your pic variable doesn't specify all the fields for the IPicture interface (it's missing type [required], description and filename [not required])
  • The 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!

from node-taglib-sharp.

benrr101 avatar benrr101 commented on September 26, 2024

Looks like that resolves your issue. Let me know if you have anymore issues, and thanks again for trying out node-taglib-sharp!

from node-taglib-sharp.

vk22 avatar vk22 commented on September 26, 2024

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!

from node-taglib-sharp.

vk22 avatar vk22 commented on September 26, 2024

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!

from node-taglib-sharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.