Able to save song and cover art to the appropriate paths. Next is saving it to the database
This commit is contained in:
@@ -10,8 +10,11 @@ set(SOURCES
|
|||||||
src/controller/loginController.hpp
|
src/controller/loginController.hpp
|
||||||
src/controller/songController.hpp
|
src/controller/songController.hpp
|
||||||
src/database/base_repository.cpp
|
src/database/base_repository.cpp
|
||||||
|
#src/database/coverArtRepository.cpp
|
||||||
|
#src/database/songRepository.cpp
|
||||||
src/dto/loginResultDto.hpp
|
src/dto/loginResultDto.hpp
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
|
src/managers/coverArtManager.cpp
|
||||||
src/managers/directory_manager.cpp
|
src/managers/directory_manager.cpp
|
||||||
src/managers/song_manager.cpp
|
src/managers/song_manager.cpp
|
||||||
src/managers/token_manager.cpp
|
src/managers/token_manager.cpp
|
||||||
@@ -20,6 +23,9 @@ set(SOURCES
|
|||||||
)
|
)
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
include/database/base_repository.h
|
include/database/base_repository.h
|
||||||
|
#include/database/coverArtRepository.h
|
||||||
|
#include/database/songRepository.h
|
||||||
|
include/managers/coverArtManager.h
|
||||||
include/managers/directory_manager.h
|
include/managers/directory_manager.h
|
||||||
include/managers/song_manager.h
|
include/managers/song_manager.h
|
||||||
include/managers/token_manager.h
|
include/managers/token_manager.h
|
||||||
@@ -79,6 +85,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/appsettings.json ${CMAKE_BINARY_DIR}/
|
|||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/authcredentials.json ${CMAKE_BINARY_DIR}/bin/authcredentials.json COPYONLY)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/authcredentials.json ${CMAKE_BINARY_DIR}/bin/authcredentials.json COPYONLY)
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/database.json ${CMAKE_BINARY_DIR}/bin/database.json COPYONLY)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/database.json ${CMAKE_BINARY_DIR}/bin/database.json COPYONLY)
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/paths.json ${CMAKE_BINARY_DIR}/bin/paths.json COPYONLY)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/paths.json ${CMAKE_BINARY_DIR}/bin/paths.json COPYONLY)
|
||||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Images/Stock/CoverArt.png ${CMAKE_BINARY_DIR}/bin/CoverArt.png COPYONLY)
|
||||||
|
|
||||||
add_executable(icarus ${SOURCES} ${HEADERS})
|
add_executable(icarus ${SOURCES} ${HEADERS})
|
||||||
target_include_directories(icarus PUBLIC ${JWT_CPP_INCLUDE})
|
target_include_directories(icarus PUBLIC ${JWT_CPP_INCLUDE})
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
class base_repository
|
class base_repository
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
protected:
|
||||||
MYSQL* setup_mysql_connection(database_connection);
|
MYSQL* setup_mysql_connection(database_connection);
|
||||||
|
|
||||||
MYSQL_RES* perform_mysql_query(MYSQL*, const std::string&);
|
MYSQL_RES* perform_mysql_query(MYSQL*, const std::string&);
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef COVERARTREPOSITORY_H_
|
||||||
|
#define COVERARTREPOSITORY_H_
|
||||||
|
|
||||||
|
#include <mysql/mysql.h>
|
||||||
|
|
||||||
|
#include "models/models.h"
|
||||||
|
|
||||||
|
class coverArtRepository
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef SONGREPOSITORY_H_
|
||||||
|
#define SONGREPOSITORY_H_
|
||||||
|
|
||||||
|
#include <mysql/mysql.h>
|
||||||
|
|
||||||
|
#include "models/models.h"
|
||||||
|
|
||||||
|
class songRespository
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef COVERARTMANAGER_H_
|
||||||
|
#define COVERARTMANAGER_H_
|
||||||
|
|
||||||
|
#include "models/models.h"
|
||||||
|
|
||||||
|
class coverArtManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Cover saveCover(const Song&, std::string&, const std::string&);
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -2,6 +2,9 @@
|
|||||||
#define DIRECTORY_MANAGER_H_
|
#define DIRECTORY_MANAGER_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include "models/models.h"
|
#include "models/models.h"
|
||||||
|
|
||||||
@@ -10,12 +13,18 @@ class directory_manager
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
std::string create_directory_process(Song, const std::string&);
|
std::string create_directory_process(Song, const std::string&);
|
||||||
|
static std::string configPath(std::string_view);
|
||||||
|
static std::string contentOfPath(std::string_view);
|
||||||
|
|
||||||
|
static nlohmann::json credentialConfigContent(const std::string&);
|
||||||
|
static nlohmann::json databaseConfigContent(const std::string&);
|
||||||
|
static nlohmann::json pathConfigContent(const std::string&);
|
||||||
// Return Cover instead
|
// Return Cover instead
|
||||||
std::string read_cover_art(const std::string&);
|
//std::string read_cover_art(const std::string&);
|
||||||
|
|
||||||
|
|
||||||
void copy_stock_to_root(const std::string&, const std::string&);
|
//void copy_stock_to_root(const std::string&, const std::string&);
|
||||||
void copy_song_to_path(const std::string&, const std::string&);
|
//void copy_song_to_path(const std::string&, const std::string&);
|
||||||
void delete_cover_art_file(const std::string&, const std::string&);
|
void delete_cover_art_file(const std::string&, const std::string&);
|
||||||
void delete_directories(Song, const std::string&);
|
void delete_directories(Song, const std::string&);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include "models/models.h"
|
#include "models/models.h"
|
||||||
|
|
||||||
class song_manager
|
class song_manager
|
||||||
@@ -11,8 +13,19 @@ class song_manager
|
|||||||
public:
|
public:
|
||||||
song_manager(std::string&);
|
song_manager(std::string&);
|
||||||
|
|
||||||
|
/**
|
||||||
|
std::string retrieveMusicPath();
|
||||||
|
std::string retrieveTempPath();
|
||||||
|
*/
|
||||||
|
|
||||||
|
//nlohmann::json pathConfigContent();
|
||||||
|
|
||||||
void saveSong(Song&);
|
void saveSong(Song&);
|
||||||
|
|
||||||
|
static void printSong(const Song&);
|
||||||
private:
|
private:
|
||||||
|
void saveSongTemp(Song&);
|
||||||
|
|
||||||
std::string exe_path;
|
std::string exe_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class metadata_retriever
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Song retrieve_metadata(std::string&);
|
Song retrieve_metadata(std::string&);
|
||||||
Cover update_cover_art(Cover, const Song, const std::string&);
|
Cover update_cover_art(const Song&, Cover& cov, const std::string&);
|
||||||
|
|
||||||
void update_metadata(Song updated_song, const Song old_song);
|
void update_metadata(Song updated_song, const Song old_song);
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
#include "oatpp/web/server/api/ApiController.hpp"
|
#include "oatpp/web/server/api/ApiController.hpp"
|
||||||
|
|
||||||
#include "managers/song_manager.h"
|
#include "managers/song_manager.h"
|
||||||
#include "models/models.h"
|
|
||||||
#include "managers/token_manager.h"
|
#include "managers/token_manager.h"
|
||||||
|
#include "models/models.h"
|
||||||
#include "types/scopes.h"
|
#include "types/scopes.h"
|
||||||
|
|
||||||
class songController : public oatpp::web::server::api::ApiController
|
class songController : public oatpp::web::server::api::ApiController
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
#include "database/coverArtRepository.h"
|
||||||
+4
-3
@@ -48,6 +48,7 @@ void test_database()
|
|||||||
mysqlD.database = ""; // the databse to pick
|
mysqlD.database = ""; // the databse to pick
|
||||||
|
|
||||||
base_repository base;
|
base_repository base;
|
||||||
|
/**
|
||||||
auto conn = base.setup_mysql_connection(mysqlD);
|
auto conn = base.setup_mysql_connection(mysqlD);
|
||||||
|
|
||||||
// assign the results return to the MYSQL_RES pointer
|
// assign the results return to the MYSQL_RES pointer
|
||||||
@@ -72,10 +73,11 @@ void test_database()
|
|||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clean up the database result set */
|
// clean up the database result set //
|
||||||
mysql_free_result(res);
|
mysql_free_result(res);
|
||||||
/* clean up the database link */
|
// clean up the database link //
|
||||||
mysql_close(conn);
|
mysql_close(conn);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +86,6 @@ int main(int argc, char **argv)
|
|||||||
oatpp::base::Environment::init();
|
oatpp::base::Environment::init();
|
||||||
std::string working_path = argv[0];
|
std::string working_path = argv[0];
|
||||||
|
|
||||||
//test_database();
|
|
||||||
run(working_path);
|
run(working_path);
|
||||||
|
|
||||||
oatpp::base::Environment::destroy();
|
oatpp::base::Environment::destroy();
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#include "managers/coverArtManager.h"
|
||||||
|
|
||||||
|
#include "utilities/metadata_retriever.h"
|
||||||
|
|
||||||
|
Cover coverArtManager::saveCover(const Song& song, std::string& rootPath, const std::string& stockCoverPath)
|
||||||
|
{
|
||||||
|
metadata_retriever meta;
|
||||||
|
Cover cov;
|
||||||
|
cov.imagePath = rootPath;
|
||||||
|
cov = meta.update_cover_art(song, cov, stockCoverPath);
|
||||||
|
cov.songTitle = song.title;
|
||||||
|
|
||||||
|
return cov;
|
||||||
|
}
|
||||||
@@ -36,6 +36,45 @@ std::string directory_manager::create_directory_process(Song song, const std::st
|
|||||||
|
|
||||||
return alb_path.string() + "/";
|
return alb_path.string() + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string directory_manager::configPath(std::string_view path)
|
||||||
|
{
|
||||||
|
return fs::canonical(path).parent_path().string();
|
||||||
|
}
|
||||||
|
std::string directory_manager::contentOfPath(std::string_view path)
|
||||||
|
{
|
||||||
|
std::string configPath(path);
|
||||||
|
std::fstream a(configPath, std::ios::in);
|
||||||
|
std::stringstream s;
|
||||||
|
s << a.rdbuf();
|
||||||
|
a.close();
|
||||||
|
|
||||||
|
return s.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json directory_manager::credentialConfigContent(const std::string& exe_path)
|
||||||
|
{
|
||||||
|
auto path = configPath(exe_path);
|
||||||
|
path.append("/authcredentials.json");
|
||||||
|
|
||||||
|
return nlohmann::json::parse(contentOfPath(path));
|
||||||
|
}
|
||||||
|
nlohmann::json directory_manager::databaseConfigContent(const std::string& exe_path)
|
||||||
|
{
|
||||||
|
auto path = configPath(exe_path);
|
||||||
|
path.append("/database.json");
|
||||||
|
|
||||||
|
return nlohmann::json::parse(contentOfPath(path));
|
||||||
|
}
|
||||||
|
nlohmann::json directory_manager::pathConfigContent(const std::string& exe_path)
|
||||||
|
{
|
||||||
|
auto path = configPath(exe_path);
|
||||||
|
path.append("/paths.json");
|
||||||
|
|
||||||
|
return nlohmann::json::parse(contentOfPath(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
std::string directory_manager::read_cover_art(const std::string& source)
|
std::string directory_manager::read_cover_art(const std::string& source)
|
||||||
{
|
{
|
||||||
auto source_path = fs::path(source);
|
auto source_path = fs::path(source);
|
||||||
@@ -80,6 +119,7 @@ void directory_manager::copy_song_to_path(const std::string& target, const std::
|
|||||||
fs::remove(source);
|
fs::remove(source);
|
||||||
std::cout<<"copy finished"<<std::endl;
|
std::cout<<"copy finished"<<std::endl;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void directory_manager::delete_cover_art_file(const std::string& cov_path, const std::string& stock_cover_path)
|
void directory_manager::delete_cover_art_file(const std::string& cov_path, const std::string& stock_cover_path)
|
||||||
{
|
{
|
||||||
if (cov_path.compare(stock_cover_path) == 0) {
|
if (cov_path.compare(stock_cover_path) == 0) {
|
||||||
@@ -129,74 +169,3 @@ void directory_manager::delete_song(const Song song)
|
|||||||
std::cout<<"deleted song"<<std::endl;
|
std::cout<<"deleted song"<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//extern "C"
|
|
||||||
//{
|
|
||||||
|
|
||||||
//void create_directory(Song, const char*, char*);
|
|
||||||
//void copy_stock_cover_art(const char*, const char*);
|
|
||||||
//void copy_song(const char*, const char*);
|
|
||||||
//void delete_cover_art(const char*, const char*);
|
|
||||||
//void delete_empty_directories(Song, const char*);
|
|
||||||
//void delete_from_filesystem(Song);
|
|
||||||
//void delete_song_empty_directories(Song, const char*);
|
|
||||||
//void print_song_details(const Song);
|
|
||||||
|
|
||||||
/**
|
|
||||||
void create_directory(Song song, const char *root_path, char *dir)
|
|
||||||
{
|
|
||||||
const auto tmp = create_directory_process(song, root_path);
|
|
||||||
size_t tmp_sz = tmp.size();
|
|
||||||
tmp.copy(dir, tmp_sz, 0);
|
|
||||||
}
|
|
||||||
void copy_stock_cover_art(const char *target, const char *source)
|
|
||||||
{
|
|
||||||
const auto buff = read_cover_art(source);
|
|
||||||
copy_stock_to_root(target, buff);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
void copy_song(const char *target, const char *source)
|
|
||||||
{
|
|
||||||
copy_song_to_path(target, source);
|
|
||||||
}
|
|
||||||
void delete_cover_art(const char *cover_path, const char *stock_path)
|
|
||||||
{
|
|
||||||
std::cout<<"starting process to delete cover art"<<std::endl;
|
|
||||||
const auto cov_path = std::string{cover_path};
|
|
||||||
const auto s_path = std::string{stock_path};
|
|
||||||
if (cov_path.compare(s_path) != 0) {
|
|
||||||
std::cout<<"cover art is not the stock path"<<std::endl;
|
|
||||||
delete_cover_art_file(cov_path);
|
|
||||||
} else {
|
|
||||||
std::cout<<"cover art is the stock path and will not be deleted"<<std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void delete_empty_directories(Song song, const char *root_path)
|
|
||||||
{
|
|
||||||
delete_directories(song, root_path);
|
|
||||||
}
|
|
||||||
void delete_from_filesystem(Song song)
|
|
||||||
{
|
|
||||||
if (delete_song(&song)) {
|
|
||||||
std::cout<<"successfully deleted song from filesystem"<<std::endl;
|
|
||||||
} else {
|
|
||||||
std::cout<<"failed to deleted song from filesystem"<<std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void delete_song_empty_directories(Song song, const char *root_path)
|
|
||||||
{
|
|
||||||
delete_song(song);
|
|
||||||
delete_directories(song, root_path);
|
|
||||||
}
|
|
||||||
void print_song_details(const Song song)
|
|
||||||
{
|
|
||||||
std::cout<<"song details"<<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<<"year: "<<song.Year<<std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include "managers/coverArtManager.h"
|
||||||
|
#include "managers/directory_manager.h"
|
||||||
|
#include "utilities/metadata_retriever.h"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@@ -9,14 +16,74 @@ song_manager::song_manager(std::string& x_path)
|
|||||||
: exe_path(x_path)
|
: exe_path(x_path)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
std::string song_manager::retrieveMusicPath()
|
||||||
|
{
|
||||||
|
std::string pathConfig = directory_manager::configPath(exe_path);
|
||||||
|
pathConfig.append("/paths.json");
|
||||||
|
nlohmann::json config = nlohmann::json::parse(directory_manager::contentOfPath(pathConfig));
|
||||||
|
|
||||||
|
return config["root_music_path"].get<std::string>();
|
||||||
|
}
|
||||||
|
std::string song_manager::retrieveTempPath()
|
||||||
|
{
|
||||||
|
auto pathConfig = directory_manager::configPath(exe_path);
|
||||||
|
pathConfig.append("/paths");
|
||||||
|
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json song_manager::pathConfigContent()
|
||||||
|
{
|
||||||
|
auto path = directory_manager::configPath(exe_path);
|
||||||
|
path.append("/paths.json");
|
||||||
|
|
||||||
|
return nlohmann::json::parse(directory_manager::contentOfPath(path));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void song_manager::saveSong(Song& song)
|
void song_manager::saveSong(Song& song)
|
||||||
{
|
{
|
||||||
constexpr auto tmp_song = "/tmp/song.mp3";
|
saveSongTemp(song);
|
||||||
if (fs::exists(fs::path(tmp_song))) {
|
metadata_retriever meta;
|
||||||
std::cout << "deleting old song " << std::endl;
|
auto data = std::move(song.data);
|
||||||
fs::remove(fs::path(tmp_song));
|
song = meta.retrieve_metadata(song.songPath);
|
||||||
}
|
song.data = std::move(data);
|
||||||
|
printSong(song);
|
||||||
|
|
||||||
|
coverArtManager covMgr;
|
||||||
|
auto coverRootPath = directory_manager::pathConfigContent(exe_path)["cover_root_path"].get<std::string>();
|
||||||
|
auto stockCoverPath = directory_manager::configPath(exe_path);
|
||||||
|
stockCoverPath.append("/CoverArt.png");
|
||||||
|
auto cov = covMgr.saveCover(song, coverRootPath, stockCoverPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void song_manager::printSong(const Song& song)
|
||||||
|
{
|
||||||
|
std::cout << "song" << 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 << "song path: " << song.songPath << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void song_manager::saveSongTemp(Song& song)
|
||||||
|
{
|
||||||
|
auto config = directory_manager::pathConfigContent(exe_path);
|
||||||
|
|
||||||
|
auto tmp_song = config["temp_root_path"].get<std::string>();
|
||||||
|
std::random_device dev;
|
||||||
|
std::mt19937 rng(dev());
|
||||||
|
std::uniform_int_distribution<std::mt19937::result_type> dist(1,1000);
|
||||||
|
tmp_song.append(std::to_string(dist(rng)));
|
||||||
|
tmp_song.append(".mp3");
|
||||||
|
|
||||||
std::fstream s(tmp_song, std::fstream::binary | std::fstream::out);
|
std::fstream s(tmp_song, std::fstream::binary | std::fstream::out);
|
||||||
s.write((char*)&song.data[0], song.data.size());
|
s.write((char*)&song.data[0], song.data.size());
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
|
song.songPath = tmp_song;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "managers/token_manager.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -10,7 +12,7 @@
|
|||||||
#include <cpr/cpr.h>
|
#include <cpr/cpr.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include "managers/token_manager.h"
|
#include "managers/directory_manager.h"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@@ -87,22 +89,26 @@ bool token_manager::is_token_valid(std::string& auth, Scope scope)
|
|||||||
|
|
||||||
auth_credentials token_manager::parse_auth_credentials(std::string_view path)
|
auth_credentials token_manager::parse_auth_credentials(std::string_view path)
|
||||||
{
|
{
|
||||||
auto exe_path = fs::canonical(path).parent_path().string();
|
auto exe_path = directory_manager::configPath(path);
|
||||||
exe_path.append("/authcredentials.json");
|
exe_path.append("/authcredentials.json");
|
||||||
|
|
||||||
|
//auto content = directory_manager::contentOfPath(exe_path);
|
||||||
|
/**
|
||||||
std::fstream a(exe_path, std::ios::in);
|
std::fstream a(exe_path, std::ios::in);
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << a.rdbuf();
|
s << a.rdbuf();
|
||||||
a.close();
|
a.close();
|
||||||
|
*/
|
||||||
|
|
||||||
auto con = nlohmann::json::parse(s.str());
|
//auto con = nlohmann::json::parse(directory_manager::contentOfPath(exe_path));
|
||||||
|
auto con = directory_manager::credentialConfigContent(exe_path);
|
||||||
|
|
||||||
auth_credentials auth;
|
auth_credentials auth;
|
||||||
auth.uri = "https://";
|
auth.uri = "https://";
|
||||||
auth.uri.append(con["Domain"]);
|
auth.uri.append(con["domain"]);
|
||||||
auth.api_identifier = con["ApiIdentifier"];
|
auth.api_identifier = con["api_identifier"];
|
||||||
auth.client_id = con["ClientId"];
|
auth.client_id = con["client_id"];
|
||||||
auth.client_secret = con["ClientSecret"];
|
auth.client_secret = con["client_secret"];
|
||||||
auth.endpoint = "oauth/token";
|
auth.endpoint = "oauth/token";
|
||||||
|
|
||||||
return auth;
|
return auth;
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
#include "utilities/imageFile.h"
|
#include "utilities/imageFile.h"
|
||||||
#include "utilities/metadata_retriever.h"
|
#include "utilities/metadata_retriever.h"
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
Song metadata_retriever::retrieve_metadata(std::string& song_path)
|
Song metadata_retriever::retrieve_metadata(std::string& song_path)
|
||||||
{
|
{
|
||||||
TagLib::FileRef file(song_path.c_str());
|
TagLib::FileRef file(song_path.c_str());
|
||||||
@@ -26,30 +28,23 @@ Song metadata_retriever::retrieve_metadata(std::string& song_path)
|
|||||||
song.duration = file.audioProperties()->lengthInSeconds();
|
song.duration = file.audioProperties()->lengthInSeconds();
|
||||||
song.songPath = song_path;
|
song.songPath = song_path;
|
||||||
|
|
||||||
/**
|
|
||||||
strcpy(sng->Title, file.tag()->title().toCString());
|
|
||||||
strcpy(sng->Artist, file.tag()->artist().toCString());
|
|
||||||
strcpy(sng->Album, file.tag()->album().toCString());
|
|
||||||
strcpy(sng->Genre, file.tag()->genre().toCString());
|
|
||||||
sng->Year = file.tag()->year();
|
|
||||||
sng->Duration = file.audioProperties()->lengthInSeconds();
|
|
||||||
strcpy(sng->SongPath, song_path);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cover metadata_retriever::update_cover_art(Cover cov, const Song song, const std::string& root_path)
|
Cover metadata_retriever::update_cover_art(const Song& song, Cover& cov, const std::string& stockCoverPath)
|
||||||
{
|
{
|
||||||
TagLib::MPEG::File sngF(song.songPath.c_str());
|
TagLib::MPEG::File sngF(song.songPath.c_str());
|
||||||
TagLib::ID3v2::Tag *tag = sngF.ID3v2Tag();
|
auto tag = sngF.ID3v2Tag();
|
||||||
auto frameList = tag->frameListMap()["APIC"];
|
auto frameList = tag->frameListMap()["APIC"];
|
||||||
|
|
||||||
if (frameList.isEmpty()) {
|
if (frameList.isEmpty()) {
|
||||||
std::string stock_path{root_path};
|
cov.imagePath.append("CoverArt.png");
|
||||||
stock_path.append("CoverArt.png");
|
|
||||||
cov.imagePath = stock_path;
|
if (!fs::exists(cov.imagePath)) {
|
||||||
//strcpy(cov->ImagePath, stock_path.c_str());
|
std::cout << "copying stock cover path" << std::endl;
|
||||||
|
fs::copy(stockCoverPath, cov.imagePath);
|
||||||
|
}
|
||||||
|
|
||||||
imageFile stock_img(cov.imagePath.c_str());
|
imageFile stock_img(cov.imagePath.c_str());
|
||||||
|
|
||||||
@@ -61,23 +56,23 @@ Cover metadata_retriever::update_cover_art(Cover cov, const Song song, const std
|
|||||||
tag->addFrame(pic);
|
tag->addFrame(pic);
|
||||||
|
|
||||||
sngF.save();
|
sngF.save();
|
||||||
std::cout<<"applied stock cover art"<<std::endl;
|
std::cout << "applied stock cover art" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
auto frame = dynamic_cast<TagLib::ID3v2::AttachedPictureFrame*>(
|
auto frame = dynamic_cast<TagLib::ID3v2::AttachedPictureFrame*>(
|
||||||
frameList.front());
|
frameList.front());
|
||||||
directory_manager dir;
|
directory_manager dir;
|
||||||
auto img_path = dir.create_directory_process(song, root_path);
|
auto img_path = dir.create_directory_process(song, cov.imagePath);
|
||||||
img_path.append(song.title);
|
img_path.append(song.title);
|
||||||
img_path.append(".png");
|
img_path.append(".png");
|
||||||
cov.imagePath = img_path;
|
cov.imagePath = img_path;
|
||||||
//strcpy(cov->ImagePath, img_path.c_str());
|
|
||||||
std::cout<<cov.imagePath<<std::endl;
|
std::cout << cov.imagePath << std::endl;
|
||||||
|
|
||||||
std::fstream img_save(cov.imagePath, std::ios::out |
|
std::fstream img_save(cov.imagePath, std::ios::out |
|
||||||
std::ios::binary);
|
std::ios::binary);
|
||||||
img_save.write(frame->picture().data(), frame->picture().size());
|
img_save.write(frame->picture().data(), frame->picture().size());
|
||||||
img_save.close();
|
img_save.close();
|
||||||
std::cout<<"saved to "<<cov.imagePath<<std::endl;
|
std::cout << "saved to " << cov.imagePath << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cov;
|
return cov;
|
||||||
|
|||||||
Reference in New Issue
Block a user