Switching to C++ #60
@@ -18,6 +18,8 @@ CREATE TABLE Song (
|
||||
Genre TEXT NOT NULL,
|
||||
Year INT NOT NULL,
|
||||
Duration INT NOT NULL,
|
||||
Track INT NOT NULL,
|
||||
Disc INT NOT NULL,
|
||||
SongPath TEXT NOT NULL,
|
||||
CoverArtId INT NOT NULL,
|
||||
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
#ifndef MODELS_H_
|
||||
#define MODELS_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct Song
|
||||
{
|
||||
int id;
|
||||
std::string title;
|
||||
std::string artist;
|
||||
std::string album;
|
||||
std::string genre;
|
||||
int year;
|
||||
int duration;
|
||||
std::string songPath;
|
||||
std::vector<unsigned char> data;
|
||||
};
|
||||
|
||||
struct Cover
|
||||
{
|
||||
int id;
|
||||
std::string songTitle;
|
||||
std::string imagePath;
|
||||
// Currently not being used but it should
|
||||
std::vector<unsigned char> data;
|
||||
};
|
||||
|
||||
struct LoginRes
|
||||
{
|
||||
int UserId;
|
||||
char Username[1024];
|
||||
char Token[1024];
|
||||
char TokenType[1024];
|
||||
char Message[1024];
|
||||
int Expiration;
|
||||
};
|
||||
|
||||
struct loginResult
|
||||
{
|
||||
int user_id;
|
||||
std::string username;
|
||||
std::string access_token;
|
||||
std::string token_type;
|
||||
std::string message;
|
||||
int expiration;
|
||||
};
|
||||
|
||||
struct auth_credentials
|
||||
{
|
||||
std::string domain;
|
||||
std::string api_identifier;
|
||||
std::string client_id;
|
||||
std::string client_secret;
|
||||
std::string uri;
|
||||
std::string endpoint;
|
||||
};
|
||||
|
||||
struct database_connection
|
||||
{
|
||||
std::string server;
|
||||
std::string username;
|
||||
std::string password;
|
||||
std::string database;
|
||||
};
|
||||
|
||||
struct TokenReq
|
||||
{
|
||||
char ClientId[1024];
|
||||
char ClientSecret[1024];
|
||||
char Audience[1024];
|
||||
char GrantType[1024];
|
||||
char URI[1024];
|
||||
char Endpoint[1024];
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -13,6 +13,8 @@ struct Song
|
||||
std::string genre;
|
||||
int year;
|
||||
int duration;
|
||||
int track;
|
||||
int disc;
|
||||
std::string songPath;
|
||||
std::vector<unsigned char> data;
|
||||
int coverArtId;
|
||||
|
||||
@@ -94,6 +94,8 @@ public:
|
||||
song->genre = songDb.genre.c_str();
|
||||
song->year = songDb.year;
|
||||
song->duration = songDb.duration;
|
||||
song->track = songDb.track;
|
||||
song->disc = songDb.disc;
|
||||
|
||||
songs->pushBack(song);
|
||||
}
|
||||
@@ -119,6 +121,8 @@ public:
|
||||
song->genre = songDb.genre.c_str();
|
||||
song->year = songDb.year;
|
||||
song->duration = songDb.duration;
|
||||
song->track = songDb.track;
|
||||
song->disc = songDb.disc;
|
||||
|
||||
return createDtoResponse(Status::CODE_200, song);
|
||||
}
|
||||
@@ -148,6 +152,8 @@ public:
|
||||
return response;
|
||||
}
|
||||
|
||||
// TODO: create endpoint for updating songs
|
||||
|
||||
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete, PATH(Int32, id)) {
|
||||
|
||||
Song song;
|
||||
@@ -159,6 +165,8 @@ public:
|
||||
return createResponse(Status::CODE_200, "OK");
|
||||
}
|
||||
|
||||
// TODO: create endpoint for streaming songs
|
||||
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::string m_exe_path;
|
||||
|
||||
@@ -77,11 +77,11 @@ void songRepository::saveRecord(const Song& song)
|
||||
MYSQL_STMT *stmt = mysql_stmt_init(conn);
|
||||
|
||||
std::string query = "INSERT INTO Song(Title, Artist, Album, Genre, ";
|
||||
query.append("Year, Duration, SongPath, CoverArtId) VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
query.append("Year, Duration, Track, Disc, SongPath, CoverArtId) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
status = mysql_stmt_prepare(stmt, query.c_str(), query.size());
|
||||
|
||||
MYSQL_BIND params[8];
|
||||
MYSQL_BIND params[10];
|
||||
memset(params, 0, sizeof(params));
|
||||
|
||||
params[0].buffer_type = MYSQL_TYPE_STRING;
|
||||
@@ -118,16 +118,26 @@ void songRepository::saveRecord(const Song& song)
|
||||
params[5].length = 0;
|
||||
params[5].is_null = 0;
|
||||
|
||||
params[6].buffer_type = MYSQL_TYPE_STRING;
|
||||
params[6].buffer = (char*)song.songPath.c_str();
|
||||
auto pathLength = song.songPath.size();
|
||||
params[6].length = &pathLength;
|
||||
params[6].buffer_type = MYSQL_TYPE_LONG;
|
||||
params[6].buffer = (char*)&song.track;
|
||||
params[6].length = 0;
|
||||
params[6].is_null = 0;
|
||||
|
||||
params[7].buffer_type = MYSQL_TYPE_LONG;
|
||||
params[7].buffer = (char*)&song.coverArtId;
|
||||
params[7].buffer = (char*)&song.disc;
|
||||
params[7].length = 0;
|
||||
params[7].is_null = 0;
|
||||
|
||||
params[8].buffer_type = MYSQL_TYPE_STRING;
|
||||
params[8].buffer = (char*)song.songPath.c_str();
|
||||
auto pathLength = song.songPath.size();
|
||||
params[8].length = &pathLength;
|
||||
params[8].is_null = 0;
|
||||
|
||||
params[9].buffer_type = MYSQL_TYPE_LONG;
|
||||
params[9].buffer = (char*)&song.coverArtId;
|
||||
params[9].length = 0;
|
||||
params[9].is_null = 0;
|
||||
|
||||
status = mysql_stmt_bind_param(stmt, params);
|
||||
status = mysql_stmt_execute(stmt);
|
||||
@@ -173,9 +183,15 @@ std::vector<Song> songRepository::parseRecords(MYSQL_RES* results)
|
||||
song.duration = std::stoi(row[i]);
|
||||
break;
|
||||
case 7:
|
||||
song.songPath = row[i];
|
||||
song.track = std::stoi(row[i]);
|
||||
break;
|
||||
case 8:
|
||||
song.disc = std::stoi(row[i]);
|
||||
break;
|
||||
case 9:
|
||||
song.songPath = row[i];
|
||||
break;
|
||||
case 10:
|
||||
song.coverArtId = std::stoi(row[i]);
|
||||
break;
|
||||
}
|
||||
@@ -218,9 +234,15 @@ Song songRepository::parseRecord(MYSQL_RES* results)
|
||||
song.duration = std::stoi(row[i]);
|
||||
break;
|
||||
case 7:
|
||||
song.songPath = row[i];
|
||||
song.track = std::stoi(row[i]);
|
||||
break;
|
||||
case 8:
|
||||
song.disc = std::stoi(row[i]);
|
||||
break;
|
||||
case 9:
|
||||
song.songPath = row[i];
|
||||
break;
|
||||
case 10:
|
||||
song.coverArtId = std::stoi(row[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ class songDto : public oatpp::data::mapping::type::Object
|
||||
DTO_FIELD(String, artist);
|
||||
DTO_FIELD(String, album);
|
||||
DTO_FIELD(String, genre);
|
||||
DTO_FIELD(Int32, track);
|
||||
DTO_FIELD(Int32, disc);
|
||||
DTO_FIELD(Int32, year);
|
||||
DTO_FIELD(Int32, duration);
|
||||
};
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
#ifndef LOGINHANDLER_H_
|
||||
#define LOGINHANDLER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "oatpp/network/server/Server.hpp"
|
||||
#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp"
|
||||
#include "oatpp/web/server/HttpConnectionHandler.hpp"
|
||||
|
||||
#include "dto/loginResultDto.hpp"
|
||||
|
||||
class loginHandler : public oatpp::web::server::HttpRequestHandler
|
||||
{
|
||||
public:
|
||||
|
||||
std::shared_ptr<OutgoingResponse> handle(const std::shared_ptr<IncomingRequest>& request) override
|
||||
{
|
||||
auto logRes = loginResultDto::createShared();
|
||||
logRes->access_token = "hahahahahahaha";
|
||||
logRes->token_type = "Fly";
|
||||
|
||||
return ResponseFactory::createResponse(Status::CODE_200, "ddd");
|
||||
}
|
||||
private:
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, m_objectMapper);
|
||||
};
|
||||
|
||||
#endif
|
||||
+1
-43
@@ -39,52 +39,10 @@ void run(const std::string& working_path)
|
||||
server.run();
|
||||
}
|
||||
|
||||
void test_database()
|
||||
{
|
||||
database_connection mysqlD;
|
||||
mysqlD.server = ""; // where the mysql database is
|
||||
mysqlD.username = ""; // the root user of mysql
|
||||
mysqlD.password = ""; // the password of the root user in mysql
|
||||
mysqlD.database = ""; // the databse to pick
|
||||
|
||||
base_repository base;
|
||||
/**
|
||||
auto conn = base.setup_mysql_connection(mysqlD);
|
||||
|
||||
// assign the results return to the MYSQL_RES pointer
|
||||
const std::string query = "SELECT *, NULL FROM Song";
|
||||
auto res = base.perform_mysql_query(conn, query);
|
||||
auto num_of_fields = mysql_num_fields(res);
|
||||
|
||||
printf("MySQL Tables in mysql database:\n");
|
||||
auto row_count = 1;
|
||||
|
||||
for (MYSQL_ROW row = NULL; (row = mysql_fetch_row(res)) != NULL;) {
|
||||
std::cout << " row " << row_count << std::endl;
|
||||
for (auto i = 0; i != num_of_fields; ++i) {
|
||||
auto val = row[i];
|
||||
|
||||
if ( val == NULL) {
|
||||
std::cout << "found null value " << std::endl;
|
||||
continue;
|
||||
}
|
||||
std::cout << val << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// clean up the database result set //
|
||||
mysql_free_result(res);
|
||||
// clean up the database link //
|
||||
mysql_close(conn);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
oatpp::base::Environment::init();
|
||||
std::string working_path = argv[0];
|
||||
const std::string working_path = argv[0];
|
||||
|
||||
run(working_path);
|
||||
|
||||
|
||||
@@ -41,8 +41,7 @@ void song_manager::saveSong(Song& song)
|
||||
auto songPath = directory_manager::create_directory_process(song, musicRootPath);
|
||||
songPath.append(song.title);
|
||||
songPath.append(".mp3");
|
||||
std::cout << std::endl;
|
||||
std::cout << "temp path: " << song.songPath << std::endl;
|
||||
std::cout << "\n\ntemp path: " << song.songPath << std::endl;
|
||||
std::cout << "new path: " << songPath << std::endl;
|
||||
fs::copy(song.songPath, songPath);
|
||||
fs::remove(song.songPath);
|
||||
@@ -84,13 +83,15 @@ void song_manager::deleteSong(Song& song)
|
||||
|
||||
void song_manager::printSong(const Song& song)
|
||||
{
|
||||
std::cout << std::endl << "song" << std::endl;
|
||||
std::cout << "\n\nsong" << std::endl;
|
||||
std::cout << "title: " << song.title << std::endl;
|
||||
std::cout << "artist: " << song.artist << std::endl;
|
||||
std::cout << "album: " << song.album << std::endl;
|
||||
std::cout << "genre: " << song.genre << std::endl;
|
||||
std::cout << "duration: " << song.duration << std::endl;
|
||||
std::cout << "year: " << song.year << std::endl;
|
||||
std::cout << "track: " << song.track << std::endl;
|
||||
std::cout << "disc: " << song.disc << std::endl;
|
||||
std::cout << "song path: " << song.songPath << std::endl;
|
||||
if (song.coverArtId != 0) {
|
||||
std::cout << "cover art id: " << song.coverArtId << std::endl;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
@@ -25,9 +26,24 @@ Song metadata_retriever::retrieve_metadata(std::string& song_path)
|
||||
song.album = file.tag()->album().toCString();
|
||||
song.genre = file.tag()->genre().toCString();
|
||||
song.year = file.tag()->year();
|
||||
song.track = file.tag()->track();
|
||||
song.duration = file.audioProperties()->lengthInSeconds();
|
||||
song.songPath = song_path;
|
||||
|
||||
// TODO: Move over to this eventually since at the moment
|
||||
// I am only targetting mp3 files
|
||||
// Used to retrieve disc
|
||||
TagLib::MPEG::File sameFile(song_path.c_str());
|
||||
auto tag = sameFile.ID3v2Tag();
|
||||
|
||||
auto frame = tag->frameList("TPOS");
|
||||
if (frame.isEmpty()) {
|
||||
song.disc = 1;
|
||||
// TODO: set default disc to 1 if none found
|
||||
} else {
|
||||
song.disc = std::stoi(frame.front()->toString().toCString());
|
||||
}
|
||||
|
||||
|
||||
return song;
|
||||
}
|
||||
@@ -99,5 +115,7 @@ void metadata_retriever::update_metadata(Song sng_updated, const Song sng_old)
|
||||
file.tag()->setYear(sng_updated.year);
|
||||
}
|
||||
|
||||
// TODO: functionality to update the track number and disc number
|
||||
|
||||
file.save();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user