Skip to content

Commit 1e3b8a4

Browse files
committed
frontend: replace Auth with YoutubeApiWrappers for YouTube callers
1 parent 9f4320e commit 1e3b8a4

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
@@ -787,7 +787,7 @@ OBSService OBSBasicSettings::SpawnTempService()
787787

788788
void OBSBasicSettings::OnOAuthStreamKeyConnected()
789789
{
790-
OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
790+
OAuthStreamKey *a = dynamic_cast<OAuthStreamKey *>(auth.get());
791791

792792
if (a) {
793793
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;
@@ -1667,7 +1668,7 @@ private slots:
16671668
QPointer<YouTubeAppDock> youtubeAppDock;
16681669
uint64_t lastYouTubeAppDockCreationTime = 0;
16691670

1670-
void YoutubeStreamCheck(const std::string &key);
1671+
void YoutubeStreamCheck(YoutubeApiWrappers *apiYouTube, const std::string &key);
16711672
void ShowYouTubeAutoStartWarning();
16721673
void YouTubeActionDialogOk(const std::string &broadcastId, const std::string &streamId, const std::string &key,
16731674
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
@@ -244,8 +244,10 @@ void OBSBasic::StreamingStart()
244244
obs_service_t *service_obj = GetService();
245245
OBSDataAutoRelease settings = obs_service_get_settings(service_obj);
246246
std::string key = obs_data_get_string(settings, "stream_id");
247-
if (!key.empty() && !youtubeStreamCheckThread) {
248-
youtubeStreamCheckThread = CreateQThread([this, key] { YoutubeStreamCheck(key); });
247+
YoutubeApiWrappers *apiYouTube = dynamic_cast<YoutubeApiWrappers *>(GetAuth());
248+
if (apiYouTube && !key.empty() && !youtubeStreamCheckThread) {
249+
youtubeStreamCheckThread =
250+
CreateQThread([this, apiYouTube, key] { YoutubeStreamCheck(apiYouTube, key); });
249251
youtubeStreamCheckThread->setObjectName("YouTubeStreamCheckThread");
250252
youtubeStreamCheckThread->start();
251253
}

frontend/widgets/OBSBasic_YouTube.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ void OBSBasic::YouTubeActionDialogOk(const std::string &broadcastId, const std::
5353
QMetaObject::invokeMethod(this, "StartStreaming");
5454
}
5555

56-
void OBSBasic::YoutubeStreamCheck(const std::string &key)
56+
void OBSBasic::YoutubeStreamCheck(YoutubeApiWrappers *apiYouTube, const std::string &key)
5757
{
58-
YoutubeApiWrappers *apiYouTube(dynamic_cast<YoutubeApiWrappers *>(GetAuth()));
5958
if (!apiYouTube) {
6059
/* technically we should never get here -Lain */
6160
QMetaObject::invokeMethod(this, "ForceStopStreaming", Qt::QueuedConnection);
@@ -196,8 +195,9 @@ void OBSBasic::SetupBroadcast()
196195
{
197196
#ifdef YOUTUBE_ENABLED
198197
Auth *const auth = GetAuth();
199-
if (IsYouTubeService(auth->service())) {
200-
OBSYoutubeActions dialog(this, auth, broadcastReady);
198+
YoutubeApiWrappers *apiYouTube = dynamic_cast<YoutubeApiWrappers *>(auth);
199+
if (apiYouTube) {
200+
OBSYoutubeActions dialog(this, *apiYouTube, broadcastReady);
201201
connect(&dialog, &OBSYoutubeActions::ok, this, &OBSBasic::YouTubeActionDialogOk);
202202
dialog.exec();
203203
}

frontend/wizards/AutoConfigStreamPage.cpp

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

256256
void AutoConfigStreamPage::OnOAuthStreamKeyConnected()
257257
{
258-
OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
258+
OAuthStreamKey *a = dynamic_cast<OAuthStreamKey *>(auth.get());
259259

260260
if (a) {
261261
bool validKey = !a->key().empty();
@@ -281,16 +281,17 @@ void AutoConfigStreamPage::OnOAuthStreamKeyConnected()
281281

282282
ui->connectedAccountText->setText(QTStr("Auth.LoadingChannel.Title"));
283283

284-
YoutubeApiWrappers *ytAuth = reinterpret_cast<YoutubeApiWrappers *>(a);
285-
ChannelDescription cd;
286-
if (ytAuth->GetChannelDescription(cd)) {
287-
ui->connectedAccountText->setText(cd.title);
288-
289-
/* Create throwaway stream key for bandwidth test */
290-
if (ui->doBandwidthTest->isChecked()) {
291-
StreamDescription stream = {"", "", "OBS Studio Test Stream"};
292-
if (ytAuth->InsertStream(stream)) {
293-
ui->key->setText(stream.name);
284+
if (YoutubeApiWrappers *ytAuth = dynamic_cast<YoutubeApiWrappers *>(a)) {
285+
ChannelDescription cd;
286+
if (ytAuth->GetChannelDescription(cd)) {
287+
ui->connectedAccountText->setText(cd.title);
288+
289+
/* Create throwaway stream key for bandwidth test */
290+
if (ui->doBandwidthTest->isChecked()) {
291+
StreamDescription stream = {"", "", "OBS Studio Test Stream"};
292+
if (ytAuth->InsertStream(stream)) {
293+
ui->key->setText(stream.name);
294+
}
294295
}
295296
}
296297
}
@@ -395,7 +396,7 @@ void AutoConfigStreamPage::reset_service_ui_fields(std::string &service)
395396
{
396397
#ifdef YOUTUBE_ENABLED
397398
// when account is already connected:
398-
OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
399+
OAuthStreamKey *a = dynamic_cast<OAuthStreamKey *>(auth.get());
399400
if (a && service == a->service() && IsYouTubeService(a->service())) {
400401
ui->connectedAccountLabel->setVisible(true);
401402
ui->connectedAccountText->setVisible(true);

0 commit comments

Comments
 (0)