I have created node js function for download youtube videos.
when I run the function following error is showing:
youtube-dl showing Error: Command failed with exit code 1: \node_modules\youtube-dl\bin\youtube-dl.exe --dump-json --format=18 --encoding utf8 http://www.youtube.com/watch?v=4FDud9Lj5HY
const video = youtubedl(
url,
// Optional arguments passed to youtube-dl.
['--format=18'],
// Additional options can be given for calling `child_process.execFile()`.
{ cwd: __dirname }
);
video.on('info', function (info) {
const _data = {
thumbnail: info.thumbnails[info.thumbnails.length - 1].url,
size: info.size / 1024 / 1024
};
});
I found a solution. I uninstall "youtube-dl" and reinstalled it. This issue is related to a plugin update
Update
Since the youtube-dl binary is updated regularly, you can run npm run update to check for and download any updates for it. You can also require youtube-dl/lib/downloader in your app if you'd like to place youtube-dl binary in a specific directory and control when it gets updates.
Related
I'm using the fluent-ffmpeg library in Node to automatically generate a single thumbnail at the halfway mark of a given video file.
const screenshot = async (pathToFile: string) => {
// Generate a temporary file path outside of the working directory with the extension .jpg
const tempFileName = tmp.tmpNameSync({ postfix: ".jpg" });
try{
await new Promise((resolve, reject) => {
ffmpeg(pathToFile)
.thumbnail({
// This works fine when NOT using tmpNameSync
filename: tempFileName,
count: 1,
timestamps: ["50%"]
})
.on("end", resolve)
.on("error", reject);
});
} catch(err){
console.log(err);
return null;
}
return tempFileName;
};
This implementation works very well when I'm using a "non-temporary" output path, such as /path/to/thumbnail.jpg. But, when I use a library such as tmp to generate a temporary file name outside of the working directory, ffmpeg throws an error.
Error: ffmpeg exited with code 1: av_interleaved_write_frame(): Input/output error
frame= 1 fps=0.0 q=7.8 size=N/A time=00:00:00.04 bitrate=N/A speed=0.152x
frame= 1 fps=0.0 q=7.8 Lsize=N/A time=00:00:00.04 bitrate=N/A speed=0.141x
video:119kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!
I cannot seem to find anything about ffmpeg struggling with accessing temporary directories online, and using the command directly in the terminal works as expected, so I don't believe this to be a permissions issue. Although, I may be going about this incorrectly.
This is the full ffmpeg command that fluent-ffmpeg generates (reduced filenames so it doesn't look horrible):
ffmpeg -ss 14.118271 -i /var/folders/__/XYZ/T/tmp-XYZ/tmp-XYZ -y -filter_complex scale=w=trunc(oh*a/2)*2:h=720[size0];[size0]split=1[screen0] -vframes 1 -map [screen0] var/folders/__/XYZ/T/tmp-XYZ.jpg
After hours of debugging, I found that the problem was a result of two things.
Firstly, ffmpeg and os.tmpdir() do not mix on MacOS.
The tmpdir method generates a symlink when using MacOS instead of an absolute path, which ffmpeg doesn't seem to like. Although, this seems to be inconsistent in when it does and doesn't affect the outcome.
Regardless, the fix for this is simple.
const fixSymlinkPath = (path: string) => {
// If the current platform is MacOS, prefix the path generated with /private.
// This is the true location of the path.
return process.platform === "darwin"
? `/private${path}`
: path;
};
// Use like so.
let path = fixSymlinkPath(tmp.tmpNameSync());
Secondly, (and this is something I should've noticed earlier) fluent-ffmpeg strips leading / from the filename property, resulting in a relative path and not an absolute one.
This effectively meant that ffmpeg was outputting to a non-existent directory inside __DIRNAME.
ffmpeg(pathToFile).thumbnail({
folder: "/", // Ensure absolute path, essentially.
filename: tempFileName,
count: 1,
timestamps: ["50%"]
});
Hopefully this helps someone down the track.
I received this error while run the back end server of Cube js. using npm run dev to started the server. while accessing a given link. It shows error like below. Help me to resolve
Cannot GET /cubejs-api/v1
There's no such API path /cubejs-api/v1. I believe you're looking for /cubejs-api/v1/load: https://cube.dev/docs/rest-api#api-reference-v-1-load.
This misconception comes because of the following code generated by CubeJS:
const cubejsApi = cubejs(
"<API Auth>",
{ apiUrl: API_URL + "/cubejs-api/v1" }
);
What you in fact want to do on Postman or what have you is use the following url to run queries add load after v1.
Example
{{HOST}}/cubejs-api/v1/load?query={
"measures": [
"UserOrderValue.minDate",
"UserOrderValue.maxDate",
"UserOrderValue.lastWeek",
"UserOrderValue.lastMonth",
"UserOrderValue.lastQuarter",
"UserOrderValue.lastYear"
]
}
I use the following command when building an ionic project for desktop
ionic cordova build browser --prod
Which results in the following file being generated
build/main.js
However I would like to be able to add a version number to the generated file automatically as part of the build process. So would end up with something like
build/main.js?version=1.00
as to avoid needing to clear the browser cache after every prod build.
Is there a flag for this, or is it something I must do manually?
Any advice would be great!
EDIT:
My solution is on GitHub for anyone interested!
https://github.com/RichardM99/ionic-3-version-build-file-hook
Here's some advice - You can create a cordova hook.
Hooks are scripts that you want to be executed at different stages of the build process. In your case, you are looking at a script which renames the main.js file after the build event is finished, or in other words a 'after_build' type hook.
The script will usually be a Node.js file, although you can have other types of scripts executed as well.
One more thing. Since you want to get around cache, you wont be renaming the file itself. What you will want to do is rather replace the reference to "main.js" in you "index.html" to include a random or maybe your actual version number.
I have pointed you in a direction, but won't spoonfeed. Look up documentation on cordova hooks. They are super simple if you understand Javascript/Node
Something like this should get the job done:
var index_orig = fs.readFileSync(path-to-index.html, 'utf8');
var index_new = index_orig.replace("main.js", "main.js?version="+version_num);
fs.writeFileSync(path-to-index.html, index_new, 'utf8');
If you want the actual build number, you can read your config.xml and parse it to get it's value.
Hope it helps.
I wrote blog long time ago
In my build pipeline i have command to set version
version "$(app.versionPrefix)$(Build.BuildNumber)"
$(app.versionPrefix) - is a prefix version such as 0.1.
$(Build.BuildNumber) - is build version
Then I have environment file
export const environment = {
apiUrl: 'https://....',
production: true,
version: '0.0.57'
}
Then i have js script to update version in environment and config.xml
var replace = require('replace-in-file');
var package = require("./package.json");
var buildVersion = package.version;
const options = {
files: ['config.xml'],
from: /" version="([0-9]*.[0-9]*.[0-9]*)"/g,
to: "\" version=\""+ buildVersion + "\"",
allowEmptyPaths: false,
};
const optionsEnv = {
files: ['src/environments/environment.prod.ts'],
from: /version: '(.*)'/g,
to: "version: '"+ buildVersion + "' ",
allowEmptyPaths: false,
};
try {
let changedFiles = replace.sync(options);
if (changedFiles == 0) {
throw "Please make sure that file '" + options.files + "' has \"version: ''\"";
}
changedFiles = replace.sync(optionsEnv);
if (changedFiles == 0) {
throw "Please make sure that file '" + optionsEnv.files + "' has \"version: ''\"";
}
console.log('Build version set: "' + options.to + '"');
}
catch (error) {
console.error('Error occurred:', error);
throw error
}
NOTE: you need to install plugin replace-in-file
Then in build pipe line I am running this script
node ./replace.build.js
In your case if you need only for browser you can tune script.
I'm trying to use Meteor 1.4 with Cordova (mobile support) to read files on my android phone.
I've got a small Meteor app running on my phone (via meteor run android-device). I have also created a small text file in the app's private storage using adb shell and run-as.
I can read the file if I call getFile('a'), but I can't find any way to use cordova.file.dataDirectory (even with WebAppLocalServer.localFileSystemUrl) as recommended in the Meteor guide. I get FileError {code: 5} (ENCODING_ERR).
Here's the JS console output from the Chrome inspector when I click the button in my app:
This repros on both Android 5 and 6.
My dev environment is 64-bit Ubuntu 14.04 LTS.
App Info for my app reports it has these permissions:
modify or delete the contents of your SD card
read the contents of your SD card
The app uses the cordova file plugin version 4.2.0.
Dup? How to read/write a file in Meteor-Cordova?
This does work in the chrome://inspect console via USB debugging: HTTP.call('GET', 'http://localhost:12640/local-filesystem/data/user/0/com.adammonsen.app/files/a', {}, function (e,r) {console.error(e); console.log(r)});
output is Object {statusCode: 200, content: "in external dir↵", headers: Object, data: null}
Got it. The trick is to use window.resolveLocalFileSystemURL() to get at the filesystem. Here's how to get at a file on external storage. My original question was about app-private storage. If you're looking for that, just use the cordova.file.dataDirectory instead of cordova.file.externalDataDirectory.
function reportError(err) {
console.error(err);
}
function readFile(file) {
var reader = new FileReader();
reader.onloadend = function() {
console.log('read file! contents: ' + this.result);
};
reader.readAsText(file);
}
function processFileEntry(fileEntry) {
fileEntry.file(file => {
readFile(file);
}, reportError);
}
Template.hello.events({
'click button'(event, instance) {
// increment the counter when button is clicked
instance.counter.set(instance.counter.get() + 1);
if (Meteor.isCordova) {
// aaaaaand do some other stuff
const path = cordova.file.externalDataDirectory + 'a';
window.resolveLocalFileSystemURL(path, fileEntry => {
console.log('fileEntry: ', fileEntry);
processFileEntry(fileEntry);
}, reportError);
}
},
});
See https://github.com/meonkeys/cordova-file-test/tree/solution for a full working example and instructions.
Make sure AndroidExtraFilesystems includes files-external. I used this line in my mobile-config.js:
App.setPreference('AndroidExtraFilesystems', 'files,files-external');
I'd love to understand the difference between the APIs, but for now I'm just happy I found something that works reliably.
I'm using Grunt to kick off a unit-test framework (Intern), which ultimately pipes another node.js process that I'm then using Charm to output results to the screen. I'm having to pass in the terminal size information from a Grunt config option, but it's a bit messy and I'd like to try and get the terminal size from within the piped process, but the standard process.stdout.cols/getWindowSize are simply unavailable as the piped process doesn't register as TTY (although Charm works fine with it all).
Any suggestions?
EDIT Just to be clear here ... the Grunt JavaScript file is running in the main node.js process, but the file I'm attempting to retrieve this info from (and where I'm therefore running people's suggested commands) is in a spawned child process.
Try these:
tput cols tells you the number of columns.
tput lines tells you the number of rows.
echo -e "lines\ncols"|tput -S to get both the lines and cols
There's stty, from coreutils:
$ stty size #60 120 <= sample output
While running the below code in terminal prints the cols:
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("tput cols", puts);
The pty.js module can make a child act like a regular terminal.
var pty = require('pty.js');
var term = pty.spawn('bash', [], {
name: 'xterm-color',
cwd: process.env.HOME,
env: process.env
});
term.on('data', function(data) {
console.log(data);
});
term.write('ls\r');
term.resize(100, 40);
term.write('ls /\r');
console.log(term.process);