Compare commits
No commits in common. "cb8939a3e3fab0177a79b0e2fb106f01e176036b" and "01fc3a0551d985b94a19d1c40ef384ef825fd698" have entirely different histories.
cb8939a3e3
...
01fc3a0551
27
README.md
27
README.md
@ -38,22 +38,7 @@ https://github.com/nlohmann/json
|
|||||||
# eyeD3
|
# eyeD3
|
||||||
https://eyed3.readthedocs.io/en/latest/
|
https://eyed3.readthedocs.io/en/latest/
|
||||||
* For MP3 tagging
|
* For MP3 tagging
|
||||||
```
|
* TODO: Add info here
|
||||||
// Common
|
|
||||||
--encoding utf8
|
|
||||||
--preserve-file-times
|
|
||||||
|
|
||||||
// First Step - Remove Images
|
|
||||||
--remove-all-images
|
|
||||||
|
|
||||||
// Second Step - Change what is needed
|
|
||||||
--add-image "...":FRONT_COVER
|
|
||||||
--artist "..."
|
|
||||||
--album "..."
|
|
||||||
--title "..."
|
|
||||||
--track ...
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
# metaflac
|
# metaflac
|
||||||
https://xiph.org/flac/download.html
|
https://xiph.org/flac/download.html
|
||||||
@ -64,17 +49,17 @@ metaflac
|
|||||||
--preserve-modtime
|
--preserve-modtime
|
||||||
--no-utf8-convert
|
--no-utf8-convert
|
||||||
|
|
||||||
// First Step - Remove Pictures
|
// First Step - Remove Tags
|
||||||
--remove --block-type=PICTURE
|
|
||||||
|
|
||||||
// Second Step - Remove Tags
|
|
||||||
--remove-tag=TITLE
|
--remove-tag=TITLE
|
||||||
--remove-tag=ARTIST
|
--remove-tag=ARTIST
|
||||||
--remove-tag=ALBUM
|
--remove-tag=ALBUM
|
||||||
--remove-tag=TRACKNUMBER
|
--remove-tag=TRACKNUMBER
|
||||||
|
|
||||||
|
// Second Step - Remove Pictures
|
||||||
|
--remove --block-type=PICTURE
|
||||||
|
|
||||||
// Third Step - Add
|
// Third Step - Add
|
||||||
"--import-picture-from=3|image/jpeg|||/path/to/cover"
|
--import-picture-from=3|image/jpeg|||"/path/to/cover"
|
||||||
"--set-tag=TITLE=..."
|
"--set-tag=TITLE=..."
|
||||||
"--set-tag=ARTIST=..."
|
"--set-tag=ARTIST=..."
|
||||||
"--set-tag=ALBUM=..."
|
"--set-tag=ALBUM=..."
|
||||||
|
|||||||
6
TODO.md
6
TODO.md
@ -1 +1,5 @@
|
|||||||
* Add API Rate Limit
|
* Rate limit
|
||||||
|
* Use external tools
|
||||||
|
* Download and resize cover before tracks
|
||||||
|
* Tag tracks
|
||||||
|
* Update README with eyeD3
|
||||||
|
|||||||
14
common.cpp
14
common.cpp
@ -3,7 +3,6 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@ -188,16 +187,3 @@ string clean_filename(const string& s)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool exec_cmd(const string& cmd)
|
|
||||||
{
|
|
||||||
int error;
|
|
||||||
|
|
||||||
error = system(cmd.c_str());
|
|
||||||
if (0 != error)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|||||||
1
common.h
1
common.h
@ -19,6 +19,5 @@ void json_extract(const nlohmann::json& j, const std::string& key, bool& out);
|
|||||||
bool ensure_folder(const std::string& main_path, const std::string& folder);
|
bool ensure_folder(const std::string& main_path, const std::string& folder);
|
||||||
std::string trim_whitespace(const std::string& s);
|
std::string trim_whitespace(const std::string& s);
|
||||||
std::string clean_filename(const std::string& s);
|
std::string clean_filename(const std::string& s);
|
||||||
bool exec_cmd(const std::string& cmd);
|
|
||||||
|
|
||||||
#endif // COMMON_H_
|
#endif // COMMON_H_
|
||||||
|
|||||||
194
main.cpp
194
main.cpp
@ -15,111 +15,6 @@ void usage(const char *name)
|
|||||||
cout << "Usage: " << name << " [catalog id] ..." << endl;
|
cout << "Usage: " << name << " [catalog id] ..." << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
string gen_resize_command(const string& release_folder, const string& convert_exec)
|
|
||||||
{
|
|
||||||
string cmd;
|
|
||||||
|
|
||||||
cmd = convert_exec;
|
|
||||||
cmd += " \"";
|
|
||||||
cmd += build_fname(release_folder, "", "Cover.*");
|
|
||||||
cmd += "\" -resize 750x750 \"";
|
|
||||||
cmd += build_fname(release_folder, "", "Cover_small.jpg");
|
|
||||||
cmd += "\"";
|
|
||||||
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
string gen_mp3_clear(const string& filepath, const string& eyed3_exec)
|
|
||||||
{
|
|
||||||
string cmd;
|
|
||||||
|
|
||||||
cmd = eyed3_exec;
|
|
||||||
cmd += " --preserve-file-times --remove-all-images \"";
|
|
||||||
cmd += filepath;
|
|
||||||
cmd += "\" > /dev/null 2>&1";
|
|
||||||
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
string gen_mp3_set_tags(const string& filepath, const string& artist,
|
|
||||||
const string& title, const string& album, int track_num,
|
|
||||||
const string& cover_filepath, string eyed3_exec)
|
|
||||||
{
|
|
||||||
string cmd;
|
|
||||||
|
|
||||||
cmd = eyed3_exec;
|
|
||||||
cmd += " --encoding utf8 --preserve-file-times --add-image \"";
|
|
||||||
cmd += cover_filepath;
|
|
||||||
cmd += "\":FRONT_COVER --artist \"";
|
|
||||||
cmd += artist;
|
|
||||||
// cmd += "\" --album \"";
|
|
||||||
// cmd += album;
|
|
||||||
cmd += "\" --title \"";
|
|
||||||
cmd += title;
|
|
||||||
cmd += "\" --track ";
|
|
||||||
cmd += to_string(track_num);
|
|
||||||
cmd += " \"";
|
|
||||||
cmd += filepath;
|
|
||||||
cmd += "\" > /dev/null 2>&1";
|
|
||||||
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
string gen_flac_clear_images(const string& filepath, const string& metaflac_exec)
|
|
||||||
{
|
|
||||||
string cmd;
|
|
||||||
|
|
||||||
cmd = metaflac_exec;
|
|
||||||
cmd += " --preserve-modtime --no-utf8-convert";
|
|
||||||
cmd += " --remove --block-type=PICTURE \"";
|
|
||||||
cmd += filepath;
|
|
||||||
cmd += "\"";
|
|
||||||
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
string gen_flac_clear_tags(const string& filepath, const string& metaflac_exec)
|
|
||||||
{
|
|
||||||
string cmd;
|
|
||||||
|
|
||||||
cmd = metaflac_exec;
|
|
||||||
cmd += " --preserve-modtime --no-utf8-convert";
|
|
||||||
cmd += " --remove-tag=TITLE";
|
|
||||||
cmd += " --remove-tag=ARTIST";
|
|
||||||
// cmd += " --remove-tag=ALBUM";
|
|
||||||
cmd += " --remove-tag=TRACKNUMBER";
|
|
||||||
cmd += " \"";
|
|
||||||
cmd += filepath;
|
|
||||||
cmd += "\"";
|
|
||||||
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
string gen_flac_set_tags(const string& filepath, const string& artist,
|
|
||||||
const string& title, const string& album, int track_num,
|
|
||||||
const string& cover_filepath, string metaflac_exec)
|
|
||||||
{
|
|
||||||
string cmd;
|
|
||||||
|
|
||||||
cmd = metaflac_exec;
|
|
||||||
cmd += " --preserve-modtime --no-utf8-convert";
|
|
||||||
cmd += " \"--import-picture-from=3|image/jpeg|||";
|
|
||||||
cmd += cover_filepath;
|
|
||||||
cmd += "\" \"--set-tag=TITLE=";
|
|
||||||
cmd += title;
|
|
||||||
cmd += "\" \"--set-tag=ARTIST=";
|
|
||||||
cmd += artist;
|
|
||||||
// cmd += "\" \"--set-tag=ALBUM=";
|
|
||||||
// cmd += album;
|
|
||||||
cmd += "\" \"--set-tag=TRACKNUMBER=";
|
|
||||||
cmd += to_string(track_num);
|
|
||||||
cmd += "\" --dont-use-padding \"";
|
|
||||||
cmd += filepath;
|
|
||||||
cmd += "\"";
|
|
||||||
|
|
||||||
return cmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// Config stuff
|
// Config stuff
|
||||||
@ -156,10 +51,6 @@ int main(int argc, char **argv)
|
|||||||
json_extract(config, "Pass", pass);
|
json_extract(config, "Pass", pass);
|
||||||
json_extract(config, "download_path", main_path);
|
json_extract(config, "download_path", main_path);
|
||||||
|
|
||||||
json_extract(config, "convert_exec", convert_exec);
|
|
||||||
json_extract(config, "eyed3_exec", eyed3_exec);
|
|
||||||
json_extract(config, "metaflac_exec", metaflac_exec);
|
|
||||||
|
|
||||||
ok = mcat.login(email, pass);
|
ok = mcat.login(email, pass);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
@ -205,22 +96,6 @@ int main(int argc, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download Cover
|
|
||||||
ok = mcat.download_cover(release.catalog_id, release_folder);
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
cout << "Could not download cover for release " << release.catalog_id << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resize cover
|
|
||||||
ok = exec_cmd(gen_resize_command(release_folder, convert_exec));
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
cout << "Could not resize cover for release - " << release.catalog_id << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Download tracks (1 -- N)
|
// Download tracks (1 -- N)
|
||||||
for (Track& track : release.tracks)
|
for (Track& track : release.tracks)
|
||||||
{
|
{
|
||||||
@ -228,7 +103,6 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
// Download MP3
|
// Download MP3
|
||||||
filepath = build_fname(mp3_folder, "", filename);
|
filepath = build_fname(mp3_folder, "", filename);
|
||||||
filepath += ".mp3";
|
|
||||||
ok = mcat.download_track(release.id, track.id, filepath, FORMAT_MP3);
|
ok = mcat.download_track(release.id, track.id, filepath, FORMAT_MP3);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
@ -237,34 +111,8 @@ int main(int argc, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear MP3 Images
|
|
||||||
ok = exec_cmd(gen_mp3_clear(filepath, eyed3_exec));
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
cout << "Could not clear images for MP3 track " << track.number <<
|
|
||||||
" from release " << release.catalog_id << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set MP3 Tags
|
|
||||||
ok = exec_cmd(
|
|
||||||
gen_mp3_set_tags(filepath,
|
|
||||||
track.artist,
|
|
||||||
track.title,
|
|
||||||
release.title,
|
|
||||||
track.number,
|
|
||||||
build_fname(release_folder, "", "Cover_small.jpg"),
|
|
||||||
eyed3_exec));
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
cout << "Could not tag MP3 track " << track.number <<
|
|
||||||
" from release " << release.catalog_id << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Download FLAC
|
// Download FLAC
|
||||||
filepath = build_fname(flac_folder, "", filename);
|
filepath = build_fname(flac_folder, "", filename);
|
||||||
filepath += ".flac";
|
|
||||||
ok = mcat.download_track(release.id, track.id, filepath, FORMAT_FLAC);
|
ok = mcat.download_track(release.id, track.id, filepath, FORMAT_FLAC);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
@ -273,40 +121,6 @@ int main(int argc, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear FLAC Images
|
|
||||||
ok = exec_cmd(gen_flac_clear_images(filepath, metaflac_exec));
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
cout << "Could not clear images for FLAC track " << track.number <<
|
|
||||||
" from release " << release.catalog_id << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear FLAC Tags
|
|
||||||
ok = exec_cmd(gen_flac_clear_tags(filepath, metaflac_exec));
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
cout << "Could not clear tags for FLAC track " << track.number <<
|
|
||||||
" from release " << release.catalog_id << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set FLAC Tags
|
|
||||||
ok = exec_cmd(
|
|
||||||
gen_flac_set_tags(filepath,
|
|
||||||
track.artist,
|
|
||||||
track.title,
|
|
||||||
release.title,
|
|
||||||
track.number,
|
|
||||||
build_fname(release_folder, "", "Cover_small.jpg"),
|
|
||||||
metaflac_exec));
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
cout << "Could not tag FLAC track " << track.number <<
|
|
||||||
" from release " << release.catalog_id << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Download Extended Mix
|
// Download Extended Mix
|
||||||
if (!track.extended_mix_file_id.empty())
|
if (!track.extended_mix_file_id.empty())
|
||||||
{
|
{
|
||||||
@ -329,6 +143,14 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Download Cover
|
||||||
|
ok = mcat.download_cover(release.catalog_id, release_folder);
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
cout << "Could not download cover for release " << release.catalog_id << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = mcat.logout();
|
ok = mcat.logout();
|
||||||
|
|||||||
@ -502,11 +502,12 @@ bool Monstercat_DL::download_cover(const string& catalog_id, const string& path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Monstercat_DL::download_track(const string& release_id,
|
bool Monstercat_DL::download_track(const string& release_id,
|
||||||
const string& track_id, const string& filepath, bool is_mp3)
|
const string& track_id, const string& path, bool is_mp3)
|
||||||
{
|
{
|
||||||
CURL_DL& curl = CURL_DL::get_handle();
|
CURL_DL& curl = CURL_DL::get_handle();
|
||||||
bool ok;
|
bool ok;
|
||||||
string url;
|
string url;
|
||||||
|
string filepath;
|
||||||
stringstream out_data;
|
stringstream out_data;
|
||||||
ofstream out_file;
|
ofstream out_file;
|
||||||
|
|
||||||
@ -536,6 +537,16 @@ bool Monstercat_DL::download_track(const string& release_id,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filepath = path;
|
||||||
|
if (is_mp3)
|
||||||
|
{
|
||||||
|
filepath += ".mp3";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filepath += ".flac";
|
||||||
|
}
|
||||||
|
|
||||||
out_file.open(filepath, std::ios::binary);
|
out_file.open(filepath, std::ios::binary);
|
||||||
if (!out_file.is_open())
|
if (!out_file.is_open())
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user