feat: add audio only option
This commit is contained in:
parent
5e3f832d3e
commit
8629c93766
|
@ -5,11 +5,13 @@ class EnqueueTask {
|
|||
var url:String;
|
||||
var outname:Null<String>;
|
||||
var prepend:Bool;
|
||||
var audio_only:Bool;
|
||||
|
||||
public function new(url:String, outname:Null<String>, prepend:Bool) {
|
||||
public function new(url:String, outname:Null<String>, prepend:Bool, audio_only:Bool) {
|
||||
this.url = url;
|
||||
this.outname = outname;
|
||||
this.prepend = prepend;
|
||||
this.audio_only = audio_only;
|
||||
}
|
||||
|
||||
public function send():Void {
|
||||
|
|
|
@ -27,7 +27,6 @@ function onEnqSubmit(e:Dynamic):Void {
|
|||
e.preventDefault();
|
||||
|
||||
var url_inp = cast(Browser.document.getElementById("url_inp"), InputElement);
|
||||
|
||||
var outname = cast(Browser.document.getElementById("outname_inp"), InputElement).value;
|
||||
|
||||
if (url_inp.value.length == 0) {
|
||||
|
@ -38,7 +37,8 @@ function onEnqSubmit(e:Dynamic):Void {
|
|||
new EnqueueTask(
|
||||
url_inp.value,
|
||||
outname.length == 0 ? null : outname,
|
||||
cast(Browser.document.getElementById("prepend_switch"), InputElement).checked
|
||||
cast(Browser.document.getElementById("prepend_switch"), InputElement).checked,
|
||||
cast(Browser.document.getElementById("audio_only_switch"), InputElement).checked
|
||||
).send();
|
||||
|
||||
url_inp.value = "";
|
||||
|
|
|
@ -5,6 +5,7 @@ const State = @import("State.zig");
|
|||
pub const Task = struct {
|
||||
url: []const u8,
|
||||
outname: ?[]const u8,
|
||||
audio_only: bool,
|
||||
};
|
||||
|
||||
state: *State,
|
||||
|
@ -40,6 +41,7 @@ pub fn pushTask(self: *DownloadQueue, task: Task, prepend: bool) !void {
|
|||
.outname = blk: {
|
||||
break :blk try std.heap.c_allocator.dupe(u8, task.outname orelse break :blk null);
|
||||
},
|
||||
.audio_only = task.audio_only,
|
||||
} };
|
||||
|
||||
self.m.lock();
|
||||
|
@ -105,6 +107,10 @@ fn next(self: *DownloadQueue) !void {
|
|||
try argv.append("--format");
|
||||
try argv.append("bestvideo[height<=1080]+bestaudio/best[height<=1080]");
|
||||
|
||||
if (task.audio_only) {
|
||||
try argv.append("--extract-audio");
|
||||
}
|
||||
|
||||
var outfile_buf: [512]u8 = undefined;
|
||||
if (task.outname) |outname| {
|
||||
try argv.append("--output");
|
||||
|
|
|
@ -64,3 +64,7 @@ button.vid_del_btn:hover {
|
|||
ul {
|
||||
list-style-type: square;
|
||||
}
|
||||
|
||||
.audio_only_txt {
|
||||
color: #ff5555;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,10 @@ const inferred_html =
|
|||
\\<span class="gray"><inferred></span>
|
||||
;
|
||||
|
||||
const audio_only_prefix_html =
|
||||
\\<span class="audio_only_txt">Audio Only </span>
|
||||
;
|
||||
|
||||
pub fn routeCb(comptime routeFn: anytype, comptime has_state: bool) *anyopaque {
|
||||
return @intToPtr(*anyopaque, @ptrToInt(&struct {
|
||||
fn f(
|
||||
|
@ -81,10 +85,14 @@ pub fn indexRoute(
|
|||
|
||||
if (state.downloads.active_task) |active| {
|
||||
try w.print(
|
||||
\\<p>Active task: <b>{s}</b> -> <b>{s}</b></p>
|
||||
\\<p>Active task: <b>{s}{s}</b> -> <b>{s}</b></p>
|
||||
\\<hr>
|
||||
,
|
||||
.{ active.url, active.outname orelse inferred_html },
|
||||
.{
|
||||
if (active.audio_only) audio_only_prefix_html else "",
|
||||
active.url,
|
||||
active.outname orelse inferred_html,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -94,14 +102,18 @@ pub fn indexRoute(
|
|||
);
|
||||
|
||||
var task = state.downloads.tasks.last;
|
||||
while (task != null) {
|
||||
while (task) |t| {
|
||||
try w.print(
|
||||
\\<tr><td>{s}</td><td>{s}</td></tr>
|
||||
\\<tr><td>{s}{s}</td><td>{s}</td></tr>
|
||||
,
|
||||
.{ task.?.data.url, task.?.data.outname orelse inferred_html },
|
||||
.{
|
||||
if (t.data.audio_only) audio_only_prefix_html else "",
|
||||
t.data.url,
|
||||
t.data.outname orelse inferred_html,
|
||||
},
|
||||
);
|
||||
|
||||
task = task.?.prev;
|
||||
task = t.prev;
|
||||
}
|
||||
|
||||
try w.writeAll(
|
||||
|
@ -122,6 +134,7 @@ pub fn indexRoute(
|
|||
\\ <input type="text" placeholder="URL" id="url_inp"><br>
|
||||
\\ <input type="text" placeholder="output name" id="outname_inp"><br>
|
||||
\\ <input type="checkbox" id="prepend_switch">Prepend<br>
|
||||
\\ <input type="checkbox" id="audio_only_switch">Audio Only<br>
|
||||
\\ <input type="submit" id="enqueue_btn" value="Enqueue">
|
||||
\\</form>
|
||||
\\<button id="pause_btn"></button>
|
||||
|
@ -227,6 +240,8 @@ pub fn indexJsonRoute(
|
|||
pub const ApiTask = struct {
|
||||
url: []const u8,
|
||||
outname: ?[]const u8,
|
||||
audio_only: bool = false,
|
||||
|
||||
prepend: bool = false,
|
||||
};
|
||||
|
||||
|
@ -267,7 +282,7 @@ pub fn vidsRoute(
|
|||
|
||||
std.log.info("adding {s} to queue", .{task.url});
|
||||
try state.downloads.pushTask(
|
||||
.{ .url = task.url, .outname = task.outname },
|
||||
.{ .url = task.url, .outname = task.outname, .audio_only = task.audio_only },
|
||||
task.prepend,
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue