我正在爲Raspberry Pi開發一個Java項目,並且需要幫助讓Runtime正常工作。Java Runtime.getRuntime()。exec()youtube2mp3
youtube2mp3利用YouTube-DL和ffmpeg的(INFO:http://jeffreyv.hubpages.com/hub/Youtube-to-MP3-on-Ubuntu-Linux)
我修改劇本有點一邊寫上我的iMac代碼:
x=youtube-dl-$RANDOM-$RANDOM.flv
youtube-dl --output=$x --format=18 "$1"
ffmpeg -i $x -acodec libmp3lame -ac 2 -ab 128k -vn -y "$2"
mv "$2" ~/Downloads
rm $x
rm *.mp4
然後我累調用它在我的servlet開始下載:
try {
String command = "sudo /usr/local/bin/youtube2mp3 \"" + requestedSong.getTrackUrl() +"\" \"" + requestedSong.getTrackArtist() + "-" + requestedSong.getTrackTitle() + ".mp3\"";
System.out.println("CMD: " + command);
//Process child = Runtime.getRuntime().exec(new String[]{"/usr/local/bin/youtube2mp3", "\"" + requestedSong.getTrackUrl() + "\"", "\"" + requestedSong.getTrackArtist() + "-" + requestedSong.getTrackTitle() + ".mp3 \""});
Process child = Runtime.getRuntime().exec(command);
child.waitFor();
InputStream in = child.getInputStream();
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(in)));
String line = "";
while (sc.hasNextLine()) {
line = sc.nextLine();
System.out.println("INFO: " + line);
}
} catch (InterruptedException ex) {
Logger.getLogger(ControlServlet.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ControlServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
該命令在運行時相當詳細,但我的掃描器對象沒有拾取任何東西。我試着把這段代碼留在servlet中,並且使用線程,但是兩次都失敗了。
的命令不需要sudo來運行,我已經改變sudoers文件不要求對管理員的密碼
我(我使用運行時()運行ARP掃描早些時候在節目中)能夠將規則複製並粘貼到「命令」輸出的終端中,並且運行良好。
任何幫助將不勝感激。
UPDATE
這裏是運行youtube2mp3命令的輸出:
sudo /usr/local/bin/youtube2mp3 "http://www.youtube.com/watch?v=X_tbksFYhl4" "test-none.mp3"
[youtube] Setting language
[youtube] X_tbksFYhl4: Downloading video webpage
[youtube] X_tbksFYhl4: Downloading video info webpage
[youtube] X_tbksFYhl4: Extracting video information
[download] Destination: youtube-dl-7433-2196.flv
[download] 100.0% of 39.17M at 1.83M/s ETA 00:00
ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
built on Sep 6 2012 13:52:52 with clang 4.0 ((tags/Apple/clang-421.0.60))
configuration: --prefix=/usr/local/Cellar/ffmpeg/0.11.1 --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 51. 54.100/51. 54.100
libavcodec 54. 23.100/54. 23.100
libavformat 54. 6.100/54. 6.100
libavdevice 54. 0.100/54. 0.100
libavfilter 2. 77.100/2. 77.100
libswscale 2. 1.100/2. 1.100
libswresample 0. 15.100/0. 15.100
libpostproc 52. 0.100/52. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'youtube-dl-7433-2196.flv':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isomavc1mp42
creation_time : 2010-01-17 00:16:32
Duration: 00:09:59.23, start: 0.000000, bitrate: 548 kb/s
Stream #0:0(und): Audio: aac (mp4a/0x6134706D), 44100 Hz, stereo, s16, 113 kb/s
Metadata:
creation_time : 2010-01-17 00:16:32
handler_name : (C) 2007 Google Inc. v08.13.2007.
Stream #0:1(und): Video: h264 (Constrained Baseline) (avc1/0x31637661), yuv420p, 480x270 [SAR 1:1 DAR 16:9], 432 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc
Metadata:
creation_time : 2010-01-17 00:16:33
handler_name : (C) 2007 Google Inc. v08.13.2007.
Output #0, mp3, to 'test-none.mp3':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isomavc1mp42
TDEN : 2010-01-17 00:16:32
TSSE : Lavf54.6.100
Stream #0:0(und): Audio: mp3, 44100 Hz, stereo, s16, 128 kb/s
Metadata:
creation_time : 2010-01-17 00:16:32
handler_name : (C) 2007 Google Inc. v08.13.2007.
Stream mapping:
Stream #0:0 -> #0:0 (aac -> libmp3lame)
Press [q] to stop, [?] for help
size= 9364kB time=00:09:59.22 bitrate= 128.0kbits/s
video:0kB audio:9363kB global headers:0kB muxing overhead 0.006039%
rm: *.mp4: No such file or directory
爲什麼在嘗試讀取標準輸出之前等待進程完成? –
我想確保我抓住了一切。我用arp-scan做了同樣的事情,以確保我得到了所有Mac地址和/或錯誤。這不應該導致問題。 – Ctcoggin