Spark-NF / hls-downloader

Download HLS streams in NodeJS
Apache License 2.0
73 stars 32 forks source link

SyntaxError: The requested module 'node-hls-downloader' does not provide an export named 'download' #9

Closed torresgol10 closed 3 years ago

torresgol10 commented 3 years ago

Hi, I have the following problem, I write my code and the result when executing it.

Node version: 14.0.0 Npm version: 6.14.4

Code:

import { download } from "node-hls-downloader";

async function x(){
    await download({
        quality: "best",
        concurrency: 5,
        outputFile: "video.mp4",
        streamUrl: "https://....m3u8",
    });
}

x();

Error:

import { download } from "node-hls-downloader"; ^^^^^^^^ SyntaxError: The requested module 'node-hls-downloader' does not provide an export named 'download' at ModuleJob._instantiate (internal/modules/esm/module_job.js:92:21) at async ModuleJob.run (internal/modules/esm/module_job.js:107:20) at async Loader.import (internal/modules/esm/loader.js:179:24)

Spark-NF commented 3 years ago

Indeed, it doesn't currently work with the ESM module format. The example in the README was taken from a TypeScript project so I didn't notice this.

I'll update this ASAP. Until then, you can fallback to the working old syntax using require() if that's possible for you:

const download = require("node-hls-downloader").download;

Another option is not using destructuring:

import hls from "node-hls-downloader";

hls.download(/* ... */);
torresgol10 commented 3 years ago

Sorry to bother again, after making the indicated change, I have detected that it only downloads the last second of the video, I put my complete code so you can test my m3u8 and the video is without audio.

I think the problem is in the file index.js variable fromEnd that is not passed through the config and its value is 1.

Sorry for my bad English and thanks for your quick response.

const download = require("node-hls-downloader").download;
// console.log(download)

async function x(){
    await download({
        quality: "best",
        concurrency: 1,
        outputFile: "video.mp4",
        streamUrl: "https://movin.platzi.com/0b1f84be-a89e-470a-b076-1d2704a1311b/14_java-oop_1906_CLASS.ism/manifest(format=m3u8-aapl,audio-only=false)",
    });
}

x();

Always put this console.log: No new segments since last check

Spark-NF commented 3 years ago

It's no bother 😃 But it'd be more fit to create another issue next time to track them independently.

I think the problem is in the file index.js variable fromEnd that is not passed through the config and its value is 1.

You're totally correct. As a temporary fix, you can simply pass a very high value in "fromEnd", such as 99999.

The code was initially done to work on live streams, hence the current "fromEnd" logic and the "No new segments since last check" messages. I'll make the "live" mode optional and default to simply load everything as-is from the stream.

torresgol10 commented 3 years ago

Sorry to bother you again 😭, I have updated the plugins and it works correctly but when creating the .mp4 ffmpeg has no audio, can you help me? I've been trying to fix it but I can't find the error, my code is the same as I put in the previous comments.

Many thanks for everything.

If I can help you with something, just ask.

Spark-NF commented 3 years ago

When checking the file you're trying to download, there doesn't seem to be an audio track in the merged TS file, which would explain why you don't get any sound.

Note that some websites have split audio and video files, especially for HD videos. That's for example the case for YouTube. Maybe the website you're trying to download from does the same?