|
@@ -1,25 +1,64 @@
|
|
|
#include "core.hpp"
|
|
|
-#include <giomm/icon.h>
|
|
|
-#include <gtkmm/image.h>
|
|
|
-#include <gtkmm/label.h>
|
|
|
-#include <string>
|
|
|
+#include <nlohmann/json.hpp>
|
|
|
+#include <YoutubeApi/youtubeapi.hpp>
|
|
|
+#include <Database/database.hpp>
|
|
|
+
|
|
|
+using json = nlohmann::json;
|
|
|
|
|
|
namespace core {
|
|
|
|
|
|
- std::string AppState::current_yt_id = "";
|
|
|
-
|
|
|
- db::video getVideoByYTID(std::string yt_id)
|
|
|
+ Core::Core(
|
|
|
+ std::string client_secret,
|
|
|
+ std::string config_path,
|
|
|
+ int quality,
|
|
|
+ bool launch_fullscreen,
|
|
|
+ bool launch_ontop,
|
|
|
+ bool launch_miniplayer,)
|
|
|
+ // Инициализация
|
|
|
+ : m_client_secret(client_secret)
|
|
|
+ , m_selected_ytid("")
|
|
|
+ , m_config_path(config_path)
|
|
|
+ , m_db_path(db_path)
|
|
|
+ , m_quality(quality)
|
|
|
+ , m_launch_fullscreen(launch_fullscreen),
|
|
|
+ , m_launch_ontop(launch_ontop),
|
|
|
+ , m_launch_miniplayer(launch_miniplayer),
|
|
|
+ {}
|
|
|
+
|
|
|
+ Core::setQuality(int quality)
|
|
|
+ {
|
|
|
+ this->m_quality = quality;
|
|
|
+ }
|
|
|
+
|
|
|
+ Core::saveConfig()
|
|
|
+ {
|
|
|
+ // Сериализация
|
|
|
+ json j_object = {
|
|
|
+ {"quality", this->m_quality},
|
|
|
+ {"fullscreen", this->m_launch_fullscreen},
|
|
|
+ {"ontop", this->m_launch_ontop},
|
|
|
+ {"miniplayer", this->m_launch_miniplayer},
|
|
|
+ };
|
|
|
+ std::string dump = j_object.dump(1, '\t');
|
|
|
+
|
|
|
+ // Запись в файл
|
|
|
+ std::ofstream config(m_config_path);
|
|
|
+ config << dump;
|
|
|
+ config.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ db::video Core::getVideoByYTID(std::string ytid)
|
|
|
{
|
|
|
db::video output;
|
|
|
|
|
|
// 1. Проверить есть ли видео в базе данных
|
|
|
- if (db::getVideoByYTID(yt_id, &output)) {
|
|
|
+ if (db::getVideoByYTID(ytid, &output)) {
|
|
|
return output;
|
|
|
}
|
|
|
|
|
|
// Видео в базе данных нет. Получаем информацию о нём через ytapi
|
|
|
- ytapi::video_result found_video = ytapi::getVideoByYTID(yt_id);
|
|
|
- output.yt_id = yt_id;
|
|
|
+ ytapi::Video found_video = ytapi::getVideoByYTID(ytid);
|
|
|
+ output.ytid = ytid;
|
|
|
output.title = found_video.title;
|
|
|
output.description = found_video.description;
|
|
|
output.published_at = found_video.published_at;
|
|
@@ -31,7 +70,7 @@ namespace core {
|
|
|
db::author video_author;
|
|
|
if (!db::getAuthorByYTID(found_video.author_yt_id, &video_author)) {
|
|
|
// Автора в базе данных нет. Добавляем
|
|
|
- video_author.yt_id = found_video.author_yt_id;
|
|
|
+ video_author.ytid = found_video.author_yt_id;
|
|
|
video_author.name = found_video.author_name;
|
|
|
db::addAuthor(&video_author);
|
|
|
}
|
|
@@ -43,50 +82,15 @@ namespace core {
|
|
|
return output;
|
|
|
}
|
|
|
|
|
|
- std::string getYTDLFormat(int height)
|
|
|
- {
|
|
|
- return "bestvideo[height<=?"+std::to_string(height)+"]+bestaudio/best";
|
|
|
- }
|
|
|
-
|
|
|
- std::string Settings::s_config_path("");
|
|
|
- std::string Settings::s_api_key("");
|
|
|
- int Settings::s_quality(0);
|
|
|
-
|
|
|
- void Settings::setConfigPath(std::string config_path)
|
|
|
- {
|
|
|
- s_config_path = config_path;
|
|
|
- }
|
|
|
-
|
|
|
- void Settings::setApiKey(std::string api_key)
|
|
|
- {
|
|
|
- ytapi::youtubeInit(api_key);
|
|
|
- s_api_key = api_key;
|
|
|
- }
|
|
|
-
|
|
|
- void Settings::setQuality(int quality)
|
|
|
- {
|
|
|
- s_quality = quality;
|
|
|
- }
|
|
|
-
|
|
|
- std::string Settings::getConfigPath()
|
|
|
- {
|
|
|
- return s_config_path;
|
|
|
- }
|
|
|
-
|
|
|
- std::string Settings::getApiKey()
|
|
|
- {
|
|
|
- return s_api_key;
|
|
|
- }
|
|
|
-
|
|
|
- int Settings::getQuality()
|
|
|
+ std::string Core::getYTDLFormat()
|
|
|
{
|
|
|
- return s_quality;
|
|
|
+ return "bestvideo[height<=?"+std::to_string(m_quality)+"]+bestaudio/best";
|
|
|
}
|
|
|
|
|
|
- // Устанавливает оценку в бд и посылает запрос на оценку
|
|
|
- void rateVideo(std::string yt_id, int rating)
|
|
|
+ // Устанавливает оценку в БД и посылает запрос на оценку
|
|
|
+ void rateVideo(std::string ytid, VideoRating rating)
|
|
|
{
|
|
|
- db::setVideoRating(yt_id, rating);
|
|
|
- //ytapi::setVideoRating(yt_id, rating);
|
|
|
+ db::setVideoRating(ytid, static_cast<int>(rating));
|
|
|
+ ytapi::setVideoRating(ytid, static_cast<int>(rating), m_client_secret);
|
|
|
}
|
|
|
}
|