From c8507c3c8a0238db75d33a8ac232aeba868fbdac Mon Sep 17 00:00:00 2001 From: Anonymous Date: Tue, 16 May 2017 11:28:09 +0100 Subject: [PATCH] misc fixes, album art --- source/app.d | 19 ++++++++++++++++--- source/qobuz/api.d | 11 +++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/source/app.d b/source/app.d index a6087ad..772df02 100644 --- a/source/app.d +++ b/source/app.d @@ -3,6 +3,8 @@ import qobuz.api; int main(string[] args) { + string VERSION = "1.0"; + if (args.length != 2) { writefln("Usage: %s ", args[0]); return -1; @@ -49,7 +51,12 @@ int main(string[] args) } string dirName = artist~" - "~title~" ("~year~") [WEB FLAC]"; - mkdir(dirName); + try { + mkdir(dirName); + } catch (Exception e) { + writeln("Could not create directory: `"~dirName~"`. Does it exist already?"); + return -9; + } foreach (i, track; tracks) { auto num = (i+1).text; @@ -67,9 +74,9 @@ int main(string[] args) } try { - auto pipes = pipeProcess([magic["ffmpeg"].str, "-i", "-", "-metadata", "title="~trackName, "-metadata", "author="~artist, + auto pipes = pipeProcess([magic["ffmpeg"].str, "-i", "-", "-metadata", "title="~trackName, "-metadata", "artist="~artist, "-metadata", "album="~title, "-metadata", "year="~year, "-metadata", "track="~num, "-metadata", "genre="~genre, - dirName~"/"~num~" "~trackName~".flac"], Redirect.stdin | Redirect.stderr | Redirect.stdout); + "-metadata", "comment=qobuz-get "~VERSION, dirName~"/"~num~" "~trackName~".flac"], Redirect.stdin | Redirect.stderr | Redirect.stdout); foreach (chunk; byChunkAsync(url, 1024)) { pipes.stdin.rawWrite(chunk); pipes.stdin.flush; @@ -83,5 +90,11 @@ int main(string[] args) writeln("Done!"); } + // Get album art + write("Getting album art... "); + stdout.flush; + download(id.getArtUrl, dirName~"/cover.jpg"); + writeln("Done!"); + return 0; } diff --git a/source/qobuz/api.d b/source/qobuz/api.d index e4d0867..d58f31d 100644 --- a/source/qobuz/api.d +++ b/source/qobuz/api.d @@ -80,3 +80,14 @@ string getDownloadUrl(JSONValue magic, string id) { assert(0); } + +string getArtUrl(string id) { + if (id.length != 13) { + writeln("Album ID of invalid length given!"); + exit(-10); + } + + string a = id[11..13]; + string b = id[9..11]; + return "http://static.qobuz.com/images/covers/"~a~"/"~b~"/"~id~"_max.jpg"; +}