Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
Al Beano | 7df418a447 | |
Al Beano | 35b0e9f525 | |
Al Beano | 169dcd9897 | |
Al Beano | 84d5fe939f | |
Al Beano | fab4c19ad9 | |
Al Beano | 2c950c6fe9 | |
Al Beano | 08046498b1 | |
Al Beano | 75a1a7521a | |
Al Beano | 86e228cacf | |
Al Beano | 523e362cb9 | |
Al Beano | 85735fc63e |
|
@ -7,3 +7,4 @@ __test__*__
|
|||
qobuz-get
|
||||
*.swp
|
||||
magic.json
|
||||
qobuz-get.exe
|
||||
|
|
|
@ -4,6 +4,8 @@ Tool to download FLACs from qobuz.com.
|
|||
|
||||
## Setup
|
||||
|
||||
**If git.fuwafuwa.moe is down, click [here](https://github.com/whiteisthenewblack/qobuz-get/files/1599102/qobuz-get-win32-1.3.zip) for the latest Windows binary.**
|
||||
|
||||
Statically linked 64-bit Linux and Windows binaries are available in the [Releases](https://git.fuwafuwa.moe/albino/qobuz-get/releases) tab. On Linux, you should install sox, ffmpeg and mktorrent with your package manager, and insert the paths to the binaries (found using `which sox`, `which ffmpeg`, etc...) into magic.json.
|
||||
|
||||
There are three other values which must be inserted into magic.json. `app_id` and `app_secret` are listed on [this page](http://shell.cyberia.is/~albino/qobuz-creds.html). `user_auth_token` is specific to your qobuz account. See the bottom of this README for instructions on finding it. These values could change from time to time, so if qobuz-get stops working suddenly, you probably need to get new ones.
|
||||
|
@ -36,6 +38,6 @@ Check that the values in magic.json are correct, then ask for help on IRC. Conne
|
|||
|
||||
* Open http://play.qobuz.com in your browser and log in with your credentials.
|
||||
* Open the 'Network' tab of your browser's developer tools. (In Firefox, right click on page -> inspect element -> select the 'Network' tab)
|
||||
* Type any letter into the "Search" box at the top right of the page.
|
||||
* In the Network window, you should see a `GET` request beginning with `search`. Select it.
|
||||
* Open the page for any album.
|
||||
* In the Network window, you should see a `GET` request beginning with `get?album_id`. Select it.
|
||||
* You should see a list of headers on the right hand side (in Chrome, you need to click the "Headers" tab). Scroll down to the one which says `x-user-auth-token`. Select the content, and copy and paste it into magic.json. Done!
|
||||
|
|
112
source/app.d
112
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 qobuz.api;
|
||||
import etc.c.curl;
|
||||
|
||||
int main(string[] args)
|
||||
{
|
||||
string VERSION = "1.1";
|
||||
string VERSION = "1.4";
|
||||
|
||||
if (args.length != 2) {
|
||||
writefln("Usage: %s <album id or url>", args[0]);
|
||||
|
@ -38,7 +39,7 @@ int main(string[] args)
|
|||
try {
|
||||
title = album["title"].str;
|
||||
artist = album["artist"]["name"].str;
|
||||
genre = album["genres_list"][0].str;
|
||||
genre = album["genre"]["name"].str;
|
||||
auto releaseTime = SysTime.fromUnixTime(album["released_at"].integer, UTC());
|
||||
year = releaseTime.year.text;
|
||||
|
||||
|
@ -51,6 +52,8 @@ int main(string[] args)
|
|||
}
|
||||
|
||||
string dirName = artist~" - "~title~" ("~year~") [WEB FLAC]";
|
||||
dirName = dirName.replaceAll(regex("[\\?<>:\"/\\\\|\\*]"), "");
|
||||
|
||||
try {
|
||||
mkdir(dirName);
|
||||
} catch (Exception e) {
|
||||
|
@ -58,14 +61,24 @@ int main(string[] args)
|
|||
return -9;
|
||||
}
|
||||
|
||||
foreach (i, track; tracks) {
|
||||
auto num = (i+1).text;
|
||||
string url, trackName;
|
||||
auto discs = tracks[tracks.length - 1]["media_number"].integer;
|
||||
|
||||
foreach (track; tracks) {
|
||||
string url, num, discNum, trackName, trackArtist;
|
||||
try {
|
||||
num = track["track_number"].integer.text;
|
||||
discNum = track["media_number"].integer.text;
|
||||
trackName = track["title"].str;
|
||||
try {
|
||||
trackArtist = track["performer"]["name"].str;
|
||||
} catch (Exception e) {
|
||||
// Qobuz doesn't return a "performer" for all albums, and I'm not sure about
|
||||
// the best way to deal with this. Leaving blank for now.A
|
||||
trackArtist = "";
|
||||
}
|
||||
if (num.length < 2)
|
||||
num = "0"~num;
|
||||
writef(" [%s] %s... ", num, trackName);
|
||||
writef(" [%s/%s] %s... ", discNum, num, trackName);
|
||||
stdout.flush;
|
||||
url = getDownloadUrl(magic, track["id"].integer.text);
|
||||
} catch (Exception e) {
|
||||
|
@ -73,27 +86,89 @@ int main(string[] args)
|
|||
return -7;
|
||||
}
|
||||
|
||||
string discDir;
|
||||
if (discs > 1)
|
||||
discDir = dirName~"/Disc "~discNum;
|
||||
else
|
||||
discDir = dirName;
|
||||
|
||||
if (!discDir.exists || !discDir.isDir) {
|
||||
try {
|
||||
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,
|
||||
"-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;
|
||||
mkdir(discDir);
|
||||
} catch (Exception e) {
|
||||
writeln("Failed to create directory `"~discDir~"`.");
|
||||
return -11;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
auto fileName = trackName;
|
||||
fileName = fileName.replaceAll(regex("[\\?<>:\"/\\\\|\\*]"), "");
|
||||
auto relPath = discDir~"/"~num~" - "~fileName~".flac";
|
||||
|
||||
version (Windows) {
|
||||
// making up for NTFS/Windows inadequacy
|
||||
// can't really do much better than truncating, sorry.
|
||||
auto totalPath = getcwd() ~ relPath;
|
||||
if (totalPath.length > 255) {
|
||||
totalPath = totalPath[0..(totalPath.length - 4)];
|
||||
relPath = relPath[0..(relPath.length - 4)];
|
||||
while (totalPath.length > 250) {
|
||||
totalPath = totalPath[0..(totalPath.length - 1)];
|
||||
relPath = relPath[0..(relPath.length - 1)];
|
||||
}
|
||||
totalPath ~= ".flac";
|
||||
relPath ~= ".flac";
|
||||
}
|
||||
}
|
||||
|
||||
auto pipes = pipeProcess([magic["ffmpeg"].str, "-i", "-", "-metadata", "title="~trackName, "-metadata", "artist="~trackArtist,
|
||||
"-metadata", "album="~title, "-metadata", "date="~year, "-metadata", "track="~num, "-metadata", "genre="~genre,
|
||||
"-metadata", "albumartist="~artist, "-metadata", "discnumber="~discNum, "-metadata", "tracktotal="~tracks.length.text,
|
||||
"-metadata", "disctotal="~discs.text, relPath],
|
||||
Redirect.stdin | Redirect.stderr | Redirect.stdout);
|
||||
|
||||
extern(C) static size_t writefunc(const ubyte* data, size_t size, size_t nmemb, void* p) {
|
||||
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;
|
||||
wait(pipes.pid);
|
||||
} catch (Exception e) {
|
||||
writeln("Failed to download track! Check that ffmpeg is properly configured.");
|
||||
writeln(e.msg);
|
||||
return -8;
|
||||
}
|
||||
writeln("Done!");
|
||||
}
|
||||
|
||||
string firstDisc;
|
||||
if (discs > 1)
|
||||
firstDisc = dirName~"/Disc 1";
|
||||
else
|
||||
firstDisc = dirName;
|
||||
|
||||
// Get album art
|
||||
write("Getting album art... ");
|
||||
stdout.flush;
|
||||
download(id.getArtUrl, dirName~"/cover.jpg");
|
||||
download(id.getArtUrl, firstDisc~"/cover.jpg");
|
||||
for (int i = 2; i <= discs; i++) {
|
||||
copy(firstDisc~"/cover.jpg", dirName~"/Disc "~i.text~"/cover.jpg");
|
||||
}
|
||||
writeln("Done!");
|
||||
|
||||
string choice;
|
||||
|
@ -104,12 +179,15 @@ int main(string[] args)
|
|||
}
|
||||
if (choice == "y") {
|
||||
try {
|
||||
auto full = execute([magic["sox"].str, dirName~"/01 "~tracks[0]["title"].str~".flac", "-n", "remix", "1", "spectrogram",
|
||||
auto trackName = tracks[0]["title"].str;
|
||||
trackName = trackName.replaceAll(regex("[\\?<>:\"/\\\\|\\*]"), "");
|
||||
|
||||
auto full = execute([magic["sox"].str, firstDisc~"/01 - "~trackName~".flac", "-n", "remix", "1", "spectrogram",
|
||||
"-x", "3000", "-y", "513", "-z", "120", "-w", "Kaiser", "-o", "SpecFull.png"]);
|
||||
auto zoom = execute([magic["sox"].str, dirName~"/01 "~tracks[0]["title"].str~".flac", "-n", "remix", "1", "spectrogram",
|
||||
auto zoom = execute([magic["sox"].str, firstDisc~"/01 - "~trackName~".flac", "-n", "remix", "1", "spectrogram",
|
||||
"-X", "500", "-y", "1025", "-z", "120", "-w", "Kaiser", "-S", "0:30", "-d", "0:04", "-o", "SpecZoom.png"]);
|
||||
if (full.status != 0 || zoom.status != 0)
|
||||
throw new Exception("mktorrent failed");
|
||||
throw new Exception("sox failed");
|
||||
writeln("SpecFull.png and SpecZoom.png written.");
|
||||
} catch (Exception e) {
|
||||
writeln("Generating spectrals failed! Is sox configured properly?");
|
||||
|
@ -141,3 +219,5 @@ int main(string[] args)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ex: set tabstop=2 expandtab:
|
||||
|
|
|
@ -91,3 +91,5 @@ string getArtUrl(string id) {
|
|||
string b = id[9..11];
|
||||
return "http://static.qobuz.com/images/covers/"~a~"/"~b~"/"~id~"_max.jpg";
|
||||
}
|
||||
|
||||
// ex: set tabstop=2 expandtab:
|
||||
|
|
Loading…
Reference in New Issue