Skip to content

Commit 9ff665c

Browse files
committed
frontend: replace Auth with YoutubeApiWrappers for YouTube callers
1 parent 2396e6e commit 9ff665c

7 files changed

Lines changed: 28 additions & 30 deletions

File tree

frontend/dialogs/OBSYoutubeActions.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ const QString SchedulDateAndTimeFormat = "yyyy-MM-dd'T'hh:mm:ss'Z'";
1717
const QString RepresentSchedulDateAndTimeFormat = "dddd, MMMM d, yyyy h:m";
1818
const QString IndexOfGamingCategory = "20";
1919

20-
OBSYoutubeActions::OBSYoutubeActions(QWidget *parent, Auth *auth, bool broadcastReady)
20+
OBSYoutubeActions::OBSYoutubeActions(QWidget *parent, YoutubeApiWrappers &apiYouTube, bool broadcastReady)
2121
: QDialog(parent),
2222
ui(new Ui::OBSYoutubeActions),
23-
apiYouTube(dynamic_cast<YoutubeApiWrappers *>(auth)),
24-
workerThread(new WorkerThread(apiYouTube)),
23+
apiYouTube(&apiYouTube),
24+
workerThread(new WorkerThread(&apiYouTube)),
2525
broadcastReady(broadcastReady)
2626
{
2727
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
@@ -122,12 +122,6 @@ OBSYoutubeActions::OBSYoutubeActions(QWidget *parent, Auth *auth, bool broadcast
122122
connect(ui->selectFileButton, &QPushButton::clicked, this, thumbSelectionHandler);
123123
connect(ui->thumbnailPreview, &ClickableLabel::clicked, this, thumbSelectionHandler);
124124

125-
if (!apiYouTube) {
126-
blog(LOG_DEBUG, "YouTube API auth NOT found.");
127-
Cancel();
128-
return;
129-
}
130-
131125
const char *name = config_get_string(OBSBasic::Get()->Config(), "YouTube", "ChannelName");
132126
this->setWindowTitle(QTStr("YouTube.Actions.WindowTitle").arg(name));
133127

frontend/dialogs/OBSYoutubeActions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class OBSYoutubeActions : public QDialog {
4747
void ShowErrorDialog(QWidget *parent, QString text);
4848

4949
public:
50-
explicit OBSYoutubeActions(QWidget *parent, Auth *auth, bool broadcastReady);
50+
explicit OBSYoutubeActions(QWidget *parent, YoutubeApiWrappers &apiYouTube, bool broadcastReady);
5151
virtual ~OBSYoutubeActions() override;
5252

5353
bool Valid() { return valid; };

frontend/settings/OBSBasicSettings_Stream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ OBSService OBSBasicSettings::SpawnTempService()
808808

809809
void OBSBasicSettings::OnOAuthStreamKeyConnected()
810810
{
811-
OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
811+
OAuthStreamKey *a = dynamic_cast<OAuthStreamKey *>(auth.get());
812812

813813
if (a) {
814814
bool validKey = !a->key().empty();

frontend/widgets/OBSBasic.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class OBSProjector;
6060
class VolumeControl;
6161
#ifdef YOUTUBE_ENABLED
6262
class YouTubeAppDock;
63+
class YoutubeApiWrappers;
6364
#endif
6465
class QMessageBox;
6566
class QWidgetAction;
@@ -1670,7 +1671,7 @@ private slots:
16701671
QPointer<YouTubeAppDock> youtubeAppDock;
16711672
uint64_t lastYouTubeAppDockCreationTime = 0;
16721673

1673-
void YoutubeStreamCheck(const std::string &key);
1674+
void YoutubeStreamCheck(YoutubeApiWrappers *apiYouTube, const std::string &key);
16741675
void ShowYouTubeAutoStartWarning();
16751676
void YouTubeActionDialogOk(const std::string &broadcastId, const std::string &streamId, const std::string &key,
16761677
bool autostart, bool autostop, bool startNow);

frontend/widgets/OBSBasic_Streaming.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,10 @@ void OBSBasic::StreamingStart()
256256
obs_service_t *service_obj = GetService();
257257
OBSDataAutoRelease settings = obs_service_get_settings(service_obj);
258258
std::string key = obs_data_get_string(settings, "stream_id");
259-
if (!key.empty() && !youtubeStreamCheckThread) {
260-
youtubeStreamCheckThread = CreateQThread([this, key] { YoutubeStreamCheck(key); });
259+
YoutubeApiWrappers *apiYouTube = dynamic_cast<YoutubeApiWrappers *>(GetAuth());
260+
if (apiYouTube && !key.empty() && !youtubeStreamCheckThread) {
261+
youtubeStreamCheckThread =
262+
CreateQThread([this, apiYouTube, key] { YoutubeStreamCheck(apiYouTube, key); });
261263
youtubeStreamCheckThread->setObjectName("YouTubeStreamCheckThread");
262264
youtubeStreamCheckThread->start();
263265
}

frontend/widgets/OBSBasic_YouTube.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ void OBSBasic::YouTubeActionDialogOk(const std::string &broadcastId, const std::
5454
}
5555
}
5656

57-
void OBSBasic::YoutubeStreamCheck(const std::string &key)
57+
void OBSBasic::YoutubeStreamCheck(YoutubeApiWrappers *apiYouTube, const std::string &key)
5858
{
59-
YoutubeApiWrappers *apiYouTube(dynamic_cast<YoutubeApiWrappers *>(GetAuth()));
6059
if (!apiYouTube) {
6160
/* technically we should never get here -Lain */
6261
QMetaObject::invokeMethod(this, "ForceStopStreaming", Qt::QueuedConnection);
@@ -202,8 +201,9 @@ void OBSBasic::SetupBroadcast()
202201
{
203202
#ifdef YOUTUBE_ENABLED
204203
Auth *const auth = GetAuth();
205-
if (IsYouTubeService(auth->service())) {
206-
OBSYoutubeActions dialog(this, auth, broadcastReady);
204+
YoutubeApiWrappers *apiYouTube = dynamic_cast<YoutubeApiWrappers *>(auth);
205+
if (apiYouTube) {
206+
OBSYoutubeActions dialog(this, *apiYouTube, broadcastReady);
207207
connect(&dialog, &OBSYoutubeActions::ok, this, &OBSBasic::YouTubeActionDialogOk);
208208
dialog.exec();
209209
}

frontend/wizards/AutoConfigStreamPage.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void AutoConfigStreamPage::on_show_clicked()
265265

266266
void AutoConfigStreamPage::OnOAuthStreamKeyConnected()
267267
{
268-
OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
268+
OAuthStreamKey *a = dynamic_cast<OAuthStreamKey *>(auth.get());
269269

270270
if (a) {
271271
bool validKey = !a->key().empty();
@@ -292,16 +292,17 @@ void AutoConfigStreamPage::OnOAuthStreamKeyConnected()
292292

293293
ui->connectedAccountText->setText(QTStr("Auth.LoadingChannel.Title"));
294294

295-
YoutubeApiWrappers *ytAuth = reinterpret_cast<YoutubeApiWrappers *>(a);
296-
ChannelDescription cd;
297-
if (ytAuth->GetChannelDescription(cd)) {
298-
ui->connectedAccountText->setText(cd.title);
299-
300-
/* Create throwaway stream key for bandwidth test */
301-
if (ui->doBandwidthTest->isChecked()) {
302-
StreamDescription stream = {"", "", "OBS Studio Test Stream"};
303-
if (ytAuth->InsertStream(stream)) {
304-
ui->key->setText(stream.name);
295+
if (YoutubeApiWrappers *ytAuth = dynamic_cast<YoutubeApiWrappers *>(a)) {
296+
ChannelDescription cd;
297+
if (ytAuth->GetChannelDescription(cd)) {
298+
ui->connectedAccountText->setText(cd.title);
299+
300+
/* Create throwaway stream key for bandwidth test */
301+
if (ui->doBandwidthTest->isChecked()) {
302+
StreamDescription stream = {"", "", "OBS Studio Test Stream"};
303+
if (ytAuth->InsertStream(stream)) {
304+
ui->key->setText(stream.name);
305+
}
305306
}
306307
}
307308
}
@@ -406,7 +407,7 @@ void AutoConfigStreamPage::reset_service_ui_fields(std::string &service)
406407
{
407408
#ifdef YOUTUBE_ENABLED
408409
// when account is already connected:
409-
OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
410+
OAuthStreamKey *a = dynamic_cast<OAuthStreamKey *>(auth.get());
410411
if (a && service == a->service() && IsYouTubeService(a->service())) {
411412
ui->connectedAccountLabel->setVisible(true);
412413
ui->connectedAccountText->setVisible(true);

0 commit comments

Comments
 (0)