From 2c950c6fe9570685ed765cf5cd01e4840e32446c Mon Sep 17 00:00:00 2001 From: Al Beano Date: Fri, 8 Dec 2017 18:03:39 +0000 Subject: [PATCH] Limit file name length on Windows --- .gitignore | 1 + source/app.d | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 955424f..153d943 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __test__*__ qobuz-get *.swp magic.json +qobuz-get.exe diff --git a/source/app.d b/source/app.d index 1535a88..3c64b4e 100644 --- a/source/app.d +++ b/source/app.d @@ -103,10 +103,28 @@ int main(string[] args) 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, discDir~"/"~num~" - "~fileName~".flac"], + "-metadata", "disctotal="~discs.text, relPath], Redirect.stdin | Redirect.stderr | Redirect.stdout); foreach (chunk; byChunkAsync(url, 1024)) { pipes.stdin.rawWrite(chunk); @@ -116,6 +134,7 @@ int main(string[] args) wait(pipes.pid); } catch (Exception e) { writeln("Failed to download track! Check that ffmpeg is properly configured."); + writeln(e.msg); return -8; } writeln("Done!");