如何将从 youtube-dl 下载的 youtube 视频的文件名保存在变量中
How to save the filename of youtube video downloaded from youtube-dl in a variable
我正在制作一个 android 应用程序,它使用 youtube-dll 从 youtube 中提取音频。我想将该 YouTube 视频的标题保存在一个变量中,但是命令 request.option("--get-title") 没有返回任何内容,我不知道如何将它保存在一个变量中。有人可以帮忙吗?这是代码
YoutubeDLRequest request = new YoutubeDLRequest(url);
File youtubeDLDir = getDownloadLocation();
request.setOption("-o", youtubeDLDir.getAbsolutePath() + "/%(title)s.%
(ext)s");
request.setOption("-x");
request.setOption("--prefer-ffmpeg");
request.setOption("--add-metadata");
request.setOption("--metadata-from-title", "%(artist)s - %(title)s");
request.setOption("--embed-thumbnail");
request.setOption("--audio-format", "mp3");
您必须使用静态 YoutubeDL.getVideoInfo(String url)
方法。之后,您可以将其保存到 VideoInfo
实例中,或者直接使用 return 值中的成员变量。
此代码段将为您提供视频的标题和扩展名
String[] getVideoInfo(String url) throws YoutubeDLException, InterruptedException {
VideoInfo streamInfo = YoutubeDL.getInstance().getInfo(url);
return new String[]{streamInfo.getTitle(), streamInfo.getExt()};
}
然后像这样访问它
String title = getVideoInfo(url)[0];
String extension = getVideoInfo(url)[1];
我正在制作一个 android 应用程序,它使用 youtube-dll 从 youtube 中提取音频。我想将该 YouTube 视频的标题保存在一个变量中,但是命令 request.option("--get-title") 没有返回任何内容,我不知道如何将它保存在一个变量中。有人可以帮忙吗?这是代码
YoutubeDLRequest request = new YoutubeDLRequest(url);
File youtubeDLDir = getDownloadLocation();
request.setOption("-o", youtubeDLDir.getAbsolutePath() + "/%(title)s.%
(ext)s");
request.setOption("-x");
request.setOption("--prefer-ffmpeg");
request.setOption("--add-metadata");
request.setOption("--metadata-from-title", "%(artist)s - %(title)s");
request.setOption("--embed-thumbnail");
request.setOption("--audio-format", "mp3");
您必须使用静态 YoutubeDL.getVideoInfo(String url)
方法。之后,您可以将其保存到 VideoInfo
实例中,或者直接使用 return 值中的成员变量。
此代码段将为您提供视频的标题和扩展名
String[] getVideoInfo(String url) throws YoutubeDLException, InterruptedException {
VideoInfo streamInfo = YoutubeDL.getInstance().getInfo(url);
return new String[]{streamInfo.getTitle(), streamInfo.getExt()};
}
然后像这样访问它
String title = getVideoInfo(url)[0];
String extension = getVideoInfo(url)[1];