use of com.yausername.youtubedl_android.YoutubeDLRequest in project MPlayer by abh80.
the class Function2 method download.
public static void download(String directory, String id, Function2<Float, Boolean, Void> callback) {
System.out.println(id);
Thread t = new Thread(() -> {
YoutubeDLRequest request = new YoutubeDLRequest("https://youtube.com/watch?v=" + id);
request.addOption("-o", directory + "/" + id + ".mp3");
request.addOption("--extract-audio");
request.addOption("--audio-format", "mp3");
try {
YoutubeDL.getInstance().execute(request, (progress, etaInSeconds, line) -> {
System.out.println(line);
callback.apply(progress, false);
});
} catch (YoutubeDLException | InterruptedException e) {
e.printStackTrace();
}
});
t.start();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
if (!t.isAlive()) {
callback.apply(100f, true);
timer.cancel();
}
}
}, 0, 2000);
}
use of com.yausername.youtubedl_android.YoutubeDLRequest in project androidtv-news by anenasa.
the class Channel method parse.
void parse() throws JSONException, IOException, YoutubeDLException, InterruptedException {
String url = getUrl();
YoutubeDLRequest request;
if (url.startsWith("https://hamivideo.hinet.net/channel/") && url.endsWith(".do")) {
String id = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));
OkHttpClient okHttpClient = new OkHttpClient();
Request okHttpRequest = new Request.Builder().url("https://hamivideo.hinet.net/api/play.do?freeProduct=1&id=" + id).build();
Response response = okHttpClient.newCall(okHttpRequest).execute();
JSONObject object = new JSONObject(response.body().string());
request = new YoutubeDLRequest(object.getString("url"));
} else {
request = new YoutubeDLRequest(url);
}
request.addOption("-f", getFormat());
if (!getHeader().isEmpty()) {
String[] headers = getHeader().split("\\\\r\\\\n");
for (String header : headers) {
request.addOption("--add-header", header);
}
}
VideoInfo streamInfo = YoutubeDL.getInstance().getInfo(request);
setVideo(streamInfo.getUrl());
}
Aggregations