init
This commit is contained in:
104
libEcliptPlayer/include/eclipt/EPG.h
Normal file
104
libEcliptPlayer/include/eclipt/EPG.h
Normal file
@@ -0,0 +1,104 @@
|
||||
#ifndef ECLIPT_EPG_H
|
||||
#define ECLIPT_EPG_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
namespace eclipt {
|
||||
|
||||
struct EPGEvent {
|
||||
int64_t id = 0;
|
||||
std::string title;
|
||||
std::string description;
|
||||
int64_t start_time = 0;
|
||||
int64_t end_time = 0;
|
||||
int64_t duration = 0;
|
||||
std::string channel_id;
|
||||
std::string category;
|
||||
std::string icon_url;
|
||||
bool is_current = false;
|
||||
bool is_future = false;
|
||||
bool is_past = false;
|
||||
};
|
||||
|
||||
struct EPGChannel {
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string icon_url;
|
||||
std::string group;
|
||||
std::vector<EPGEvent> events;
|
||||
|
||||
const EPGEvent* getCurrentEvent() const;
|
||||
std::vector<const EPGEvent*> getEventsInRange(int64_t start, int64_t end) const;
|
||||
};
|
||||
|
||||
struct EPGData {
|
||||
std::string source;
|
||||
int64_t fetched_time = 0;
|
||||
int64_t valid_from = 0;
|
||||
int64_t valid_to = 0;
|
||||
std::map<std::string, EPGChannel> channels;
|
||||
|
||||
bool loadFromFile(const std::string& path);
|
||||
bool loadFromXml(const std::string& xml_content);
|
||||
bool loadFromUrl(const std::string& url);
|
||||
|
||||
bool merge(const EPGData& other);
|
||||
|
||||
const EPGChannel* findChannel(const std::string& id) const;
|
||||
std::vector<const EPGChannel*> findChannels(const std::string& group) const;
|
||||
};
|
||||
|
||||
class EPGParser {
|
||||
public:
|
||||
virtual ~EPGParser() = default;
|
||||
virtual bool parse(const std::string& content, EPGData& epg) = 0;
|
||||
virtual std::string getLastError() const = 0;
|
||||
};
|
||||
|
||||
class XmltvParser : public EPGParser {
|
||||
public:
|
||||
bool parse(const std::string& content, EPGData& epg) override;
|
||||
std::string getLastError() const override { return last_error_; }
|
||||
|
||||
private:
|
||||
std::string last_error_;
|
||||
bool parseChannel(const std::string& xml, EPGChannel& channel);
|
||||
bool parseProgramme(const std::string& xml, EPGEvent& event);
|
||||
int64_t parseXmltvTime(const std::string& str);
|
||||
};
|
||||
|
||||
class EPGFetcher {
|
||||
public:
|
||||
EPGFetcher();
|
||||
~EPGFetcher();
|
||||
|
||||
void setBaseUrl(const std::string& url);
|
||||
void setAuth(const std::string& username, const std::string& password);
|
||||
|
||||
bool fetch(EPGData& epg, const std::string& channel_id = "");
|
||||
bool fetchAll(EPGData& epg);
|
||||
|
||||
void cancel();
|
||||
bool isCancelled() const { return cancelled_; }
|
||||
|
||||
using ProgressCallback = std::function<void(int percent, const char* status)>;
|
||||
void setProgressCallback(ProgressCallback callback);
|
||||
|
||||
private:
|
||||
std::string base_url_;
|
||||
std::string username_;
|
||||
std::string password_;
|
||||
bool cancelled_ = false;
|
||||
ProgressCallback progress_callback_;
|
||||
|
||||
std::string buildUrl(const std::string& channel_id);
|
||||
bool authenticate();
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user