2020-11-28 14:40:46 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-11-22 15:17:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
2020-11-22 20:29:45 +00:00
|
|
|
#include <vector>
|
2020-11-22 15:17:14 +00:00
|
|
|
|
|
|
|
class sqlite3;
|
|
|
|
class sqlite3_stmt;
|
|
|
|
class progress_info;
|
|
|
|
|
|
|
|
extern struct yt_config {
|
|
|
|
std::string api_key;
|
|
|
|
std::map<std::string, std::string> extra_headers;
|
|
|
|
} yt_config;
|
|
|
|
|
2021-07-18 14:11:16 +00:00
|
|
|
class UserFlag
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int id;
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
UserFlag(sqlite3_stmt *row);
|
2021-07-18 21:27:20 +00:00
|
|
|
void save(sqlite3 *db) const;
|
2021-07-18 14:11:16 +00:00
|
|
|
|
|
|
|
static UserFlag create(sqlite3 *db, const std::string &name);
|
|
|
|
static int next_free(sqlite3 *db);
|
|
|
|
static std::vector<UserFlag> get_all(sqlite3 *db);
|
|
|
|
|
|
|
|
static constexpr int max_flag_count = (sizeof(uint32_t)*8);
|
|
|
|
|
|
|
|
private:
|
|
|
|
UserFlag(int id, const std::string &name);
|
|
|
|
};
|
|
|
|
|
2020-11-26 12:27:11 +00:00
|
|
|
enum VideoFlag {
|
|
|
|
kNone = 0,
|
|
|
|
kWatched = (1<<0),
|
|
|
|
kDownloaded = (1<<1),
|
|
|
|
};
|
|
|
|
|
2021-07-18 21:57:44 +00:00
|
|
|
class ChannelFilter {
|
|
|
|
public:
|
|
|
|
int id;
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
uint32_t video_mask;
|
|
|
|
uint32_t video_value;
|
|
|
|
|
|
|
|
uint32_t user_mask;
|
|
|
|
uint32_t user_value;
|
|
|
|
|
|
|
|
ChannelFilter();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ChannelFilter(const int id, const std::string &name);
|
|
|
|
};
|
|
|
|
|
2020-11-22 15:17:14 +00:00
|
|
|
class Channel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string id;
|
|
|
|
std::string name;
|
2020-11-26 12:27:11 +00:00
|
|
|
bool is_virtual;
|
2021-07-18 21:57:44 +00:00
|
|
|
ChannelFilter filter;
|
2020-11-22 15:17:14 +00:00
|
|
|
|
2021-07-18 14:11:16 +00:00
|
|
|
int user_flags;
|
|
|
|
|
2020-11-22 15:17:14 +00:00
|
|
|
Channel(sqlite3_stmt *row);
|
|
|
|
static Channel add(sqlite3 *db, const std::string &selector, const std::string &value);
|
2021-07-18 21:57:44 +00:00
|
|
|
static Channel add_virtual(const std::string &name, const ChannelFilter filter);
|
2020-11-22 20:29:45 +00:00
|
|
|
static std::vector<Channel> get_all(sqlite3 *db);
|
2020-11-22 15:17:14 +00:00
|
|
|
|
|
|
|
std::string upload_playlist() const;
|
2021-07-18 14:39:32 +00:00
|
|
|
int fetch_new_videos(sqlite3 *db, progress_info *info=nullptr, std::optional<std::string> after={}, std::optional<int> max_count={}) const;
|
2020-11-22 15:17:14 +00:00
|
|
|
void load_info(sqlite3 *db);
|
|
|
|
bool is_valid() const;
|
|
|
|
|
2021-07-18 21:58:33 +00:00
|
|
|
void save_user_flags(sqlite3 *db) const;
|
2021-07-18 14:11:16 +00:00
|
|
|
|
2020-11-22 15:17:14 +00:00
|
|
|
unsigned int unwatched;
|
2020-12-06 18:40:10 +00:00
|
|
|
size_t tui_name_width;
|
2020-11-22 15:17:14 +00:00
|
|
|
private:
|
|
|
|
Channel(const std::string &id, const std::string &name);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Video
|
|
|
|
{
|
|
|
|
std::string id;
|
2020-12-06 18:40:10 +00:00
|
|
|
std::string channel_id;
|
2020-11-22 15:17:14 +00:00
|
|
|
std::string title;
|
|
|
|
std::string description;
|
|
|
|
int flags;
|
2021-07-18 14:39:32 +00:00
|
|
|
std::string added_to_playlist;
|
2020-11-22 15:17:14 +00:00
|
|
|
std::string published;
|
|
|
|
|
|
|
|
Video(sqlite3_stmt *row);
|
|
|
|
void set_flag(sqlite3 *db, VideoFlag flag, bool value=true);
|
2020-11-22 20:29:45 +00:00
|
|
|
static std::vector<Video> get_all_for_channel(const std::string &channel_id);
|
2021-07-18 21:57:44 +00:00
|
|
|
static std::vector<Video> get_all_with_filter(const ChannelFilter &filter);
|
2020-11-22 15:17:14 +00:00
|
|
|
|
|
|
|
size_t tui_title_width;
|
|
|
|
};
|