(experimental) Download tracks using curl
std.net.curl seems to cause various issues in this case, and it is probably easier to interface with curl directly.
This commit is contained in:
parent
84d5fe939f
commit
169dcd9897
24
source/app.d
24
source/app.d
|
@ -1,9 +1,10 @@
|
||||||
import std.stdio, std.regex, std.json, std.file, std.datetime, std.conv, std.process, std.net.curl, std.string;
|
import std.stdio, std.regex, std.json, std.file, std.datetime, std.conv, std.process, std.net.curl, std.string;
|
||||||
import qobuz.api;
|
import qobuz.api;
|
||||||
|
import etc.c.curl;
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
string VERSION = "1.2";
|
string VERSION = "1.4";
|
||||||
|
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
writefln("Usage: %s <album id or url>", args[0]);
|
writefln("Usage: %s <album id or url>", args[0]);
|
||||||
|
@ -126,10 +127,25 @@ int main(string[] args)
|
||||||
"-metadata", "albumartist="~artist, "-metadata", "discnumber="~discNum, "-metadata", "tracktotal="~tracks.length.text,
|
"-metadata", "albumartist="~artist, "-metadata", "discnumber="~discNum, "-metadata", "tracktotal="~tracks.length.text,
|
||||||
"-metadata", "disctotal="~discs.text, relPath],
|
"-metadata", "disctotal="~discs.text, relPath],
|
||||||
Redirect.stdin | Redirect.stderr | Redirect.stdout);
|
Redirect.stdin | Redirect.stderr | Redirect.stdout);
|
||||||
foreach (chunk; byChunkAsync(url, 1024)) {
|
|
||||||
pipes.stdin.rawWrite(chunk);
|
extern(C) static size_t writefunc(const ubyte* data, size_t size, size_t nmemb, void* p) {
|
||||||
pipes.stdin.flush;
|
auto pp = *(cast(ProcessPipes*) p);
|
||||||
|
pp.stdin.rawWrite(data[0..size*nmemb]);
|
||||||
|
pp.stdin.flush();
|
||||||
|
return size*nmemb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CURL* curl;
|
||||||
|
CURLcode res;
|
||||||
|
curl = curl_easy_init();
|
||||||
|
curl_easy_setopt(curl, CurlOption.url, toStringz(url));
|
||||||
|
curl_easy_setopt(curl, CurlOption.followlocation, 1L);
|
||||||
|
curl_easy_setopt(curl, CurlOption.writefunction, cast(void*) &writefunc);
|
||||||
|
curl_easy_setopt(curl, CurlOption.writedata, cast(void*) &pipes);
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
assert(res == CurlError.ok);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
|
||||||
pipes.stdin.close;
|
pipes.stdin.close;
|
||||||
wait(pipes.pid);
|
wait(pipes.pid);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue