init
This commit is contained in:
78
libEcliptPlayer/include/eclipt/Playlist.h
Normal file
78
libEcliptPlayer/include/eclipt/Playlist.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef ECLIPT_PLAYLIST_H
|
||||
#define ECLIPT_PLAYLIST_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
namespace eclipt {
|
||||
|
||||
enum class PlaylistType {
|
||||
M3U,
|
||||
M3U8,
|
||||
PLS,
|
||||
EXT
|
||||
};
|
||||
|
||||
struct StreamInfo {
|
||||
int index = -1;
|
||||
std::string name;
|
||||
std::string language;
|
||||
std::string codec;
|
||||
int bandwidth = 0;
|
||||
std::string url;
|
||||
std::string group;
|
||||
bool is_default = false;
|
||||
bool is_selected = false;
|
||||
};
|
||||
|
||||
struct PlaylistItem {
|
||||
std::string name;
|
||||
std::string url;
|
||||
std::string tvg_name;
|
||||
std::string tvg_id;
|
||||
std::string group;
|
||||
int tvg_logo = 0;
|
||||
int64_t duration = -1;
|
||||
bool is_live = false;
|
||||
std::vector<StreamInfo> streams;
|
||||
};
|
||||
|
||||
struct Playlist {
|
||||
std::string name;
|
||||
PlaylistType type = PlaylistType::M3U;
|
||||
std::vector<PlaylistItem> items;
|
||||
std::string base_url;
|
||||
|
||||
Playlist() = default;
|
||||
bool loadFromFile(const std::string& path);
|
||||
bool loadFromString(const std::string& content);
|
||||
bool loadFromUrl(const std::string& url);
|
||||
|
||||
std::vector<PlaylistItem> getLiveStreams() const;
|
||||
std::vector<PlaylistItem> getByGroup(const std::string& group) const;
|
||||
PlaylistItem* findById(const std::string& id);
|
||||
};
|
||||
|
||||
class IPlaylistParser {
|
||||
public:
|
||||
virtual ~IPlaylistParser() = default;
|
||||
virtual bool parse(const std::string& content, Playlist& playlist) = 0;
|
||||
virtual std::string getLastError() const = 0;
|
||||
};
|
||||
|
||||
class M3UParser : public IPlaylistParser {
|
||||
public:
|
||||
bool parse(const std::string& content, Playlist& playlist) override;
|
||||
std::string getLastError() const override { return last_error_; }
|
||||
|
||||
private:
|
||||
std::string last_error_;
|
||||
bool parseExtInf(const std::string& line, PlaylistItem& item);
|
||||
bool parseAttribute(const std::string& attr, std::string& key, std::string& value);
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user