I manage to download embadded video from terminal but when I call it from java program is not working. this I use from java
for(String url: reffererSet) {
String command = "youtube-dl " url;
System.out.println(command);
Process proc = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = "";
while((line = reader.readLine()) != null) {
System.out.print(line "\n");
}
}
youtube-dl https://player.vimeo.com/video/2352345 --referer 'https://reffererUrl.html'
When I execute from terminal
[vimeo] 2352345: Downloading webpage
[vimeo] 2352345: Extracting information
[vimeo] 2352345: Downloading JSON metadata
WARNING: Unable to download JSON metadata: HTTP Error 404: Not Found
and start to download the video when I run from java I see only this output:
[vimeo] 2352345: Downloading webpage
And skip to next link without downloading the video
CodePudding user response:
Your most likely solution is to use the full path of youtube-dl
, so on Linux will probably be /usr/bin/youtube-dl
. This is because Runtime.getRuntime().exec
is actually running a file and not a bash shell.
If that doesn't fix your problem then you should also write the error stream of the process to the standard out and that will tell you the problem.
CodePudding user response:
As ben said, you should use the full path. Programs are not always in the same /usr/bin/* folder. For future projects you should try to use /usr/bin/bash -c "command here"
.