From 1ef40bcbfb20d4f07a40ce937dc25cb925c04820 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 1 Jan 2022 00:39:35 -0500 Subject: [PATCH] Got functionality working --- README.md | 16 +++-- include/Managers/CommitManager.h | 104 ++++++++++++++++++++++++++++++- include/Models/Song.h | 1 - include/Utilities/Checks.h | 40 +++++++++++- src/Managers/CommitManager.cpp | 93 ++++++++++++++++----------- src/Models/Song.cpp | 6 ++ src/Parsers/APIParser.cpp | 3 - src/Syncers/Upload.cpp | 6 +- 8 files changed, 221 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 8c42e1c..6b02d47 100644 --- a/README.md +++ b/README.md @@ -35,10 +35,14 @@ cmake --build . -j The program has been built and can be executed by the binary file *icd*. For information on how to use icd, merely execute the program without any command line arguments. ### Downloading Song -``icd download -u spacecadet -p stellar40 -h https://icarus.com -b 15`` +``BASH +icd download -u spacecadet -p stellar40 -h https://icarus.com -b 15 +``` ### Uploading Song -``icd upload -u spacecadet -p stellar40 -h https://icarus.com -s /path/of/song.mp3`` +```BASH +icd upload -u spacecadet -p stellar40 -h https://icarus.com -s /path/of/song.mp3 +``` ### Uploading Song with metadata @@ -54,10 +58,14 @@ icd upload-meta -u spacecadet -p stellar40 -h https://icarus.com -smca /path/whe ### Retrieving Song in json -``icd retrieve -u spacecadet -p stellar40 -h https://icarus.com -rt songs`` +```Bash +icd retrieve -u spacecadet -p stellar40 -h https://icarus.com -rt songs +``` ### Deleting Song -``icd delete -u spacecadet -p stellar40 -h https://icarus.com -D 15`` +```BASH +icd delete -u spacecadet -p stellar40 -h https://icarus.com -D 15 +``` ## Contributing diff --git a/include/Managers/CommitManager.h b/include/Managers/CommitManager.h index fdc82d1..73ff50f 100644 --- a/include/Managers/CommitManager.h +++ b/include/Managers/CommitManager.h @@ -10,6 +10,7 @@ #include"Models/IcarusAction.h" #include"Models/Song.h" #include"Models/Token.h" +#include"Utilities/Checks.h" namespace Managers { @@ -63,15 +64,116 @@ namespace Managers // * TrackID - track number to chose from when retrieving metadata. "1" and "1:1" are similar // * Metadata - Source file containing metadata of the song // * Cover art - path to image cover art - // TODO: Change the name void uploadSongWithMetadata(); // Expects the song path, trackID, metadata file path, and cover path void singTargetUpload(const std::string &songPath, const std::string &trackID, const std::string &metaPath, const std::string &coverPath); // Expects the source directory that contains songs, a metadata file, and cover image + // Disc and Track is retrieved from the filename if the filename conforms to a standard. + // If not, then the disc and track will default to 1 + // + // Standards + // * track01.mp3 - Disc 1, Track 1 + // * track05d02.mp3 - Disc 2, Track 5 void multiTargetUpload(const std::string &sourcePath); + // Standards + // * track01.mp3 - Disc 1, Track 1 + // * track05d02.mp3 - Disc 2, Track 5 + template + void initializeDiscAndTrack(Song &song) + { + auto disc = 1; + auto track = 1; + // If 1 go with first standard, if 2 go with the second, if 0 then will default to 1 for disc and track + auto mode = 0; + const Str &songPath = song.songPath; + + auto trd = song.songPath.find("trackd"); + auto tr = song.songPath.find("track"); + + if (tr != Str::npos) + { + mode = 1; + } + + if (trd != Str::npos) + { + mode = 2; + } + + auto dl = [](char c, char t){ return c == t; }; + auto d = Utilities::Checks::itemIterInContainer(songPath, 'd', dl); + auto k = Utilities::Checks::itemIterInContainer(songPath, 'k', dl); + auto dot = Utilities::Checks::itemIterInContainer(songPath, '.', dl); + + switch(mode) + { + case 1: + { + if (k != songPath.end() && dot != songPath.end()) + { + auto tStr = std::string(++k, dot); + std::cout << "TStr: " << tStr<<"\n"; + + if (Utilities::Checks::isNumber(tStr)) + { + track = std::atoi(tStr.c_str()); + } + } + break; + } + case 2: + { + if (k != songPath.end() && dot != songPath.end() && d != songPath.end()) + { + auto tStr = std::string(++k, d); + auto dStr = std::string(++d, dot); + std::cout<<"DStr: "< + void parseDiscAndTrack(Song &song, const Str &trackID) + { + auto sep = [](char c, char t) { return c == t; }; + auto separator = Utilities::Checks::itemIterInContainer(trackID, ':', sep); + + if (separator != trackID.end()) + { + auto dStr = Str(trackID.begin(), separator); + auto tStr = Str(++separator, trackID.end()); + + song.disc = std::atoi(dStr.c_str()); + song.track = std::atoi(tStr.c_str()); + } + else + { + auto isNumber = Utilities::Checks::isNumber(trackID); + if (isNumber) + { + song.track = std::atoi(trackID.c_str()); + } + } + } + // Checks for the no confirm flag. Used when uploading songs from a directory bool checkForNoConfirm() diff --git a/include/Models/Song.h b/include/Models/Song.h index b2ea9d9..4cafbe3 100644 --- a/include/Models/Song.h +++ b/include/Models/Song.h @@ -18,7 +18,6 @@ namespace Models std::cout<<"\n"; } - // TODO: Incomplete implementation std::string toMetadataJson(); diff --git a/include/Utilities/Checks.h b/include/Utilities/Checks.h index 0760fb7..b4c186d 100644 --- a/include/Utilities/Checks.h +++ b/include/Utilities/Checks.h @@ -12,7 +12,7 @@ namespace Utilities public: Checks() = delete; - static bool isNumber(const std::string &val) + static auto isNumber(const std::string &val) { return !val.empty() && std::find_if(val.begin(), val.end(), [](char c) @@ -20,6 +20,44 @@ namespace Utilities return !std::isdigit(c); }) == val.end(); } + + // Note: Not implemented + template + static auto itemInContainer(const Container container, const Item item, Func func) + { + auto result = false; + auto i = std::find_if(container.begin(), container.end(), [&](Item i) + { + return func(item, i); + }); + + if (i != container.end()) + { + result = true; + } + + return result; + } + + template + static auto itemIterInContainer(const Container &container, const Item &item, Func func) + { + auto result = false; + // std::cout<(song, trackID); - if (separator != trackID.end()) - { - cout<<"Found colon\n"; - auto dStr = string(trackID.begin(), separator); - auto tStr = string(++separator, trackID.end()); - - cout<<"disc "<>(album.songs, song, c); if (sng == album.songs.end()) { - cout<<"Not found with disc "< songs; + Models::CoverArt cover; + string metadataPath; + + for (auto &p: fs::directory_iterator(sourcePath)) + { + const auto &pp = p.path(); + const auto stem = pp.stem(); + const auto file = pp.filename(); + const auto extension = pp.extension(); + + cout<<"Stem "<(song); + + songs.emplace_back(std::move(song)); + } + else if (extension.compare(".jpg") == 0 || extension.compare(".png") == 0) + { + cover.path.assign(pp.string()); + } + else if (extension.compare(".json") == 0) + { + metadataPath.assign(pp.string()); + } + } + + auto album = retrieveMetadata(metadataPath); + + Upload up(api, token); + + for (auto &song : songs) + { + up.uploadSongWithMetadata(album, song, cover); + } } #pragma region private diff --git a/src/Models/Song.cpp b/src/Models/Song.cpp index b149918..49338a7 100644 --- a/src/Models/Song.cpp +++ b/src/Models/Song.cpp @@ -10,6 +10,12 @@ namespace Models { nlohmann::json s; s["title"] = this->title; + s["artist"] = this->artist; + s["album"] = this->album; + s["genre"] = this->genre; + s["year"] = this->year; + s["track"] = this->track; + s["disc"] = this->disc; return s.dump(); } diff --git a/src/Parsers/APIParser.cpp b/src/Parsers/APIParser.cpp index 4e8746b..3d62019 100644 --- a/src/Parsers/APIParser.cpp +++ b/src/Parsers/APIParser.cpp @@ -43,9 +43,6 @@ namespace Parsers } - // TODO: For now I will hard code - // the api version since I am only - // on version 1 api.version = "v1"; } #pragma functions diff --git a/src/Syncers/Upload.cpp b/src/Syncers/Upload.cpp index 98d3554..daaaa88 100644 --- a/src/Syncers/Upload.cpp +++ b/src/Syncers/Upload.cpp @@ -108,7 +108,7 @@ namespace Syncers void Upload::uploadSongWithMetadata(Managers::CommitManager::Album &album, Models::Song& song, Models::CoverArt &cover) { - this->api.endpoint.append("/upload/with/data"); + this->api.endpoint.assign("song/data/upload/with/data"); try { @@ -133,8 +133,9 @@ namespace Syncers const auto meta = s.dump(); - // cout<<"\n\nMeta:\n"<