How to Fix Audio Parsing Issue with NPM Packages in a Pipedream Component?

This topic was automatically generated from Slack. You can find the original thread here.

Hello. I posted this on the Pipedream Community page yesterday but have since learnt that Discord is where the action is. I’m having massive issues getting audio to parse through NPM packages.

import fs from "fs/promises";
import * as mm from "music-metadata";

export default defineComponent({
  props: {
    audioFilePath: {
      type: "string",
      label: "Audio File Path",
      description: "Path of the audio file to extract metadata from",
    },
  },
  async run() {
    const buffer = await fs.readFile(this.audioFilePath);
    const metadata = await mm.parseBuffer(buffer, 'audio/mpeg', { duration: true });

    const artist = metadata.common.artist;
    const title = metadata.common.title;

    console.log('Artist:', artist);
    console.log('Title:', title);

    return { artist, title };
  },
});

In this instance, we’re logging the artist and title to the console to validate that the file isn’t parsing through the package - and guess what, it isn’t. I’ve tried lots of different NPM options - FFProbe, JSMediaTags, ID3tags… you name it - I can’t get any of them to parse the file correctly.

Hello , may I ask what is the result you observed, is it an error or invalid data?

The code executes - but the ‘artist’ and ‘title’ both log as ‘undefined’. I tried a different approach, using the parseFile statement below - but the result was the same.

import * as mm from "music-metadata";

export default defineComponent({
  props: {
    audioFilePath: {
      type: "string",
      label: "Audio File Path",
      description: "Path of the audio file to extract metadata from",
    },
  },
  async run() {
    const metadata = await mm.parseFile(this.audioFilePath, { duration: true });

    const artist = metadata.common.artist;
    const title = metadata.common.title;

    console.log('Artist:', artist);
    console.log('Title:', title);

    return { artist, title };
  },
});

May I ask what is the input for the audioFilePath prop? Is it from /tmp dir? Have you downloaded the audio file to Pipedream tmp dir?

Yes, I’m copying the file from Gdrive to /TMP using the helper. The file is below 6 megabytes and contains the appropriate metadata.

I see, have you tried your code in your local machine (only the content in run method) to see if it works?

No, I haven’t - I’m massive n00b at’s basically been using ChatGPT4 and posting HTTP requests to your AI - but your suggestion was on my list of things to try

I think that’s one way to go. I suspect that your file in invalid and/or you downloaded the file to tmp dir but referred to it incorrectly in to audioFilePath

It would be better if you have coding knowledge to understand what it’s doing and what’s wrong. If you’re still unsure that you can implement your usecase, you can:

  1. Read more about Pipedream Node.js document here
  2. Read more about Javascript, especially Node.js part. Also you can watch through Pipedream speedrun series to have more references
  3. Submit a ticket for Pipedream, stating the action on the app that you need
  4. If you have subscribed to Pipedream team plan, you will be added to a dedicated slack support channel
  5. If you’d like to hire a Pipedream expert for your usecase, feel free to use this link: Connect with a Pipedream Partner

Thanks Leo. As you suggested, there is a problem with the tmp file as when I hosted and used an URL for the file path the code executed correctly.