0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
obs-studio/UI/youtube-api-wrappers.hpp
derrod a4d37dba73 UI: Fix YouTube event selection, API usage, stream resumption
All these fixes are interlinked but to explain them further:
Event selection would only partially work, the code to re-use an
existing liveStream was never hit and so didn't work. It would also
break going live because broadcast_id would never be set. Additionally
it called StartBroadcast for no reason if autostart was enabled.

API usage was unoptimal. Instead of only fetching the events we need
(active, ready) it would fetch *every single livestream* on the youtube
channel, 7 at a time, and then throw away every single result in the
majority of use cases.
This commit changes it to only fetch "active" and "ready" broadcasts and
then only filters out active ones that cannot be resumed (because
they're stil live).

Resuming existing streams also didn't work because they were just thrown
out by the selection. Now they get included if the attached liveStream
is not receiving data. The're distinguished in the UI and are listed
first. Simply selecting them and starting the stream will work.

These's still some stuff left, like redundant API calls. But thankfully
those fail silently and we can simply ignore it for now.
2021-08-17 18:35:55 +02:00

98 lines
2.4 KiB
C++

#pragma once
#include "auth-youtube.hpp"
#include <json11.hpp>
#include <QString>
struct ChannelDescription {
QString id;
QString title;
QString country;
QString language;
};
struct StreamDescription {
QString id;
QString name;
QString title;
QString description;
};
struct CategoryDescription {
QString id;
QString title;
};
struct BroadcastDescription {
QString id;
QString title;
QString description;
QString privacy;
CategoryDescription category;
QString latency;
bool made_for_kids;
bool auto_start;
bool auto_stop;
bool dvr;
bool schedul_for_later;
QString schedul_date_time;
QString projection;
};
struct BindDescription {
const QString id;
const QString stream_name;
};
bool IsYouTubeService(const std::string &service);
class YoutubeApiWrappers : public YoutubeAuth {
Q_OBJECT
bool TryInsertCommand(const char *url, const char *content_type,
std::string request_type, const char *data,
json11::Json &ret, long *error_code = nullptr);
bool UpdateAccessToken();
bool InsertCommand(const char *url, const char *content_type,
std::string request_type, const char *data,
json11::Json &ret);
public:
YoutubeApiWrappers(const Def &d);
bool GetChannelDescription(ChannelDescription &channel_description);
bool InsertBroadcast(BroadcastDescription &broadcast);
bool InsertStream(StreamDescription &stream);
bool BindStream(const QString broadcast_id, const QString stream_id);
bool GetBroadcastsList(json11::Json &json_out, const QString &page,
const QString &status);
bool
GetVideoCategoriesList(const QString &country, const QString &language,
QVector<CategoryDescription> &category_list_out);
bool SetVideoCategory(const QString &video_id,
const QString &video_title,
const QString &video_description,
const QString &categorie_id);
bool StartBroadcast(const QString &broadcast_id);
bool StopBroadcast(const QString &broadcast_id);
bool ResetBroadcast(const QString &broadcast_id);
bool StartLatestBroadcast();
bool StopLatestBroadcast();
void SetBroadcastId(QString &broadcast_id);
bool FindBroadcast(const QString &id, json11::Json &json_out);
bool FindStream(const QString &id, json11::Json &json_out);
QString GetLastError() { return lastErrorMessage; };
bool GetTranslatedError(QString &error_message);
private:
QString broadcast_id;
int lastError;
QString lastErrorMessage;
QString lastErrorReason;
};