1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #pragma once
- #include <glibmm/ustring.h>
- #include <string>
- #include <curl/curl.h>
- #include <vector>
- #include <sstream>
- #include <nlohmann/json.hpp>
- #include <iostream>
- #include <Database/entities.hpp>
- #include <Database/database.hpp>
- namespace ytapi {
-
- // Детали видео - необработанные
- struct video_result {
- std::string yt_id; // ID на YouTube
- Glib::ustring title; // Название
- Glib::ustring description; // Описание
- std::string duration; // Длительность
- std::string author_yt_id; // ID автора на YouTube
- Glib::ustring author_name; // Имя автора на YouTube
- std::string published_at; // Когда было опубликовано
- int views_count; // Количество просмотров
- int rating; // Моя оценка видео
- };
-
- // API ключ
- static std::string api_key;
- // Записывает ключ API в api_key
- void youtubeInit(std::string key);
-
- // Функция записи данных в std::ostringstream
- size_t writeHttpToString(char* ptr, size_t size, size_t nmemb, void *userdata);
- // Функция записи данных в файл на диске
- size_t writeHttpToFile(void* ptr, size_t size, size_t nmemb, FILE* userdata);
- // Кодирует URL-строку
- // https://stackoverflow.com/a/154627
- std::string urlencode(const std::string& decoded);
- // Раскодирует URL-строку
- std::string urldecode(const std::string& encoded);
- // Получает список YT_ID видео по запросу
- std::vector<std::string> getVideoIDsByQuery(std::string query);
- // Возвращает объект видео, получив данные по API
- video_result getVideoByYTID(std::string yt_id);
- // Возвращает список видео id из JSON списка видео
- std::vector<std::string> getVideoIDsFromJSON(std::string input);
- // Подгатавливает, настраивает и выполняет CURL запрос. Возвращает
- // успешность вызова
- bool performCurlRequest(std::string url, std::stringstream* response);
- // Подгатавливает, настраивает и выполняет CURL запрос на скачивание файла
- // Файл сохранится в save_path
- bool performCurlRequest(std::string url, std::string save_path);
- // Скачивает превью видео и сохраняет в путь save_path
- void downloadMediumThumnail(std::string yt_id, std::string save_path);
- // Скачивает большое превью видео и сохраняет в путь save_path
- void downloadLargeThumnail(std::string yt_id, std::string save_path);
- }
|