j-holub / Node-MPV

A NodeJs Module for MPV Player
https://www.npmjs.com/package/node-mpv
MIT License
116 stars 73 forks source link

Check if MPV is installed #100

Closed dimzeta closed 2 years ago

dimzeta commented 2 years ago

Bug Description

My new PC does not have MPV installed. That's fine, I don't need it, I want to run my NodeJS project and develop other features. But it crashes because of that.

2021-10-05 16:27:31:203 info: --- Env: development ---
error: uncaughtException: Command failed: mpv --version
/bin/sh: mpv: command not found

Error: Command failed: mpv --version
/bin/sh: mpv: command not found

    at ChildProcess.exithandler (node:child_process:397:12)
    at ChildProcess.emit (node:events:394:28)
    at maybeClose (node:internal/child_process:1064:16)
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:394:28)
    at Pipe.<anonymous> (node:net:672:12) {"error":{"killed":false,"code":127,"signal":null,"cmd":"mpv --version"},"stack":"Error: Command failed: mpv --version\n/bin/sh: mpv: command not found\n\n    at ChildProcess.exithandler (node:child_process:397:12)\n    at ChildProcess.emit (node:events:394:28)\n    at maybeClose (node:internal/child_process:1064:16)\n    at Socket.<anonymous> (node:internal/child_process:450:11)\n    at Socket.emit (node:events:394:28)\n    at Pipe.<anonymous> (node:net:672:12)","exception":true,"date":"Tue Oct 05 2021 16:27:31 GMT+0200 (heure d’été d’Europe centrale)","process":{"pid":22510,"uid":501,"gid":20,"cwd":"/Volumes/SSD/Sites/quiz/backend","execPath":"/Users/dimitribocquet/.nvm/versions/node/v16.9.1/bin/node","version":"v16.9.1","argv":["/Users/dimitribocquet/.nvm/versions/node/v16.9.1/bin/node","/Volumes/SSD/Sites/quiz/backend/app.js"],"memoryUsage":{"rss":101367808,"heapTotal":68894720,"heapUsed":38808248,"external":24276234,"arrayBuffers":20872713}},"os":{"loadavg":[1.34521484375,1.72314453125,1.64697265625],"uptime":4572},"trace":[{"column":12,"file":"node:child_process","function":"ChildProcess.exithandler","line":397,"method":"exithandler","native":false},{"column":28,"file":"node:events","function":"ChildProcess.emit","line":394,"method":"emit","native":false},{"column":16,"file":"node:internal/child_process","function":"maybeClose","line":1064,"method":null,"native":false},{"column":11,"file":"node:internal/child_process","function":null,"line":450,"method":null,"native":false},{"column":28,"file":"node:events","function":"Socket.emit","line":394,"method":"emit","native":false},{"column":12,"file":"node:net","function":null,"line":672,"method":null,"native":false}],"timestamp":"2021-10-05 16:27:31:220"}
error: uncaughtException: Command failed: mpv --version

I tried to embed the require with a try-catch, but it does not work (I am never in the catch):

let mpvAPI;
try {
    mpvAPI = require('node-mpv');
} catch (error) {
    console.log("MPV not installed");
    console.log(error);
}

Do we have a way to verify if MPV is installed?

j-holub commented 2 years ago

Hey there,

MPV needs to be installed on your system for this module to work. It's a wrapper around it and it sends commands to the running MPV binary.

Whether you have MPV installed depends on what OS you're using, I'm assuming either Linux or macOS judging from the /bin/sh output. On either, just open a terminal and enter mpv and press enter. If it works, awesome you have mpv, if it says something along the lines of command not found you either don't have MPV installed or it's not in your path.

On Linux, use your distributions package manager. For example apt-get on Ubuntu as in sudo apt-get install mpv. Let's just hope it does install a new enough version, if I remember correctly, you need at least 0.7 or something that (which is really old, but on some Linux distros such as Debian you never know).

For macOS brew is a great third party package manager that can be used to install various packages and tools, such as MPV.

Of course you can also just check the installation section on the mpv website, this should get you covered.

I don't think this is a bug as not working when mpv isn't installed is expected behaviour, that's why I will close this issue for now. Please feel free to re-open it if you see fit. And hit me up if you got any questions : )

Cheers!