Blank slate
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
[submodule "3rdparty/vcpkg"]
|
|
||||||
path = vcpkg
|
|
||||||
url = https://github.com/microsoft/vcpkg
|
|
||||||
|
|||||||
-108
@@ -1,108 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20.6)
|
|
||||||
|
|
||||||
if(NOT DEFINED VCPKG_ROOT_PATH)
|
|
||||||
set(VCPKG_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/vcpkg)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
message("The vcpkg root path ${VCPKG_ROOT_PATH}")
|
|
||||||
|
|
||||||
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
|
|
||||||
set(TOOLCHAIN_PATH ${VCPKG_ROOT_PATH}/scripts/buildsystems/vcpkg.cmake)
|
|
||||||
|
|
||||||
set(CMAKE_TOOLCHAIN_FILE
|
|
||||||
"${TOOLCHAIN_PATH}"
|
|
||||||
CACHE STRING "Vcpkg toolchain file")
|
|
||||||
|
|
||||||
message("Using default toolchain file")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
set(SOFTWARE_DESCRIPTION
|
|
||||||
"A tool to interact with the Icarus Music streaming API")
|
|
||||||
set(SOFTWARE_VERSION
|
|
||||||
"0.3.2")
|
|
||||||
|
|
||||||
|
|
||||||
project(IcarusDownloadManager VERSION ${SOFTWARE_VERSION} DESCRIPTION ${SOFTWARE_DESCRIPTION} LANGUAGES CXX)
|
|
||||||
|
|
||||||
|
|
||||||
message(STATUS "Checking compiler flags for C++20 support.")
|
|
||||||
|
|
||||||
# Set C++20 support flags for various compilers
|
|
||||||
include(CheckCXXCompilerFlag)
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
message("Windows environment")
|
|
||||||
|
|
||||||
if (MSVC_VERSION GREATER_EQUAL "1900")
|
|
||||||
message("Visual Studio version is at least ${vs_ver}")
|
|
||||||
|
|
||||||
include(CheckCXXCompilerFlag)
|
|
||||||
CHECK_CXX_COMPILER_FLAG("/std:c++20" _cpp_latest_flag_supported)
|
|
||||||
if (_cpp_latest_flag_supported)
|
|
||||||
add_compile_options("/std:c++20")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
|
|
||||||
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
|
||||||
|
|
||||||
if(COMPILER_SUPPORTS_CXX20)
|
|
||||||
message(STATUS "C++20 is supported.")
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -stdlib=libc++")
|
|
||||||
else()
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
|
|
||||||
endif()
|
|
||||||
elseif(COMPILER_SUPPORTS_CXX0X)
|
|
||||||
message(STATUS "C++0x is supported.")
|
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++")
|
|
||||||
else()
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++20 support. Please use a different C++ compiler.")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
set(SOURCES
|
|
||||||
src/Main.cpp
|
|
||||||
src/Managers/ActionManager.cpp
|
|
||||||
src/Managers/CommitManager.cpp
|
|
||||||
src/Managers/FileManager.cpp
|
|
||||||
src/Managers/TokenManager.cpp
|
|
||||||
src/Managers/UserManager.cpp
|
|
||||||
src/Models/Song.cpp
|
|
||||||
src/Parsers/APIParser.cpp
|
|
||||||
src/Syncers/Delete.cpp
|
|
||||||
src/Syncers/Download.cpp
|
|
||||||
src/Syncers/RetrieveRecords.cpp
|
|
||||||
src/Syncers/Upload.cpp
|
|
||||||
src/Utilities/Conversions.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set(IDM_INCLUDE_DIR
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/include")
|
|
||||||
|
|
||||||
include_directories(${IDM_INCLUDE_DIR})
|
|
||||||
|
|
||||||
set(USE_SYSTEM_CURL OFF)
|
|
||||||
set(BUILD_CPR_TESTS OFF)
|
|
||||||
|
|
||||||
find_package(nlohmann_json CONFIG REQUIRED)
|
|
||||||
find_package(OpenSSL REQUIRED)
|
|
||||||
find_package(CURL REQUIRED)
|
|
||||||
find_package(cpr CONFIG REQUIRED)
|
|
||||||
|
|
||||||
|
|
||||||
add_executable(icd ${SOURCES})
|
|
||||||
target_link_libraries(icd PRIVATE nlohmann_json::nlohmann_json OpenSSL::SSL OpenSSL::Crypto CURL::libcurl cpr::cpr)
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
// Microsoft Visual C++ generated resource script.
|
|
||||||
//
|
|
||||||
#include "resource.h"
|
|
||||||
|
|
||||||
#define APSTUDIO_READONLY_SYMBOLS
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Generated from the TEXTINCLUDE 2 resource.
|
|
||||||
//
|
|
||||||
#include "winres.h"
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
#undef APSTUDIO_READONLY_SYMBOLS
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// English (United States) resources
|
|
||||||
|
|
||||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
|
||||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
|
||||||
#pragma code_page(1252)
|
|
||||||
|
|
||||||
#ifdef APSTUDIO_INVOKED
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// TEXTINCLUDE
|
|
||||||
//
|
|
||||||
|
|
||||||
1 TEXTINCLUDE
|
|
||||||
BEGIN
|
|
||||||
"resource.h\0"
|
|
||||||
END
|
|
||||||
|
|
||||||
2 TEXTINCLUDE
|
|
||||||
BEGIN
|
|
||||||
"#include ""winres.h""\r\n"
|
|
||||||
"\0"
|
|
||||||
END
|
|
||||||
|
|
||||||
3 TEXTINCLUDE
|
|
||||||
BEGIN
|
|
||||||
"\r\n"
|
|
||||||
"\0"
|
|
||||||
END
|
|
||||||
|
|
||||||
#endif // APSTUDIO_INVOKED
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Version
|
|
||||||
//
|
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
|
||||||
FILEVERSION 0,3,2,0
|
|
||||||
PRODUCTVERSION 0,3,2,0
|
|
||||||
FILEFLAGSMASK 0x3fL
|
|
||||||
#ifdef _DEBUG
|
|
||||||
FILEFLAGS 0x1L
|
|
||||||
#else
|
|
||||||
FILEFLAGS 0x0L
|
|
||||||
#endif
|
|
||||||
FILEOS 0x40004L
|
|
||||||
FILETYPE 0x1L
|
|
||||||
FILESUBTYPE 0x0L
|
|
||||||
BEGIN
|
|
||||||
BLOCK "StringFileInfo"
|
|
||||||
BEGIN
|
|
||||||
BLOCK "040904b0"
|
|
||||||
BEGIN
|
|
||||||
VALUE "FileDescription", "Tool to interact with Icarus API"
|
|
||||||
VALUE "FileVersion", "0.3.2.0"
|
|
||||||
VALUE "InternalName", "IcarusDo.exe"
|
|
||||||
VALUE "LegalCopyright", "Copyright (C) 2022"
|
|
||||||
VALUE "OriginalFilename", "IcarusDo.exe"
|
|
||||||
VALUE "ProductName", "IcarusDownloadManager"
|
|
||||||
VALUE "ProductVersion", "0.3.2.0"
|
|
||||||
END
|
|
||||||
END
|
|
||||||
BLOCK "VarFileInfo"
|
|
||||||
BEGIN
|
|
||||||
VALUE "Translation", 0x409, 1200
|
|
||||||
END
|
|
||||||
END
|
|
||||||
|
|
||||||
#endif // English (United States) resources
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef APSTUDIO_INVOKED
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Generated from the TEXTINCLUDE 3 resource.
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
#endif // not APSTUDIO_INVOKED
|
|
||||||
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.2.32630.192
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IcarusDownloadManager", "IcarusDownloadManager.vcxproj", "{12955990-643F-4A99-95E5-4752AFA179B0}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|x64 = Debug|x64
|
|
||||||
Debug|x86 = Debug|x86
|
|
||||||
Release|x64 = Release|x64
|
|
||||||
Release|x86 = Release|x86
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{12955990-643F-4A99-95E5-4752AFA179B0}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{12955990-643F-4A99-95E5-4752AFA179B0}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{12955990-643F-4A99-95E5-4752AFA179B0}.Debug|x86.ActiveCfg = Debug|Win32
|
|
||||||
{12955990-643F-4A99-95E5-4752AFA179B0}.Debug|x86.Build.0 = Debug|Win32
|
|
||||||
{12955990-643F-4A99-95E5-4752AFA179B0}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{12955990-643F-4A99-95E5-4752AFA179B0}.Release|x64.Build.0 = Release|x64
|
|
||||||
{12955990-643F-4A99-95E5-4752AFA179B0}.Release|x86.ActiveCfg = Release|Win32
|
|
||||||
{12955990-643F-4A99-95E5-4752AFA179B0}.Release|x86.Build.0 = Release|Win32
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {EA22B463-3EA6-4452-9AF1-D300C3BDE72D}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
|
||||||
<ProjectConfiguration Include="Debug|Win32">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|Win32">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Debug|x64">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|x64">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
</ItemGroup>
|
|
||||||
<PropertyGroup Label="Globals">
|
|
||||||
<VCProjectVersion>17.0</VCProjectVersion>
|
|
||||||
<ProjectGuid>{12955990-643F-4A99-95E5-4752AFA179B0}</ProjectGuid>
|
|
||||||
<Keyword>Win32Proj</Keyword>
|
|
||||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
|
||||||
<CharacterSet>NotSet</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
|
||||||
<CharacterSet>NotSet</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
|
||||||
<ImportGroup Label="ExtensionSettings">
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="Shared">
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<PropertyGroup Label="UserMacros" />
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<LinkIncremental>true</LinkIncremental>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<LinkIncremental>true</LinkIncremental>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<IncludePath>$(ProjectDir)include;$(IncludePath)</IncludePath>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<IncludePath>$(ProjectDir)include;$(IncludePath)</IncludePath>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<TargetMachine>MachineX86</TargetMachine>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<SubSystem>Windows</SubSystem>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<TargetMachine>MachineX86</TargetMachine>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<SubSystem>Windows</SubSystem>
|
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include="src\Main.cpp" />
|
|
||||||
<ClCompile Include="src\managers\ActionManager.cpp" />
|
|
||||||
<ClCompile Include="src\managers\CommitManager.cpp" />
|
|
||||||
<ClCompile Include="src\managers\FileManager.cpp" />
|
|
||||||
<ClCompile Include="src\managers\TokenManager.cpp" />
|
|
||||||
<ClCompile Include="src\managers\UserManager.cpp" />
|
|
||||||
<ClCompile Include="src\models\Song.cpp" />
|
|
||||||
<ClCompile Include="src\parsers\APIParser.cpp" />
|
|
||||||
<ClCompile Include="src\syncers\Delete.cpp" />
|
|
||||||
<ClCompile Include="src\syncers\Download.cpp" />
|
|
||||||
<ClCompile Include="src\syncers\RetrieveRecords.cpp" />
|
|
||||||
<ClCompile Include="src\syncers\Upload.cpp" />
|
|
||||||
<ClCompile Include="src\utilities\Conversions.cpp" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="include\managers\ActionManager.h" />
|
|
||||||
<ClInclude Include="include\managers\CommitManager.h" />
|
|
||||||
<ClInclude Include="include\managers\FileManager.h" />
|
|
||||||
<ClInclude Include="include\managers\TokenManager.h" />
|
|
||||||
<ClInclude Include="include\managers\UserManager.h" />
|
|
||||||
<ClInclude Include="include\models\API.h" />
|
|
||||||
<ClInclude Include="include\models\Flags.h" />
|
|
||||||
<ClInclude Include="include\models\IcarusAction.h" />
|
|
||||||
<ClInclude Include="include\models\Song.h" />
|
|
||||||
<ClInclude Include="include\models\Token.h" />
|
|
||||||
<ClInclude Include="include\models\UploadForm.h" />
|
|
||||||
<ClInclude Include="include\models\User.h" />
|
|
||||||
<ClInclude Include="include\parsers\APIParser.h" />
|
|
||||||
<ClInclude Include="include\syncers\Delete.h" />
|
|
||||||
<ClInclude Include="include\syncers\Download.h" />
|
|
||||||
<ClInclude Include="include\syncers\RetrieveRecords.h" />
|
|
||||||
<ClInclude Include="include\syncers\SyncerBase.h" />
|
|
||||||
<ClInclude Include="include\syncers\Upload.h" />
|
|
||||||
<ClInclude Include="include\utilities\Checks.h" />
|
|
||||||
<ClInclude Include="include\utilities\Conversions.h" />
|
|
||||||
<ClInclude Include="resource.h" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ResourceCompile Include="IcarusDownloadManager.rc" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
||||||
<ImportGroup Label="ExtensionTargets">
|
|
||||||
</ImportGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup>
|
|
||||||
<Filter Include="Source Files">
|
|
||||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
|
||||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Header Files">
|
|
||||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
|
||||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Resource Files">
|
|
||||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
|
||||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
|
|
||||||
</Filter>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include="src\Main.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\managers\ActionManager.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\managers\CommitManager.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\managers\FileManager.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\managers\TokenManager.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\managers\UserManager.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\models\Song.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\parsers\APIParser.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\syncers\Delete.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\syncers\Download.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\syncers\RetrieveRecords.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\syncers\Upload.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\utilities\Conversions.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="include\managers\ActionManager.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\managers\CommitManager.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\managers\FileManager.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\managers\TokenManager.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\managers\UserManager.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\models\API.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\models\Flags.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\models\IcarusAction.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\models\Song.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\models\Token.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\models\UploadForm.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\models\User.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\parsers\APIParser.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\syncers\Delete.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\syncers\Download.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\syncers\RetrieveRecords.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\syncers\SyncerBase.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\syncers\Upload.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\utilities\Checks.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="include\utilities\Conversions.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<LocalDebuggerCommandArguments>upload-meta -u kverse -p demolaugh -h http://localhost:5002 -smca "D:\OneDrive\media\music\mp3\bb_king\paying_the_cost_to_be_the_boss"</LocalDebuggerCommandArguments>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<LocalDebuggerCommandArguments>upload-meta -u kverse -p demolaugh -h http://localhost:5002 -smca "D:\OneDrive\media\music\mp3\bb_king\paying_the_cost_to_be_the_boss"</LocalDebuggerCommandArguments>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
#ifndef ACTIONMANAGER_H_
|
|
||||||
#define ACTIONMANAGER_H_
|
|
||||||
|
|
||||||
#include<algorithm>
|
|
||||||
#include<string>
|
|
||||||
#include<string_view>
|
|
||||||
#include<array>
|
|
||||||
#include<vector>
|
|
||||||
|
|
||||||
#include"Models/Flags.h"
|
|
||||||
#include"Models/IcarusAction.h"
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ActionManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ActionManager(char**, int);
|
|
||||||
|
|
||||||
Models::IcarusAction retrieveIcarusAction() const;
|
|
||||||
private:
|
|
||||||
constexpr std::array<const char*, 16> supportedFlags() noexcept
|
|
||||||
{
|
|
||||||
constexpr std::array<const char*, 16> allFlags{"-u", "-p", "-t", "-h", "-s",
|
|
||||||
"-sd", "-sr", "-d", "-D", "-b", "-rt", "-nc",
|
|
||||||
"-m", "-ca", "-smca", "-t"};
|
|
||||||
|
|
||||||
return allFlags;
|
|
||||||
}
|
|
||||||
constexpr std::array<const char*, 4> supportedActions() noexcept;
|
|
||||||
|
|
||||||
void initialize();
|
|
||||||
void validateFlags();
|
|
||||||
// Checks to see if the flag is valid
|
|
||||||
template<typename Str>
|
|
||||||
bool isValidFlag(const Str flag)
|
|
||||||
{
|
|
||||||
const auto flags = supportedFlags();
|
|
||||||
const auto i = std::find_if(flags.begin(), flags.end(), [&](const Str &f)
|
|
||||||
{
|
|
||||||
return f.compare(flag) == 0 ? true : false;
|
|
||||||
});
|
|
||||||
|
|
||||||
auto result = i != flags.end() ? true : false;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Str>
|
|
||||||
bool doesFlagHaveValue(const Str flag)
|
|
||||||
{
|
|
||||||
const auto flags = parsedFlags();
|
|
||||||
auto i = std::find_if(flags.begin(), flags.end(), [&](const Str &f)
|
|
||||||
{
|
|
||||||
return f.compare(flag) == 0 ? true : false;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (i != flags.end())
|
|
||||||
{
|
|
||||||
if (++i != flags.end() && !isValidFlag<Str>(*i))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void printAction() noexcept;
|
|
||||||
void printFlags() noexcept;
|
|
||||||
|
|
||||||
std::vector<std::string> parsedFlags();
|
|
||||||
|
|
||||||
std::string action;
|
|
||||||
|
|
||||||
std::vector<Models::Flags> flags;
|
|
||||||
|
|
||||||
char **params;
|
|
||||||
int paramCount;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,220 +0,0 @@
|
|||||||
#ifndef COMMITMANAGER_H_
|
|
||||||
#define COMMITMANAGER_H_
|
|
||||||
|
|
||||||
#include<map>
|
|
||||||
#include<iostream>
|
|
||||||
#include<filesystem>
|
|
||||||
#include<string>
|
|
||||||
#include<string_view>
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/IcarusAction.h"
|
|
||||||
#include"Models/Song.h"
|
|
||||||
#include"Models/Token.h"
|
|
||||||
#include"Utilities/Checks.h"
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
|
|
||||||
class CommitManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CommitManager(Models::IcarusAction&);
|
|
||||||
|
|
||||||
void commitAction();
|
|
||||||
|
|
||||||
|
|
||||||
enum class RetrieveTypes
|
|
||||||
{
|
|
||||||
songs
|
|
||||||
};
|
|
||||||
|
|
||||||
// Used for parsing songs from the metadata file
|
|
||||||
class Album
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Album() = default;
|
|
||||||
|
|
||||||
void printInfo();
|
|
||||||
|
|
||||||
|
|
||||||
std::string album;
|
|
||||||
std::string albumArtist;
|
|
||||||
std::string genre;
|
|
||||||
int year;
|
|
||||||
int trackCount;
|
|
||||||
int discCount;
|
|
||||||
std::vector<Models::Song> songs;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum class ActionValues;
|
|
||||||
|
|
||||||
std::map<std::string, ActionValues> mapActions() noexcept;
|
|
||||||
|
|
||||||
void deleteSong();
|
|
||||||
void downloadSong();
|
|
||||||
void retrieveObjects();
|
|
||||||
void uploadSong();
|
|
||||||
|
|
||||||
Models::Token parseToken(Models::API);
|
|
||||||
|
|
||||||
// Uploads a single song. The song is constructed from a metadata file that contains
|
|
||||||
// information about the album the song is from. Also, the cover art of the song must
|
|
||||||
// be present.
|
|
||||||
//
|
|
||||||
// Expects
|
|
||||||
// * Song - mp3 file path
|
|
||||||
// * 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
|
|
||||||
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<typename Song, typename Str>
|
|
||||||
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 file = std::filesystem::path(songPath);
|
|
||||||
auto filename = file.filename().string();;
|
|
||||||
|
|
||||||
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<char, Str>(filename, 'd', dl);
|
|
||||||
auto k = Utilities::Checks::itemIterInContainer<char, Str>(filename, 'k', dl);
|
|
||||||
auto dot = Utilities::Checks::itemIterInContainer<char, Str>(filename, '.', dl);
|
|
||||||
|
|
||||||
switch(mode)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
// if (k != songPath.end() && dot != songPath.end())
|
|
||||||
if (k != filename.end() && dot != filename.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())
|
|
||||||
if (k != filename.end() && dot != filename.end() && d != filename.end())
|
|
||||||
{
|
|
||||||
auto tStr = std::string(++k, d);
|
|
||||||
auto dStr = std::string(++d, dot);
|
|
||||||
std::cout<<"DStr: "<<dStr<<" TStr: " << tStr<<"\n";
|
|
||||||
|
|
||||||
if (Utilities::Checks::isNumber(tStr))
|
|
||||||
{
|
|
||||||
track = std::atoi(tStr.c_str());
|
|
||||||
}
|
|
||||||
else if (Utilities::Checks::isNumber(dStr))
|
|
||||||
{
|
|
||||||
disc = std::atoi(dStr.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
song.disc = disc;
|
|
||||||
song.track = track;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Song, typename Str>
|
|
||||||
void parseDiscAndTrack(Song &song, const Str &trackID)
|
|
||||||
{
|
|
||||||
auto sep = [](char c, char t) { return c == t; };
|
|
||||||
auto separator = Utilities::Checks::itemIterInContainer<char, Str>(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()
|
|
||||||
{
|
|
||||||
for (const auto &arg: this->icaAction.flags)
|
|
||||||
{
|
|
||||||
if (arg.flag.compare("-nc") == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Album retrieveMetadata(const std::string_view path);
|
|
||||||
std::string retrieveFileContent(const std::string_view path);
|
|
||||||
|
|
||||||
enum class ActionValues
|
|
||||||
{
|
|
||||||
deleteAct,
|
|
||||||
downloadAct,
|
|
||||||
retrieveAct,
|
|
||||||
uploadAct,
|
|
||||||
UPLOAD_SONG_WITH_METADATA // Uploads the song with metadata, including cover art
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Models::IcarusAction icaAction;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
#ifndef FILEMANAGER_H_
|
|
||||||
#define FILEMANAGER_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
|
|
||||||
class FileManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FileManager();
|
|
||||||
FileManager(std::string);
|
|
||||||
|
|
||||||
void saveFile(std::string);
|
|
||||||
void modifyFilePath(std::string);
|
|
||||||
|
|
||||||
char* retrieveFileBuffer() const;
|
|
||||||
int retrieveFileBufferLength() const;
|
|
||||||
private:
|
|
||||||
void readFile();
|
|
||||||
|
|
||||||
std::string filePath;
|
|
||||||
char* fileBuffer;
|
|
||||||
bool fileRead;
|
|
||||||
int fileBufferLength;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#ifndef TOKENMANAGER_H_
|
|
||||||
#define TOKENMANAGER_H_
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/Token.h"
|
|
||||||
#include"Models/User.h"
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
|
|
||||||
class TokenManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TokenManager(const Models::User&);
|
|
||||||
TokenManager(const Models::User&, Models::API&);
|
|
||||||
|
|
||||||
Models::Token requestToken();
|
|
||||||
private:
|
|
||||||
Models::API api;
|
|
||||||
Models::User user;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#ifndef USERMANAGER_H_
|
|
||||||
#define USERMANAGER_H_
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
|
|
||||||
#include"Models/IcarusAction.h"
|
|
||||||
#include"Models/User.h"
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
|
|
||||||
class UserManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
UserManager(Models::User);
|
|
||||||
UserManager(const Models::IcarusAction);
|
|
||||||
|
|
||||||
Models::User retrieveUser() const;
|
|
||||||
private:
|
|
||||||
void parseUserFromActions();
|
|
||||||
|
|
||||||
Models::User user;
|
|
||||||
Models::IcarusAction icaAction;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#ifndef API_H_
|
|
||||||
#define API_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
|
|
||||||
class API
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string url;
|
|
||||||
std::string endpoint;
|
|
||||||
std::string version;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef FLAGS_H_
|
|
||||||
#define FLAGS_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
|
|
||||||
class Flags
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string flag;
|
|
||||||
std::string value;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
#ifndef ICARUSACTION_H_
|
|
||||||
#define ICARUSACTION_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
#include<algorithm>
|
|
||||||
#include<string_view>
|
|
||||||
#include<vector>
|
|
||||||
#include<iostream>
|
|
||||||
|
|
||||||
#include"Flags.h"
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
|
|
||||||
class IcarusAction
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string retrieveFlagValue(const std::string_view flag)
|
|
||||||
{
|
|
||||||
std::string value;
|
|
||||||
|
|
||||||
const auto fg = std::find_if(flags.begin(), flags.end(), [&](Flags f)
|
|
||||||
{
|
|
||||||
return f.flag.compare(flag) == 0 ? true : false;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (fg != flags.end())
|
|
||||||
{
|
|
||||||
value.assign(fg->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
void print_action_and_flags() noexcept
|
|
||||||
{
|
|
||||||
std::cout<<"Action: "<<this->action<<"\n";
|
|
||||||
std::cout<<"Flag count: "<<this->flags.size()<<"\n";
|
|
||||||
|
|
||||||
for (const auto &flag : this->flags)
|
|
||||||
{
|
|
||||||
std::cout<<"flag "<<flag.flag<<" value "<<flag.value<<"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout<<"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string action;
|
|
||||||
std::vector<Flags> flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
#ifndef SONG_H_
|
|
||||||
#define SONG_H_
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
|
|
||||||
class Song
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Song() = default;
|
|
||||||
|
|
||||||
void printInfo()
|
|
||||||
{
|
|
||||||
std::cout<<"Title: "<<this->title<<"\n";
|
|
||||||
std::cout<<"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string song_path() noexcept
|
|
||||||
{
|
|
||||||
std::stringstream buffer;
|
|
||||||
|
|
||||||
buffer << this->directory;
|
|
||||||
|
|
||||||
const auto count = this->directory.size();
|
|
||||||
|
|
||||||
if (this->directory.at(count - 1) != '/' || this->directory.at(count - 1) != '\\')
|
|
||||||
{
|
|
||||||
buffer << "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer << this->filename;
|
|
||||||
|
|
||||||
return buffer.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
int generate_filename_from_track()
|
|
||||||
{
|
|
||||||
auto result = 0;
|
|
||||||
std::stringstream buffer;
|
|
||||||
buffer << "track";
|
|
||||||
|
|
||||||
// NOTE: Multiple discs in one directory is not being addressed
|
|
||||||
if (this->track < 10)
|
|
||||||
{
|
|
||||||
buffer << "0";
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer << this->track << ".mp3";
|
|
||||||
|
|
||||||
|
|
||||||
this->filename.assign(buffer.str());
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string toMetadataJson();
|
|
||||||
|
|
||||||
|
|
||||||
int id;
|
|
||||||
std::string title;
|
|
||||||
std::string artist;
|
|
||||||
std::string album;
|
|
||||||
std::string genre;
|
|
||||||
int year;
|
|
||||||
int duration;
|
|
||||||
int track;
|
|
||||||
int disc;
|
|
||||||
std::string data;
|
|
||||||
[[deprecated("Use song_path() function instead")]]
|
|
||||||
std::string songPath;
|
|
||||||
std::string filename;
|
|
||||||
std::string directory;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CoverArt
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int id;
|
|
||||||
std::string title;
|
|
||||||
std::string path;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef TOKEN_H_
|
|
||||||
#define TOKEN_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
|
|
||||||
struct Token
|
|
||||||
{
|
|
||||||
std::string accessToken;
|
|
||||||
std::string tokenType;
|
|
||||||
int expiration;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef UPLOADFORM_H_
|
|
||||||
#define UPLOADFORM_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
|
|
||||||
struct UploadForm
|
|
||||||
{
|
|
||||||
std::string url;
|
|
||||||
std::string filePath;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#ifndef USER_H_
|
|
||||||
#define USER_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
|
|
||||||
struct User
|
|
||||||
{
|
|
||||||
std::string username;
|
|
||||||
std::string password;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#ifndef APIPARSER_H_
|
|
||||||
#define APIPARSER_H_
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/IcarusAction.h"
|
|
||||||
|
|
||||||
namespace Parsers
|
|
||||||
{
|
|
||||||
|
|
||||||
class APIParser
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
APIParser(Models::IcarusAction);
|
|
||||||
|
|
||||||
Models::API retrieveAPI() const;
|
|
||||||
private:
|
|
||||||
void parseAPI();
|
|
||||||
|
|
||||||
Models::API api;
|
|
||||||
Models::IcarusAction icaAct;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#ifndef DELETE_H_
|
|
||||||
#define DELETE_H_
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/Song.h"
|
|
||||||
#include"Models/Token.h"
|
|
||||||
|
|
||||||
#include"SyncerBase.h"
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
|
|
||||||
class Delete : SyncerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Delete(Models::API);
|
|
||||||
|
|
||||||
void deleteSong(const Models::Token, Models::Song);
|
|
||||||
private:
|
|
||||||
std::string retrieveUrl(Models::Song);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#ifndef DOWNLOAD_H_
|
|
||||||
#define DOWNLOAD_H_
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
#include"Models/Song.h"
|
|
||||||
#include"Models/Token.h"
|
|
||||||
|
|
||||||
#include"SyncerBase.h"
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
|
|
||||||
class Download : SyncerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Download();
|
|
||||||
Download(Models::API);
|
|
||||||
Download(std::string);
|
|
||||||
|
|
||||||
void downloadSong(const Models::Token token, Models::Song);
|
|
||||||
private:
|
|
||||||
std::string retrieveUrl(Models::Song);
|
|
||||||
|
|
||||||
std::string downloadFilePath;
|
|
||||||
void saveSong(Models::Song&);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#ifndef RETRIEVERECORDS_H_
|
|
||||||
#define RETRIEVERECORDS_H_
|
|
||||||
|
|
||||||
#include "Managers/CommitManager.h"
|
|
||||||
#include "Models/API.h"
|
|
||||||
#include "Models/Token.h"
|
|
||||||
#include "Syncers/SyncerBase.h"
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
|
|
||||||
class RetrieveRecords: public SyncerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RetrieveRecords();
|
|
||||||
RetrieveRecords(Models::API, Models::Token);
|
|
||||||
|
|
||||||
void retrieve(Managers::CommitManager::RetrieveTypes);
|
|
||||||
private:
|
|
||||||
void fetchSongs();
|
|
||||||
|
|
||||||
Models::API api;
|
|
||||||
Models::Token token;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#ifndef SYNCERBASE_H_
|
|
||||||
#define SYNCERBASE_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#include"Models/API.h"
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
|
|
||||||
class SyncerBase
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
Models::API api;
|
|
||||||
const int OK = 200;
|
|
||||||
const int UNAUTHORIZED = 401;
|
|
||||||
const int NOTFOUND = 404;
|
|
||||||
|
|
||||||
enum class Result
|
|
||||||
{
|
|
||||||
OK = 200,
|
|
||||||
UNAUTHORIZED = 401,
|
|
||||||
NOTFOUND = 404
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
#ifndef UPLOAD_H_
|
|
||||||
#define UPLOAD_H_
|
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include "Managers/CommitManager.h"
|
|
||||||
#include "Managers/FileManager.h"
|
|
||||||
#include "Models/API.h"
|
|
||||||
#include "Models/Song.h"
|
|
||||||
#include "Models/Token.h"
|
|
||||||
#include "Models/UploadForm.h"
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
|
|
||||||
class Upload
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Upload() = default;
|
|
||||||
Upload(Models::API api, Models::Token token) : m_token(token), api(api)
|
|
||||||
{
|
|
||||||
this->api.endpoint = "song/data";
|
|
||||||
}
|
|
||||||
|
|
||||||
Models::Song uploadSong(Models::Song&);
|
|
||||||
void uploadSongsFromDirectory(const std::string&, const bool, bool);
|
|
||||||
void uploadSongWithMetadata(Managers::CommitManager::Album&, Models::Song&, Models::CoverArt&);
|
|
||||||
private:
|
|
||||||
Managers::FileManager fMgr;
|
|
||||||
Models::API api;
|
|
||||||
Models::Song song;
|
|
||||||
Models::Token m_token;
|
|
||||||
|
|
||||||
std::vector<Models::Song> retrieveAllSongsFromDirectory(const std::string&,
|
|
||||||
bool);
|
|
||||||
|
|
||||||
std::string retrieveUrl();
|
|
||||||
|
|
||||||
Models::Song retrieveSongPath(fs::directory_entry&);
|
|
||||||
|
|
||||||
void printSongDetails();
|
|
||||||
void printSongDetails(std::vector<Models::Song>&);
|
|
||||||
void printJsonData(const nlohmann::json&);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#ifndef ABOUTWINDOW_H_
|
|
||||||
#define ABOUTWINDOW_H_
|
|
||||||
|
|
||||||
#include<memory>
|
|
||||||
|
|
||||||
#include<QDialog>
|
|
||||||
#include<QDockWidget>
|
|
||||||
#include<QLabel>
|
|
||||||
#include<QPushButton>
|
|
||||||
#include<QWidget>
|
|
||||||
|
|
||||||
#include"UI/CommonWindow.h"
|
|
||||||
|
|
||||||
namespace UI
|
|
||||||
{
|
|
||||||
|
|
||||||
class AboutWindow: public QDialog, public CommonWindow
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
AboutWindow(QWidget* parent=0);
|
|
||||||
~AboutWindow() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void connections();
|
|
||||||
void setupWindow();
|
|
||||||
|
|
||||||
std::unique_ptr<QLabel> appName;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void closeWindow();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#ifndef COMMONWINDOW_H_
|
|
||||||
#define COMMONWINDOW_H_
|
|
||||||
|
|
||||||
#include<memory>
|
|
||||||
|
|
||||||
#include<QDialog>
|
|
||||||
#include<QHBoxLayout>
|
|
||||||
#include<QVBoxLayout>
|
|
||||||
#include<QComboBox>
|
|
||||||
#include<QPushButton>
|
|
||||||
|
|
||||||
|
|
||||||
namespace UI
|
|
||||||
{
|
|
||||||
|
|
||||||
class CommonWindow
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CommonWindow() = default;
|
|
||||||
~CommonWindow() = default;
|
|
||||||
protected:
|
|
||||||
virtual void connections()=0;
|
|
||||||
std::unique_ptr<QComboBox> selectionBoxQt;
|
|
||||||
std::unique_ptr<QPushButton> actionButtonQt;
|
|
||||||
std::unique_ptr<QVBoxLayout> mainLayoutQt;
|
|
||||||
std::unique_ptr<QVBoxLayout> subLayoutOneQt;
|
|
||||||
std::unique_ptr<QVBoxLayout> subLayoutTwoQt;
|
|
||||||
int windowHeight, windowWidth;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
#ifndef MAINWINDOW_H_
|
|
||||||
#define MAINWINDOW_H_
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
#include<memory>
|
|
||||||
|
|
||||||
#include<QAction>
|
|
||||||
#include<QComboBox>
|
|
||||||
#include<QDialog>
|
|
||||||
#include<QDockWidget>
|
|
||||||
#include<QLabel>
|
|
||||||
#include<QMenu>
|
|
||||||
#include<QMenuBar>
|
|
||||||
#include<QMainWindow>
|
|
||||||
#include<QPushButton>
|
|
||||||
#include<QStackedWidget>
|
|
||||||
#include<QTextEdit>
|
|
||||||
#include<QWidget>
|
|
||||||
|
|
||||||
#include"UI/CommonWindow.h"
|
|
||||||
#include"UI/AboutWindow.h"
|
|
||||||
|
|
||||||
namespace UI
|
|
||||||
{
|
|
||||||
|
|
||||||
class MainWindow: public QMainWindow, public CommonWindow
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
MainWindow();
|
|
||||||
~MainWindow() = default;
|
|
||||||
private:
|
|
||||||
void configureDownloadSection();
|
|
||||||
void configureUploadSection();
|
|
||||||
void configureWindowDimensions();
|
|
||||||
void configureWindowProperties();
|
|
||||||
void connections();
|
|
||||||
void createMenus();
|
|
||||||
void setupMainWidget();
|
|
||||||
void setupMainWindow();
|
|
||||||
void setupWindowLists();
|
|
||||||
|
|
||||||
|
|
||||||
std::unique_ptr<QStackedWidget> widgetStack;
|
|
||||||
|
|
||||||
std::unique_ptr<QVBoxLayout> stackLayout;
|
|
||||||
|
|
||||||
std::unique_ptr<QHBoxLayout> urlPortion;
|
|
||||||
std::unique_ptr<QHBoxLayout> songPathPortion;
|
|
||||||
|
|
||||||
std::unique_ptr<QWidget> mainWidgetQt;
|
|
||||||
std::unique_ptr<QWidget> uploadSongWidgetQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QDockWidget> MainDockWidgetQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QComboBox> windowComboBox;
|
|
||||||
|
|
||||||
std::unique_ptr<QPushButton> uploadSongQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QTextEdit> urlQt;
|
|
||||||
std::unique_ptr<QTextEdit> sourceFilePathQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QLabel> urlLabel;
|
|
||||||
std::unique_ptr<QLabel> songPath;
|
|
||||||
|
|
||||||
std::unique_ptr<QMenu> fileMenuQt;
|
|
||||||
std::unique_ptr<QMenu> editMenuQt;
|
|
||||||
std::unique_ptr<QMenu> helpMenuQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QAction> closeApplicationQt;
|
|
||||||
std::unique_ptr<QAction> aboutApplicationQt;
|
|
||||||
|
|
||||||
std::unique_ptr<AboutWindow> aboutWindow;
|
|
||||||
signals:
|
|
||||||
private slots:
|
|
||||||
void uploadSong();
|
|
||||||
void exitApplication();
|
|
||||||
void displaySoftwareInformation();
|
|
||||||
void setCurrentIndex(int);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
#ifndef CHECKS_H_
|
|
||||||
#define CHECKS_H_
|
|
||||||
|
|
||||||
#include<algorithm>
|
|
||||||
#include<string>
|
|
||||||
#include<cstdlib>
|
|
||||||
#include<ctype.h>
|
|
||||||
|
|
||||||
namespace Utilities
|
|
||||||
{
|
|
||||||
class Checks
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Checks() = delete;
|
|
||||||
|
|
||||||
static auto isNumber(const std::string &val)
|
|
||||||
{
|
|
||||||
return !val.empty() && std::find_if(val.begin(),
|
|
||||||
val.end(), [](char c)
|
|
||||||
{
|
|
||||||
return !std::isdigit(c);
|
|
||||||
}) == val.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: Not implemented
|
|
||||||
template<typename Item, typename Container, typename Func>
|
|
||||||
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<typename Item, typename Container, typename Func>
|
|
||||||
static auto itemIterInContainer(const Container &container, const Item &item, Func func)
|
|
||||||
{
|
|
||||||
auto result = false;
|
|
||||||
|
|
||||||
auto ii = std::find_if(container.begin(), container.end(), [&](Item i)
|
|
||||||
{
|
|
||||||
return func(i, item);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ii == container.end())
|
|
||||||
{
|
|
||||||
ii = container.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ii;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#ifndef CONVERSIONS_H_
|
|
||||||
#define CONVERSIONS_H_
|
|
||||||
|
|
||||||
#include<memory>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Utilities
|
|
||||||
{
|
|
||||||
|
|
||||||
class Conversions
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Conversions();
|
|
||||||
|
|
||||||
static void toLowerChar(char &c)
|
|
||||||
{
|
|
||||||
if (std::isalpha(c))
|
|
||||||
{
|
|
||||||
c = std::tolower(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void initializeValues();
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void printValue(T val);
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
//{{NO_DEPENDENCIES}}
|
|
||||||
// Microsoft Visual C++ generated include file.
|
|
||||||
// Used by IcarusDownloadManager.rc
|
|
||||||
|
|
||||||
// Next default values for new objects
|
|
||||||
//
|
|
||||||
#ifdef APSTUDIO_INVOKED
|
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
|
||||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
|
||||||
#define _APS_NEXT_SYMED_VALUE 101
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
#include<iostream>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#include"Managers/ActionManager.h"
|
|
||||||
#include"Managers/CommitManager.h"
|
|
||||||
|
|
||||||
using std::cin;
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using Managers::ActionManager;
|
|
||||||
using Managers::CommitManager;
|
|
||||||
|
|
||||||
constexpr static auto IcarusDownloadManager_version()
|
|
||||||
{
|
|
||||||
return "v0.3.2";
|
|
||||||
}
|
|
||||||
|
|
||||||
void printHelp()
|
|
||||||
{
|
|
||||||
cout<<"icd [Action] [flag]\n\n";
|
|
||||||
|
|
||||||
cout<<"Actions\n";
|
|
||||||
cout<<"download\n";
|
|
||||||
cout<<"upload\n";
|
|
||||||
cout<<"upload-meta\n";
|
|
||||||
cout<<"retrieve\n";
|
|
||||||
cout<<"delete\n\n";
|
|
||||||
|
|
||||||
cout<<"Flags\n";
|
|
||||||
cout<<"Required for all actions\n";
|
|
||||||
cout<<"-u username\n";
|
|
||||||
cout<<"-p password\n";
|
|
||||||
cout<<"-h host\n\n";
|
|
||||||
|
|
||||||
cout<<"Required for upload\n";
|
|
||||||
cout<<"-s path of song\n";
|
|
||||||
cout<<"-sd directory where to search for songs to upload (Optional)\n";
|
|
||||||
cout<<"-sr directory where to recursively search for songs to upload (Optional)\n";
|
|
||||||
cout<<"-nc will not prompt the user when uploading from a directory\n\n";
|
|
||||||
|
|
||||||
cout<<"Required for upload with metadata\n";
|
|
||||||
cout<<"-s path of song\n";
|
|
||||||
cout<<"-t track number\n";
|
|
||||||
cout<<"-m metadata filepath\n";
|
|
||||||
cout<<"-ca coverart filepath\n";
|
|
||||||
cout<<"-scma directory where songs, metadata, and cover art exists and will be uploaded (Optional)\n\n";
|
|
||||||
|
|
||||||
cout<<"Required for download\n";
|
|
||||||
cout<<"-b song id\n";
|
|
||||||
cout<<"-d path to download song (Optional)\n\n";
|
|
||||||
|
|
||||||
cout<<"Required for retrieving records\n";
|
|
||||||
cout<<"-rt retrieve type (songs is only accepted)\n\n";
|
|
||||||
|
|
||||||
cout<<"Required for deleting a song\n";
|
|
||||||
cout<<"-D song id\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
if (argc < 2)
|
|
||||||
{
|
|
||||||
printHelp();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ActionManager actMgr(argv, argc);
|
|
||||||
auto chosenAction = actMgr.retrieveIcarusAction();
|
|
||||||
|
|
||||||
chosenAction.print_action_and_flags();
|
|
||||||
|
|
||||||
CommitManager commitMgr(chosenAction);
|
|
||||||
commitMgr.commitAction();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
#include"Managers/ActionManager.h"
|
|
||||||
|
|
||||||
#include<algorithm>
|
|
||||||
#include<iostream>
|
|
||||||
#include<utility>
|
|
||||||
#include<cstring>
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::string;
|
|
||||||
using std::string_view;
|
|
||||||
using std::vector;
|
|
||||||
|
|
||||||
using Models::Flags;
|
|
||||||
using Models::IcarusAction;
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
ActionManager::ActionManager(char **param, int paramCount) :
|
|
||||||
params(std::move(param)), paramCount(paramCount)
|
|
||||||
{
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
IcarusAction ActionManager::retrieveIcarusAction() const
|
|
||||||
{
|
|
||||||
IcarusAction icarusAction;
|
|
||||||
icarusAction.flags = flags;
|
|
||||||
icarusAction.action = action;
|
|
||||||
|
|
||||||
return icarusAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ActionManager::initialize()
|
|
||||||
{
|
|
||||||
validateFlags();
|
|
||||||
|
|
||||||
action = std::move(string{params[1]});
|
|
||||||
transform(action.begin(), action.end(),
|
|
||||||
action.begin(), ::tolower);
|
|
||||||
}
|
|
||||||
void ActionManager::validateFlags()
|
|
||||||
{
|
|
||||||
cout<<"Validating flags\n";
|
|
||||||
|
|
||||||
const auto flagVals = parsedFlags();
|
|
||||||
|
|
||||||
for (auto flag = flagVals.begin(); flag != flagVals.end(); ++flag)
|
|
||||||
{
|
|
||||||
Flags flg;
|
|
||||||
cout<<"Value: "<<*flag<<"\n";
|
|
||||||
|
|
||||||
if (isValidFlag<string>(*flag) && doesFlagHaveValue<string>(*flag))
|
|
||||||
{
|
|
||||||
cout<<"Flag has value\n";
|
|
||||||
flg.flag = *flag;
|
|
||||||
flg.value = *(++flag);
|
|
||||||
}
|
|
||||||
else if (isValidFlag<string>(*flag))
|
|
||||||
{
|
|
||||||
cout<<"Flag does not have a value\n";
|
|
||||||
flg.flag = *flag;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout<<"Flag "<<*flag<<" is not valid"<<endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
flags.emplace_back(std::move(flg));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<string> ActionManager::parsedFlags()
|
|
||||||
{
|
|
||||||
auto parsed = vector<string>();
|
|
||||||
|
|
||||||
for (auto i = 2; i < paramCount; ++i)
|
|
||||||
{
|
|
||||||
const std::string flag(std::move(*(params + i)));
|
|
||||||
parsed.push_back(std::move(flag));
|
|
||||||
}
|
|
||||||
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma region Testing
|
|
||||||
void ActionManager::printAction() noexcept
|
|
||||||
{
|
|
||||||
if (action.empty())
|
|
||||||
{
|
|
||||||
printf("Action is empty\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout<<"Action is "<<action<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void ActionManager::printFlags() noexcept
|
|
||||||
{
|
|
||||||
cout<<"\nPrinting flags..."<<endl;
|
|
||||||
for (auto flag: flags)
|
|
||||||
{
|
|
||||||
cout<<"flag "<<flag.flag<<endl;
|
|
||||||
cout<<"value "<<flag.value<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,457 +0,0 @@
|
|||||||
#include"Managers/CommitManager.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
#include "nlohmann/json.hpp"
|
|
||||||
|
|
||||||
#include "Models/API.h"
|
|
||||||
#include "Models/Song.h"
|
|
||||||
#include "Models/Token.h"
|
|
||||||
#include "Parsers/APIParser.h"
|
|
||||||
#include "Syncers/Delete.h"
|
|
||||||
#include "Syncers/Download.h"
|
|
||||||
#include "Syncers/RetrieveRecords.h"
|
|
||||||
#include "Syncers/Upload.h"
|
|
||||||
|
|
||||||
#include "Managers/TokenManager.h"
|
|
||||||
#include "Managers/UserManager.h"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::map;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using Managers::TokenManager;
|
|
||||||
using Managers::UserManager;
|
|
||||||
using Models::API;
|
|
||||||
using Models::Song;
|
|
||||||
using Models::Token;
|
|
||||||
using Parsers::APIParser;
|
|
||||||
using Models::IcarusAction;
|
|
||||||
using Syncers::Delete;
|
|
||||||
using Syncers::Download;
|
|
||||||
using Syncers::RetrieveRecords;
|
|
||||||
using Syncers::Upload;
|
|
||||||
|
|
||||||
namespace filesystem = std::filesystem;
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
CommitManager::CommitManager(IcarusAction& icaAct) : icaAction(std::move(icaAct))
|
|
||||||
{ }
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
void CommitManager::commitAction()
|
|
||||||
{
|
|
||||||
auto action = icaAction.action;
|
|
||||||
cout<<"Commiting "<<action<<" action"<<endl;
|
|
||||||
|
|
||||||
switch (mapActions()[action])
|
|
||||||
{
|
|
||||||
case ActionValues::deleteAct:
|
|
||||||
deleteSong();
|
|
||||||
break;
|
|
||||||
case ActionValues::downloadAct:
|
|
||||||
downloadSong();
|
|
||||||
break;
|
|
||||||
case ActionValues::retrieveAct:
|
|
||||||
retrieveObjects();
|
|
||||||
break;
|
|
||||||
case ActionValues::uploadAct:
|
|
||||||
uploadSong();
|
|
||||||
break;
|
|
||||||
case ActionValues::UPLOAD_SONG_WITH_METADATA:
|
|
||||||
uploadSongWithMetadata();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::map<std::string, CommitManager::ActionValues>
|
|
||||||
CommitManager::mapActions() noexcept
|
|
||||||
{
|
|
||||||
const std::map<std::string, ActionValues> actions{
|
|
||||||
{"delete", ActionValues::deleteAct},
|
|
||||||
{"download", ActionValues::downloadAct},
|
|
||||||
{"retrieve", ActionValues::retrieveAct},
|
|
||||||
{"upload", ActionValues::uploadAct},
|
|
||||||
{"upload-meta", ActionValues::UPLOAD_SONG_WITH_METADATA}
|
|
||||||
};
|
|
||||||
|
|
||||||
return actions;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Token CommitManager::parseToken(API api)
|
|
||||||
{
|
|
||||||
cout<<"fetching token\n";
|
|
||||||
UserManager usrMgr{icaAction};
|
|
||||||
auto user = usrMgr.retrieveUser();
|
|
||||||
|
|
||||||
TokenManager tk{user, api};
|
|
||||||
|
|
||||||
return tk.requestToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommitManager::deleteSong()
|
|
||||||
{
|
|
||||||
APIParser apiPrs{icaAction};
|
|
||||||
auto api = apiPrs.retrieveAPI();
|
|
||||||
|
|
||||||
auto token = parseToken(api);
|
|
||||||
|
|
||||||
Song song{};
|
|
||||||
|
|
||||||
for (auto arg : icaAction.flags)
|
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
|
||||||
|
|
||||||
if (flag.compare("-D") == 0)
|
|
||||||
{
|
|
||||||
song.id = atoi(value.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Delete del{api};
|
|
||||||
cout<<"Deleting song..."<<endl;
|
|
||||||
del.deleteSong(token, song);
|
|
||||||
}
|
|
||||||
void CommitManager::downloadSong()
|
|
||||||
{
|
|
||||||
cout<<"Starting downloading process..."<<endl;
|
|
||||||
|
|
||||||
APIParser apiPrs{icaAction};
|
|
||||||
auto api = apiPrs.retrieveAPI();
|
|
||||||
|
|
||||||
auto token = parseToken(api);
|
|
||||||
|
|
||||||
Song song{};
|
|
||||||
|
|
||||||
for (auto arg : icaAction.flags)
|
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
|
||||||
|
|
||||||
if (flag.compare("-d") == 0)
|
|
||||||
{
|
|
||||||
song.songPath.assign(arg.value);
|
|
||||||
}
|
|
||||||
if (flag.compare("-b") == 0)
|
|
||||||
{
|
|
||||||
song.id = atoi(value.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Download dnld{api};
|
|
||||||
cout<<"downloading song"<<endl;
|
|
||||||
dnld.downloadSong(token, song);
|
|
||||||
}
|
|
||||||
void CommitManager::retrieveObjects()
|
|
||||||
{
|
|
||||||
cout<<"Starting retrieve process..."<<endl;
|
|
||||||
|
|
||||||
APIParser apiPrs{icaAction};
|
|
||||||
auto api = apiPrs.retrieveAPI();
|
|
||||||
|
|
||||||
auto token = parseToken(api);
|
|
||||||
RetrieveTypes retrieveType;
|
|
||||||
|
|
||||||
for (auto arg : icaAction.flags)
|
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
|
||||||
|
|
||||||
if (flag.compare("-rt") == 0)
|
|
||||||
{
|
|
||||||
if (value.compare("songs") == 0)
|
|
||||||
{
|
|
||||||
retrieveType = RetrieveTypes::songs;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RetrieveRecords songs{api, token};
|
|
||||||
songs.retrieve(retrieveType);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommitManager::uploadSong()
|
|
||||||
{
|
|
||||||
auto uploadSingleSong = true;
|
|
||||||
auto recursiveDirectory = false;
|
|
||||||
const auto noConfirm = checkForNoConfirm();
|
|
||||||
string songDirectory;
|
|
||||||
APIParser apiPrs{icaAction};
|
|
||||||
auto api = apiPrs.retrieveAPI();
|
|
||||||
|
|
||||||
auto token = parseToken(api);
|
|
||||||
|
|
||||||
Song song;
|
|
||||||
|
|
||||||
for (auto& arg : icaAction.flags)
|
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
|
||||||
|
|
||||||
if (flag.compare("-s") == 0)
|
|
||||||
{
|
|
||||||
song.songPath.assign(arg.value);
|
|
||||||
}
|
|
||||||
else if (flag.compare("-sd") == 0)
|
|
||||||
{
|
|
||||||
songDirectory = value;
|
|
||||||
uploadSingleSong = false;
|
|
||||||
}
|
|
||||||
else if (flag.compare("-sr") == 0)
|
|
||||||
{
|
|
||||||
songDirectory = value;
|
|
||||||
uploadSingleSong = false;
|
|
||||||
recursiveDirectory = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Upload upld{api, token};
|
|
||||||
if (uploadSingleSong)
|
|
||||||
{
|
|
||||||
cout<<"Uploading song..."<<endl;
|
|
||||||
upld.uploadSong(song);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout<<"Uploading songs from " << songDirectory << endl;
|
|
||||||
upld.uploadSongsFromDirectory(songDirectory, noConfirm, recursiveDirectory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CommitManager::uploadSongWithMetadata()
|
|
||||||
{
|
|
||||||
cout<<"Uploading single song with metadata\n\n";
|
|
||||||
|
|
||||||
// Either the set of "-s", "-m", "-ca", "-t" flags or "-smca" must exist with values
|
|
||||||
// in order to be valid but not both
|
|
||||||
const auto songPath = this->icaAction.retrieveFlagValue("-s");
|
|
||||||
const auto metadataPath = this->icaAction.retrieveFlagValue("-m");
|
|
||||||
const auto coverPath = this->icaAction.retrieveFlagValue("-ca");
|
|
||||||
const auto trackID = this->icaAction.retrieveFlagValue("-t");
|
|
||||||
const auto singleTarget = !songPath.empty() && !metadataPath.empty() &&
|
|
||||||
!coverPath.empty() && !trackID.empty() ? true : false;
|
|
||||||
|
|
||||||
const auto uni = this->icaAction.retrieveFlagValue("-smca");
|
|
||||||
const auto multiTarget = !uni.empty() ? true : false;
|
|
||||||
|
|
||||||
if (singleTarget && multiTarget)
|
|
||||||
{
|
|
||||||
cout<<"Cannot upload from source and directory\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout<<"Song path: "<<songPath<<"\n";
|
|
||||||
cout<<"TrackID: "<<trackID<<"\n";
|
|
||||||
cout<<"Metadata path: "<<metadataPath<<"\n";
|
|
||||||
cout<<"Cover Art path: "<<coverPath<<"\n";
|
|
||||||
|
|
||||||
if (singleTarget)
|
|
||||||
{
|
|
||||||
singTargetUpload(songPath, trackID, metadataPath, coverPath);
|
|
||||||
}
|
|
||||||
else if (multiTarget)
|
|
||||||
{
|
|
||||||
multiTargetUpload(uni);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CommitManager::singTargetUpload(const std::string &songPath, const std::string &trackID,
|
|
||||||
const std::string &metaPath, const std::string &coverPath)
|
|
||||||
{
|
|
||||||
APIParser apiPrs(icaAction);
|
|
||||||
auto api = apiPrs.retrieveAPI();
|
|
||||||
const auto token = parseToken(api);
|
|
||||||
|
|
||||||
auto album = retrieveMetadata(metaPath);
|
|
||||||
album.printInfo();
|
|
||||||
|
|
||||||
Song song;
|
|
||||||
song.track = 1;
|
|
||||||
song.disc = 1;
|
|
||||||
|
|
||||||
cout<<"TrackID: "<<trackID<<"\n";
|
|
||||||
|
|
||||||
parseDiscAndTrack<Song, std::string>(song, trackID);
|
|
||||||
|
|
||||||
auto c = [](const Song &songA, const Song &songB) { return songA.track == songB.track && songA.disc == songB.disc; };
|
|
||||||
auto sng = Utilities::Checks::itemIterInContainer<Song, std::vector<Song>>(album.songs, song, c);
|
|
||||||
|
|
||||||
if (sng == album.songs.end())
|
|
||||||
{
|
|
||||||
cout<<"Not found with disc "<<song.disc<<" track "<<song.track<<"\n";
|
|
||||||
std::exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
song = *sng;
|
|
||||||
const auto p = filesystem::path(songPath);
|
|
||||||
song.directory = p.parent_path().string();
|
|
||||||
song.generate_filename_from_track();
|
|
||||||
|
|
||||||
Models::CoverArt cover;
|
|
||||||
cover.title = song.title;
|
|
||||||
cover.path = coverPath;
|
|
||||||
|
|
||||||
Upload up(api, token);
|
|
||||||
up.uploadSongWithMetadata(album, song, cover);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommitManager::multiTargetUpload(const std::string &sourcePath)
|
|
||||||
{
|
|
||||||
APIParser apiPrs(icaAction);
|
|
||||||
auto api = apiPrs.retrieveAPI();
|
|
||||||
const auto token = parseToken(api);
|
|
||||||
|
|
||||||
if (!fs::is_directory(sourcePath))
|
|
||||||
{
|
|
||||||
cout<<sourcePath<<" is not a directory\n";
|
|
||||||
std::exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Song> 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 "<<stem<<" Extension "<<extension<<"\n";
|
|
||||||
|
|
||||||
auto validImg = [](const std::string& ext)
|
|
||||||
{
|
|
||||||
std::vector<string> extensions;
|
|
||||||
extensions.reserve(3);
|
|
||||||
extensions.push_back(".jpg");
|
|
||||||
extensions.push_back(".jpeg");
|
|
||||||
extensions.push_back(".");
|
|
||||||
|
|
||||||
return ext.compare(extensions[0]) == 0 || ext.compare(extensions[1]) == 0 || ext.compare(extensions[2]) == 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (extension.compare(".mp3") == 0)
|
|
||||||
{
|
|
||||||
Song song;
|
|
||||||
song.songPath = pp.string();
|
|
||||||
|
|
||||||
initializeDiscAndTrack<Song, std::string>(song);
|
|
||||||
|
|
||||||
songs.emplace_back(std::move(song));
|
|
||||||
}
|
|
||||||
// else if (extension.compare(".jpg") == 0 || extension.compare(".png") == 0)
|
|
||||||
else if (validImg(extension.string()))
|
|
||||||
{
|
|
||||||
cover.path.assign(pp.string());
|
|
||||||
}
|
|
||||||
else if (extension.compare(".json") == 0)
|
|
||||||
{
|
|
||||||
metadataPath.assign(pp.string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto album = retrieveMetadata(metadataPath);
|
|
||||||
songs.clear();
|
|
||||||
songs.assign(album.songs.begin(), album.songs.end());
|
|
||||||
|
|
||||||
Upload up(api, token);
|
|
||||||
|
|
||||||
for (auto &song : songs)
|
|
||||||
{
|
|
||||||
up.uploadSongWithMetadata(album, song, cover);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma region private
|
|
||||||
CommitManager::Album CommitManager::retrieveMetadata(const std::string_view path)
|
|
||||||
{
|
|
||||||
CommitManager::Album album;
|
|
||||||
const auto fileContent = retrieveFileContent(path);
|
|
||||||
cout<<"Parsing...\n";
|
|
||||||
auto serialized = nlohmann::json::parse(fileContent);
|
|
||||||
cout<<"Parsed\n";
|
|
||||||
|
|
||||||
album.album = serialized["album"].get<std::string>();
|
|
||||||
album.albumArtist = serialized["album_artist"].get<std::string>();
|
|
||||||
album.genre = serialized["genre"].get<std::string>();
|
|
||||||
album.year = serialized["year"].get<int>();
|
|
||||||
album.trackCount = serialized["track_count"].get<int>();
|
|
||||||
album.discCount = serialized["disc_count"].get<int>();
|
|
||||||
album.songs.reserve(album.trackCount);
|
|
||||||
|
|
||||||
for (auto &j : serialized["tracks"])
|
|
||||||
{
|
|
||||||
Song song;
|
|
||||||
song.title = j["title"].get<std::string>();
|
|
||||||
song.track = j["track"].get<int>();
|
|
||||||
song.disc = j["disc"].get<int>();
|
|
||||||
song.artist = j["artist"].get<std::string>();
|
|
||||||
song.album = album.album;
|
|
||||||
song.year = album.year;
|
|
||||||
song.genre = album.genre;
|
|
||||||
song.generate_filename_from_track();
|
|
||||||
const auto p = fs::path(path);
|
|
||||||
song.directory = p.parent_path().string();
|
|
||||||
|
|
||||||
album.songs.push_back(song);
|
|
||||||
}
|
|
||||||
|
|
||||||
return album;
|
|
||||||
}
|
|
||||||
|
|
||||||
string CommitManager::retrieveFileContent(const std::string_view path)
|
|
||||||
{
|
|
||||||
string path_str(path);
|
|
||||||
string value;
|
|
||||||
|
|
||||||
std::stringstream buffer;
|
|
||||||
std::fstream file(path_str, std::ios::in);
|
|
||||||
buffer<<file.rdbuf();
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
value.assign(buffer.str());
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
void CommitManager::Album::printInfo()
|
|
||||||
{
|
|
||||||
std::cout<<"Album: "<<this->album<<"\n";
|
|
||||||
std::cout<<"Album Artist: "<<this->albumArtist<<"\n";
|
|
||||||
std::cout<<"Genre: "<<this->genre<<"\n";
|
|
||||||
std::cout<<"Year: "<<this->year<<"\n";
|
|
||||||
std::cout<<"Track count: "<<this->trackCount<<"\n";
|
|
||||||
std::cout<<"Disc count: "<<this->discCount<<"\n";
|
|
||||||
std::cout<<"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
#include<iostream>
|
|
||||||
#include<fstream>
|
|
||||||
|
|
||||||
#include"Managers/FileManager.h"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::ifstream;
|
|
||||||
using std::ofstream;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
FileManager::FileManager() {}
|
|
||||||
FileManager::FileManager(string filePath)
|
|
||||||
{
|
|
||||||
this->filePath = filePath;
|
|
||||||
readFile();
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
void FileManager::saveFile(string newFilePath)
|
|
||||||
{
|
|
||||||
if (!fileRead)
|
|
||||||
readFile();
|
|
||||||
|
|
||||||
ofstream of{newFilePath, ofstream::binary};
|
|
||||||
of.write(fileBuffer, fileBufferLength);
|
|
||||||
of.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileManager::readFile()
|
|
||||||
{
|
|
||||||
ifstream is{filePath, ifstream::binary};
|
|
||||||
if (is)
|
|
||||||
{
|
|
||||||
is.seekg (0, is.end);
|
|
||||||
fileBufferLength = is.tellg();
|
|
||||||
is.seekg (0, is.beg);
|
|
||||||
|
|
||||||
fileBuffer = new char [fileBufferLength];
|
|
||||||
|
|
||||||
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
|
|
||||||
is.read (fileBuffer,fileBufferLength);
|
|
||||||
|
|
||||||
if (is)
|
|
||||||
cout<<"all characters read successfully.";
|
|
||||||
else
|
|
||||||
cout<<"error: only "<<is.gcount()<<" could be read";
|
|
||||||
cout<<endl;
|
|
||||||
is.close();
|
|
||||||
fileRead = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void FileManager::modifyFilePath(string filePath)
|
|
||||||
{
|
|
||||||
this->filePath = filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* FileManager::retrieveFileBuffer() const
|
|
||||||
{
|
|
||||||
return fileBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FileManager::retrieveFileBufferLength() const { return fileBufferLength; }
|
|
||||||
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
#include"Managers/TokenManager.h"
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
|
|
||||||
#include<cpr/cpr.h>
|
|
||||||
#include<nlohmann/json.hpp>
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
using Managers::TokenManager;
|
|
||||||
using Models::API;
|
|
||||||
using Models::Token;
|
|
||||||
using Models::User;
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
TokenManager::TokenManager(const User& user)
|
|
||||||
{
|
|
||||||
this->user = user;
|
|
||||||
}
|
|
||||||
TokenManager::TokenManager(const User& user, API& api)
|
|
||||||
{
|
|
||||||
this->user = user;
|
|
||||||
this->api = api;
|
|
||||||
this->api.endpoint = "api/" + api.version
|
|
||||||
+ "/login";
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
Token TokenManager::requestToken()
|
|
||||||
{
|
|
||||||
Token token{};
|
|
||||||
json usrObj;
|
|
||||||
|
|
||||||
usrObj["username"] = user.username;
|
|
||||||
usrObj["password"] = user.password;
|
|
||||||
|
|
||||||
cout<<"Sending request for token"<<endl;
|
|
||||||
auto url = api.url + api.endpoint;
|
|
||||||
cout<<url<<endl;
|
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
|
||||||
cpr::Body{usrObj.dump()},
|
|
||||||
cpr::Header{{"Content-Type", "application/json"}});
|
|
||||||
|
|
||||||
json res = json::parse(r.text);
|
|
||||||
token.accessToken = res["token"];
|
|
||||||
token.tokenType = res["token_type"];
|
|
||||||
|
|
||||||
cout<<"status code "<<r.status_code<<endl;
|
|
||||||
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
#include"Managers/UserManager.h"
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
#include<string>
|
|
||||||
#include<vector>
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
using std::vector;
|
|
||||||
|
|
||||||
using Models::IcarusAction;
|
|
||||||
using Models::User;
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
UserManager::UserManager(User user)
|
|
||||||
{
|
|
||||||
this->user = user;
|
|
||||||
}
|
|
||||||
UserManager::UserManager(const IcarusAction icaAct)
|
|
||||||
{
|
|
||||||
this->icaAction = icaAct;
|
|
||||||
this->user = User{};
|
|
||||||
parseUserFromActions();
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
User UserManager::retrieveUser() const
|
|
||||||
{
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserManager::parseUserFromActions()
|
|
||||||
{
|
|
||||||
auto args = icaAction.flags;
|
|
||||||
|
|
||||||
for (auto arg : args)
|
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
|
||||||
if (flag.compare("-u") == 0)
|
|
||||||
{
|
|
||||||
user.username = arg.value;
|
|
||||||
}
|
|
||||||
if (flag.compare("-p") == 0)
|
|
||||||
{
|
|
||||||
user.password = arg.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#include "Models/Song.h"
|
|
||||||
|
|
||||||
#include "nlohmann/json.hpp"
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
string Song::toMetadataJson()
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
#include "Parsers/APIParser.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
using Models::API;
|
|
||||||
using Models::IcarusAction;
|
|
||||||
|
|
||||||
namespace Parsers
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
APIParser::APIParser(IcarusAction icaAct) : icaAct(icaAct)
|
|
||||||
{
|
|
||||||
api = API{};
|
|
||||||
parseAPI();
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
API APIParser::retrieveAPI() const
|
|
||||||
{
|
|
||||||
return api;
|
|
||||||
}
|
|
||||||
|
|
||||||
void APIParser::parseAPI()
|
|
||||||
{
|
|
||||||
auto flags = icaAct.flags;
|
|
||||||
cout << "Parsing api" << endl;
|
|
||||||
|
|
||||||
for (auto i =0; i < flags.size(); ++i)
|
|
||||||
{
|
|
||||||
auto arg = flags[i].flag;
|
|
||||||
auto value = flags[i].value;
|
|
||||||
|
|
||||||
if (arg.compare("-h") == 0)
|
|
||||||
{
|
|
||||||
api.url = (value[value.size()-1] == '/') ? value : value + "/";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: For now I will hard code
|
|
||||||
// the api version since I am only
|
|
||||||
// on version 1
|
|
||||||
api.version = "v1";
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
#include "Syncers/Delete.h"
|
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <cpr/cpr.h>
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::exception;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using Models::API;
|
|
||||||
using Models::Song;
|
|
||||||
using Models::Token;
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
Delete::Delete(API api)
|
|
||||||
{
|
|
||||||
this->api = api;
|
|
||||||
this->api.endpoint = "song/data";
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
void Delete::deleteSong(const Token token, Song song)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto url = retrieveUrl(song);
|
|
||||||
string auth{token.tokenType};
|
|
||||||
auth.append(" " + token.accessToken);
|
|
||||||
auto r = cpr::Delete(cpr::Url(url),
|
|
||||||
cpr::Header{{"authorization", auth}});
|
|
||||||
|
|
||||||
auto statusCode = r.status_code;
|
|
||||||
|
|
||||||
cout<<"Status code "<<statusCode<<endl;
|
|
||||||
}
|
|
||||||
catch (exception e)
|
|
||||||
{
|
|
||||||
auto msg = e.what();
|
|
||||||
cout<<msg<<endl;
|
|
||||||
}
|
|
||||||
cout<<"Finished"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
string Delete::retrieveUrl(Song song)
|
|
||||||
{
|
|
||||||
string url{api.url + "api/" + api.version + "/" +
|
|
||||||
api.endpoint + "/"};
|
|
||||||
|
|
||||||
url.append(std::to_string(song.id));
|
|
||||||
cout<<"url "<<url<<endl;
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
#include "Syncers/Download.h"
|
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include <cpr/cpr.h>
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::exception;
|
|
||||||
using std::ofstream;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using Models::API;
|
|
||||||
using Models::Song;
|
|
||||||
using Models::Token;
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
Download::Download() { }
|
|
||||||
Download::Download(API api)
|
|
||||||
{
|
|
||||||
this->api = api;
|
|
||||||
this->api.endpoint = "song/data";
|
|
||||||
}
|
|
||||||
Download::Download(string filePath)
|
|
||||||
{
|
|
||||||
downloadFilePath = filePath;
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
void Download::downloadSong(const Token token, Song song)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string url = retrieveUrl(song);
|
|
||||||
song.songPath.append("track.mp3");
|
|
||||||
cout<<"song path "<<song.songPath<<endl;
|
|
||||||
string auth{token.tokenType};
|
|
||||||
auth.append(" " + token.accessToken);
|
|
||||||
|
|
||||||
auto r = cpr::Get(cpr::Url(url),
|
|
||||||
cpr::Header{{"Content-type", "audio/mpeg"},
|
|
||||||
{"Authorization", auth}});
|
|
||||||
|
|
||||||
|
|
||||||
int statusCode = r.status_code;
|
|
||||||
|
|
||||||
if (statusCode == OK) {
|
|
||||||
song.data = r.text;
|
|
||||||
saveSong(song);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
cout<<"finsihed with status code "<<statusCode<<endl;
|
|
||||||
}
|
|
||||||
catch (exception e)
|
|
||||||
{
|
|
||||||
auto msg = e.what();
|
|
||||||
cout<<msg<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string Download::retrieveUrl(Song song)
|
|
||||||
{
|
|
||||||
string url{api.url + "api/" + api.version + "/" +
|
|
||||||
api.endpoint + "/"};
|
|
||||||
|
|
||||||
url.append(std::to_string(song.id));
|
|
||||||
cout<<"url "<<url<<endl;
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Download::saveSong(Song& song)
|
|
||||||
{
|
|
||||||
cout<<"\nSaving song to: "<<song.songPath<<endl;
|
|
||||||
int bufferLength = song.data.length();
|
|
||||||
const char *data = song.data.c_str();
|
|
||||||
cout<<"buff length "<<bufferLength<<endl;
|
|
||||||
|
|
||||||
ofstream saveSong{song.songPath, std::ios::binary};
|
|
||||||
saveSong.write(data, bufferLength);
|
|
||||||
saveSong.close();
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
#include "Syncers/RetrieveRecords.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include <cpr/cpr.h>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include "Utilities/Conversions.h"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::ofstream;
|
|
||||||
|
|
||||||
using Managers::CommitManager;
|
|
||||||
using Models::API;
|
|
||||||
using Models::Token;
|
|
||||||
using Utilities::Conversions;
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
RetrieveRecords::RetrieveRecords() { }
|
|
||||||
RetrieveRecords::RetrieveRecords(API api, Token token)
|
|
||||||
: token(token), api(api) { }
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
void RetrieveRecords::retrieve(CommitManager::RetrieveTypes type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case CommitManager::RetrieveTypes::songs:
|
|
||||||
fetchSongs();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void RetrieveRecords::fetchSongs()
|
|
||||||
{
|
|
||||||
cout<<"fetching songs"<<endl;
|
|
||||||
auto url = api.url + "api/" + api.version + "/" + "song";
|
|
||||||
|
|
||||||
auto auth = token.tokenType;
|
|
||||||
auth.append(" " + token.accessToken);
|
|
||||||
auto r = cpr::Get(cpr::Url{url},
|
|
||||||
cpr::Header{{"authorization", auth},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (r.status_code != (int)Result::OK) {
|
|
||||||
cout<<"something went wrong\n";
|
|
||||||
cout<<"status code: "<<r.status_code<<endl;
|
|
||||||
cout<<"message: "<<r.text<<endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto songData = nlohmann::json::parse(r.text);
|
|
||||||
|
|
||||||
ofstream writeData{};
|
|
||||||
writeData.open("songs.json");
|
|
||||||
writeData<<songData.dump(4);
|
|
||||||
writeData.close();
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,243 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <exception>
|
|
||||||
|
|
||||||
#include "cpr/cpr.h"
|
|
||||||
|
|
||||||
#include "Syncers/Upload.h"
|
|
||||||
#include "Utilities/Conversions.h"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::cin;
|
|
||||||
using std::endl;
|
|
||||||
using std::exception;
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
using Managers::FileManager;
|
|
||||||
using Models::API;
|
|
||||||
using Models::Song;
|
|
||||||
using Models::UploadForm;
|
|
||||||
|
|
||||||
using namespace cpr;
|
|
||||||
|
|
||||||
namespace Syncers
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
Song Upload::uploadSong(Song& song)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto url = retrieveUrl();
|
|
||||||
|
|
||||||
cout<<"url "<<url<<endl;
|
|
||||||
string auth{this->m_token.tokenType};
|
|
||||||
auth.append(" " + this->m_token.accessToken);
|
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
|
||||||
cpr::Multipart{{"key", "small value"},
|
|
||||||
{"file", cpr::File{song.songPath}}},
|
|
||||||
cpr::Header{{"authorization", auth}}
|
|
||||||
);
|
|
||||||
|
|
||||||
cout << "status code: " << r.status_code<< std::endl;
|
|
||||||
cout << r.text << endl;
|
|
||||||
auto result = nlohmann::json::parse(r.text);
|
|
||||||
cout<<"Finished"<<endl;
|
|
||||||
song.id = result["id"].get<int>();
|
|
||||||
song.title = result["title"].get<std::string>();
|
|
||||||
song.artist = result["artist"].get<std::string>();
|
|
||||||
song.album = result["album"].get<std::string>();
|
|
||||||
song.genre = result["genre"].get<std::string>();
|
|
||||||
song.year = result["year"].get<int>();
|
|
||||||
song.duration = result["duration"].get<int>();
|
|
||||||
song.track = result["track"].get<int>();
|
|
||||||
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
auto msg = e.what();
|
|
||||||
cout<<msg<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Upload::uploadSongsFromDirectory(const std::string& directory,
|
|
||||||
const bool noConfirm, bool recursive = false)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto songs = retrieveAllSongsFromDirectory(directory, recursive);
|
|
||||||
auto confirmUpload = true;
|
|
||||||
|
|
||||||
while (!noConfirm)
|
|
||||||
{
|
|
||||||
auto answer = 'a';
|
|
||||||
cout << "are you sure you want to upload " << songs.size() << " songs? [y/n]";
|
|
||||||
cin >> answer;
|
|
||||||
Utilities::Conversions::toLowerChar(answer);
|
|
||||||
|
|
||||||
if (answer == 'y' || answer == 'Y')
|
|
||||||
{
|
|
||||||
confirmUpload = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "uploading songs\n";
|
|
||||||
for (auto& song: songs)
|
|
||||||
{
|
|
||||||
song = uploadSong(song);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
cout<<e.what()<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Upload::uploadSongWithMetadata(Managers::CommitManager::Album &album, Models::Song& song, Models::CoverArt &cover)
|
|
||||||
{
|
|
||||||
this->api.endpoint.assign("song/data/upload/with/data");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
auto url = retrieveUrl();
|
|
||||||
|
|
||||||
cout << "url " << url << "\n";
|
|
||||||
string auth(this->m_token.tokenType);
|
|
||||||
auth.append(" " + this->m_token.accessToken);
|
|
||||||
|
|
||||||
nlohmann::json s;
|
|
||||||
s["title"] = song.title;
|
|
||||||
s["album"] = album.album;
|
|
||||||
s["album_artist"] = album.albumArtist;
|
|
||||||
s["artist"] = song.artist;
|
|
||||||
s["year"] = album.year;
|
|
||||||
s["genre"] = album.genre;
|
|
||||||
s["disc"] = song.disc;
|
|
||||||
s["track"] = song.track;
|
|
||||||
s["disc_count"] = album.discCount;
|
|
||||||
s["track_count"] = album.trackCount;
|
|
||||||
|
|
||||||
const auto meta = s.dump();
|
|
||||||
|
|
||||||
cout<<"\n\nMeta:\n"<<meta<<"\n";
|
|
||||||
cout << "Filepath: " << song.song_path() << "\n";
|
|
||||||
|
|
||||||
auto multipart = cpr::Multipart{{"cover", cpr::File{cover.path}},
|
|
||||||
{"metadata", meta},
|
|
||||||
{"file", cpr::File{song.song_path()}}};
|
|
||||||
|
|
||||||
auto r = cpr::Post(cpr::Url{url}, multipart,
|
|
||||||
cpr::Header{{"authorization", auth}}
|
|
||||||
);
|
|
||||||
|
|
||||||
cout << "status code: " << r.status_code<< std::endl;
|
|
||||||
cout << r.text << endl;
|
|
||||||
}
|
|
||||||
catch (exception &e)
|
|
||||||
{
|
|
||||||
auto msg = e.what();
|
|
||||||
cout<<"Error: "<<msg<<"\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::vector<Song> Upload::retrieveAllSongsFromDirectory(const std::string& directory,
|
|
||||||
bool recursive)
|
|
||||||
{
|
|
||||||
std::vector<Song> allSongs;
|
|
||||||
|
|
||||||
if (recursive)
|
|
||||||
{
|
|
||||||
for (auto p: fs::recursive_directory_iterator(directory))
|
|
||||||
{
|
|
||||||
auto song = retrieveSongPath(p);
|
|
||||||
if (!song.songPath.empty())
|
|
||||||
allSongs.push_back(song);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (auto p: fs::directory_iterator(directory))
|
|
||||||
{
|
|
||||||
auto song = retrieveSongPath(p);
|
|
||||||
if (!song.songPath.empty())
|
|
||||||
allSongs.push_back(song);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return allSongs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
string Upload::retrieveUrl()
|
|
||||||
{
|
|
||||||
const string url{api.url + "api/" + api.version + "/" +
|
|
||||||
api.endpoint};
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Song Upload::retrieveSongPath(fs::directory_entry& dirEntry)
|
|
||||||
{
|
|
||||||
constexpr auto mp3Ext = ".mp3";
|
|
||||||
Song song;
|
|
||||||
if (fs::is_regular_file(dirEntry.path()))
|
|
||||||
{
|
|
||||||
const auto ext = dirEntry.path().extension().string();
|
|
||||||
if (ext.compare(mp3Ext) == 0)
|
|
||||||
{
|
|
||||||
cout << "found mp3 file" << endl;
|
|
||||||
song.songPath = dirEntry.path().string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Testing
|
|
||||||
|
|
||||||
void Upload::printSongDetails(std::vector<Song>& songs)
|
|
||||||
{
|
|
||||||
for (auto& song: songs)
|
|
||||||
{
|
|
||||||
cout<<"Song details: "<<endl;
|
|
||||||
cout<<"Id: "<<song.id<<endl;
|
|
||||||
cout<<"Title: "<<song.title<<endl;
|
|
||||||
cout<<"Artist: "<<song.artist<<endl;
|
|
||||||
cout<<"Album: "<<song.album<<endl;
|
|
||||||
cout<<"Genre: "<<song.genre<<endl;
|
|
||||||
cout<<"Year: "<<song.year<<endl;
|
|
||||||
cout<<"Duration: "<<song.duration<<endl;
|
|
||||||
cout<<"Path: "<<song.songPath<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Upload::printJsonData(const json& obj)
|
|
||||||
{
|
|
||||||
cout<<endl<<endl<<"JSon data: "<<endl;
|
|
||||||
cout<<"id: "<<obj["id"]<<endl;
|
|
||||||
cout<<"title: "<<obj["title"]<<endl;
|
|
||||||
cout<<"artist: "<<obj["artist"]<<endl;
|
|
||||||
cout<<"album: "<<obj["album"]<<endl;
|
|
||||||
cout<<"genre: "<<obj["genre"]<<endl;
|
|
||||||
cout<<"year: "<<obj["year"]<<endl;
|
|
||||||
cout<<"duration: "<<obj["duration"]<<endl;
|
|
||||||
cout<<"song_data: "<<obj["song_data"]<<endl;
|
|
||||||
|
|
||||||
cout<<endl<<endl;
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#include "UI/AboutWindow.h"
|
|
||||||
|
|
||||||
using std::unique_ptr;
|
|
||||||
|
|
||||||
namespace UI
|
|
||||||
{
|
|
||||||
#pragma region Constructors
|
|
||||||
AboutWindow::AboutWindow(QWidget* parent): QDialog(parent)
|
|
||||||
{
|
|
||||||
setupWindow();
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
void AboutWindow::setupWindow()
|
|
||||||
{
|
|
||||||
windowWidth = 250;
|
|
||||||
windowHeight = 300;
|
|
||||||
|
|
||||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
|
||||||
|
|
||||||
appName = unique_ptr<QLabel>{new QLabel(tr("IcarusDownloadManager"))};
|
|
||||||
actionButtonQt = unique_ptr<QPushButton>{new QPushButton(tr("Close"))};
|
|
||||||
|
|
||||||
mainLayoutQt->addWidget(appName.get());
|
|
||||||
mainLayoutQt->addWidget(actionButtonQt.get());
|
|
||||||
|
|
||||||
|
|
||||||
setFixedWidth(windowWidth);
|
|
||||||
setFixedHeight(windowHeight);
|
|
||||||
|
|
||||||
setLayout(mainLayoutQt.get());
|
|
||||||
|
|
||||||
setWindowTitle("About");
|
|
||||||
|
|
||||||
connections();
|
|
||||||
}
|
|
||||||
void AboutWindow::connections()
|
|
||||||
{
|
|
||||||
QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this,
|
|
||||||
SLOT(closeWindow()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AboutWindow::closeWindow()
|
|
||||||
{
|
|
||||||
this->hide();
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
#include "UI/MainWindow.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "Models/UploadForm.h"
|
|
||||||
#include "Syncers/Upload.h"
|
|
||||||
#include "Utilities/Conversions.h"
|
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
using std::string;
|
|
||||||
using std::unique_ptr;
|
|
||||||
|
|
||||||
using Models::UploadForm;
|
|
||||||
using Syncers::Upload;
|
|
||||||
|
|
||||||
namespace UI
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region Constructors
|
|
||||||
MainWindow::MainWindow()
|
|
||||||
{
|
|
||||||
setupMainWindow();
|
|
||||||
aboutWindow = unique_ptr<AboutWindow>{new AboutWindow};
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region Functions
|
|
||||||
void MainWindow::configureDownloadSection()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void MainWindow::configureUploadSection()
|
|
||||||
{
|
|
||||||
uploadSongQt = unique_ptr<QPushButton>{new QPushButton(tr("Upload"))};
|
|
||||||
urlQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
|
||||||
sourceFilePathQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
|
||||||
|
|
||||||
urlLabel = unique_ptr<QLabel>{new QLabel(tr("URL"))};
|
|
||||||
songPath = unique_ptr<QLabel>{new QLabel(tr("Song Path"))};
|
|
||||||
|
|
||||||
urlPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
|
||||||
songPathPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
|
||||||
|
|
||||||
urlPortion.get()->addWidget(urlLabel.get());
|
|
||||||
urlPortion.get()->addWidget(urlQt.get());
|
|
||||||
|
|
||||||
songPathPortion->addWidget(songPath.get());
|
|
||||||
songPathPortion->addWidget(sourceFilePathQt.get());
|
|
||||||
|
|
||||||
subLayoutOneQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
|
||||||
subLayoutOneQt.get()->addLayout(urlPortion.get());
|
|
||||||
subLayoutOneQt->addLayout(songPathPortion.get());
|
|
||||||
mainLayoutQt.get()->addLayout(subLayoutOneQt.get());
|
|
||||||
}
|
|
||||||
void MainWindow::configureWindowDimensions()
|
|
||||||
{
|
|
||||||
windowWidth = 450;
|
|
||||||
windowHeight = 450;
|
|
||||||
}
|
|
||||||
void MainWindow::configureWindowProperties()
|
|
||||||
{
|
|
||||||
setWindowTitle("IcarusDownloadManager");
|
|
||||||
setFixedHeight(windowHeight);
|
|
||||||
setFixedWidth(windowWidth);
|
|
||||||
}
|
|
||||||
void MainWindow::connections()
|
|
||||||
{
|
|
||||||
QObject::connect(uploadSongQt.get(), SIGNAL(clicked()), this, SLOT(uploadSong()));
|
|
||||||
QObject::connect(closeApplicationQt.get(), SIGNAL(triggered()), this,
|
|
||||||
SLOT(exitApplication()));
|
|
||||||
QObject::connect(aboutApplicationQt.get(), SIGNAL(triggered()), this,
|
|
||||||
SLOT(displaySoftwareInformation()));
|
|
||||||
QObject::connect(windowComboBox.get(), SIGNAL(activated(int)),
|
|
||||||
this, SLOT(setCurrentIndex(int)));
|
|
||||||
}
|
|
||||||
void MainWindow::createMenus()
|
|
||||||
{
|
|
||||||
fileMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("File"))};
|
|
||||||
editMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Edit"))};
|
|
||||||
helpMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Help"))};
|
|
||||||
|
|
||||||
closeApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
|
||||||
closeApplicationQt->setText("Exit Application");
|
|
||||||
|
|
||||||
aboutApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
|
||||||
aboutApplicationQt->setText("About");
|
|
||||||
|
|
||||||
fileMenuQt->addAction(closeApplicationQt.get());
|
|
||||||
helpMenuQt->addAction(aboutApplicationQt.get());
|
|
||||||
|
|
||||||
}
|
|
||||||
void MainWindow::setupMainWidget()
|
|
||||||
{
|
|
||||||
mainWidgetQt = unique_ptr<QWidget>{new QWidget};
|
|
||||||
|
|
||||||
windowComboBox = unique_ptr<QComboBox>{new QComboBox};
|
|
||||||
setupWindowLists();
|
|
||||||
|
|
||||||
|
|
||||||
stackLayout = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
|
||||||
stackLayout->addWidget(windowComboBox.get());
|
|
||||||
|
|
||||||
uploadSongWidgetQt = unique_ptr<QWidget>{new QWidget};
|
|
||||||
uploadSongWidgetQt->setLayout(mainLayoutQt.get());
|
|
||||||
|
|
||||||
stackLayout->addWidget(uploadSongWidgetQt.get());
|
|
||||||
|
|
||||||
mainWidgetQt->setLayout(stackLayout.get());
|
|
||||||
}
|
|
||||||
void MainWindow::setupMainWindow()
|
|
||||||
{
|
|
||||||
configureWindowDimensions();
|
|
||||||
|
|
||||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
|
||||||
widgetStack = unique_ptr<QStackedWidget>{new QStackedWidget};
|
|
||||||
|
|
||||||
configureUploadSection();
|
|
||||||
|
|
||||||
setupMainWidget();
|
|
||||||
|
|
||||||
widgetStack->addWidget(mainWidgetQt.get());
|
|
||||||
|
|
||||||
MainDockWidgetQt = unique_ptr<QDockWidget>{new QDockWidget};
|
|
||||||
MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager"));
|
|
||||||
MainDockWidgetQt->setWidget(widgetStack.get());
|
|
||||||
MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
|
||||||
|
|
||||||
setCentralWidget(MainDockWidgetQt.get());
|
|
||||||
|
|
||||||
createMenus();
|
|
||||||
|
|
||||||
configureWindowProperties();
|
|
||||||
|
|
||||||
connections();
|
|
||||||
}
|
|
||||||
void MainWindow::setupWindowLists()
|
|
||||||
{
|
|
||||||
windowComboBox->addItem(tr("Upload song"));
|
|
||||||
windowComboBox->addItem(tr("Download song"));
|
|
||||||
windowComboBox->addItem(tr("Display all songs"));
|
|
||||||
windowComboBox->addItem(tr("Display songs"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::exitApplication()
|
|
||||||
{
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
void MainWindow::displaySoftwareInformation()
|
|
||||||
{
|
|
||||||
aboutWindow->show();
|
|
||||||
}
|
|
||||||
void MainWindow::setCurrentIndex(int index)
|
|
||||||
{
|
|
||||||
cout<<"index "<<index<<endl;
|
|
||||||
QString qText = windowComboBox->itemText(index);
|
|
||||||
auto cnvert = Utilities::Conversions(qText);
|
|
||||||
auto convertedStr = cnvert.convertQStringToString();
|
|
||||||
cout<<"item text"<<endl;
|
|
||||||
}
|
|
||||||
void MainWindow::uploadSong()
|
|
||||||
{
|
|
||||||
uploadSongQt->setEnabled(false);
|
|
||||||
|
|
||||||
string url = urlQt->toPlainText().toUtf8().constData();
|
|
||||||
string filePath = sourceFilePathQt->toPlainText().toUtf8().constData();
|
|
||||||
cout<<"URL endpoint: "<<url<<endl;
|
|
||||||
cout<<"Music file path: "<<filePath<<endl;
|
|
||||||
UploadForm formData{url, filePath};
|
|
||||||
|
|
||||||
Upload upld{formData};
|
|
||||||
upld.uploadSong();
|
|
||||||
|
|
||||||
uploadSongQt->setEnabled(true);
|
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#include "Utilities/Conversions.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
using std::unique_ptr;
|
|
||||||
|
|
||||||
namespace Utilities
|
|
||||||
{
|
|
||||||
|
|
||||||
Conversions::Conversions()
|
|
||||||
{
|
|
||||||
initializeValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conversions::initializeValues()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
template <typename T>
|
|
||||||
void Conversions::printValue(T val)
|
|
||||||
{
|
|
||||||
std::cout<<"going to print value\n";
|
|
||||||
std::cout<<val<< "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-1
Submodule vcpkg deleted from 9d47b24eac
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
|
|
||||||
"dependencies": [
|
|
||||||
"nlohmann-json",
|
|
||||||
"curl",
|
|
||||||
"openssl",
|
|
||||||
"cpr"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user