window-youtube-actions.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. #include "window-basic-main.hpp"
  2. #include "window-youtube-actions.hpp"
  3. #include "obs-app.hpp"
  4. #include "qt-wrappers.hpp"
  5. #include "youtube-api-wrappers.hpp"
  6. #include <QToolTip>
  7. #include <QDateTime>
  8. #include <QDesktopServices>
  9. const QString SchedulDateAndTimeFormat = "yyyy-MM-dd'T'hh:mm:ss'Z'";
  10. const QString RepresentSchedulDateAndTimeFormat = "dddd, MMMM d, yyyy h:m";
  11. const QString IndexOfGamingCategory = "20";
  12. OBSYoutubeActions::OBSYoutubeActions(QWidget *parent, Auth *auth,
  13. bool broadcastReady)
  14. : QDialog(parent),
  15. ui(new Ui::OBSYoutubeActions),
  16. apiYouTube(dynamic_cast<YoutubeApiWrappers *>(auth)),
  17. workerThread(new WorkerThread(apiYouTube)),
  18. broadcastReady(broadcastReady)
  19. {
  20. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  21. ui->setupUi(this);
  22. ui->privacyBox->addItem(QTStr("YouTube.Actions.Privacy.Public"),
  23. "public");
  24. ui->privacyBox->addItem(QTStr("YouTube.Actions.Privacy.Unlisted"),
  25. "unlisted");
  26. ui->privacyBox->addItem(QTStr("YouTube.Actions.Privacy.Private"),
  27. "private");
  28. ui->latencyBox->addItem(QTStr("YouTube.Actions.Latency.Normal"),
  29. "normal");
  30. ui->latencyBox->addItem(QTStr("YouTube.Actions.Latency.Low"), "low");
  31. ui->latencyBox->addItem(QTStr("YouTube.Actions.Latency.UltraLow"),
  32. "ultraLow");
  33. UpdateOkButtonStatus();
  34. connect(ui->title, &QLineEdit::textChanged, this,
  35. [&](const QString &) { this->UpdateOkButtonStatus(); });
  36. connect(ui->privacyBox, &QComboBox::currentTextChanged, this,
  37. [&](const QString &) { this->UpdateOkButtonStatus(); });
  38. connect(ui->yesMakeForKids, &QRadioButton::toggled, this,
  39. [&](bool) { this->UpdateOkButtonStatus(); });
  40. connect(ui->notMakeForKids, &QRadioButton::toggled, this,
  41. [&](bool) { this->UpdateOkButtonStatus(); });
  42. connect(ui->tabWidget, &QTabWidget::currentChanged, this,
  43. [&](int) { this->UpdateOkButtonStatus(); });
  44. connect(ui->pushButton, &QPushButton::clicked, this,
  45. &OBSYoutubeActions::OpenYouTubeDashboard);
  46. connect(ui->helpAutoStartStop, &QLabel::linkActivated, this,
  47. [](const QString &) {
  48. QToolTip::showText(
  49. QCursor::pos(),
  50. QTStr("YouTube.Actions.AutoStartStop.TT"));
  51. });
  52. connect(ui->help360Video, &QLabel::linkActivated, this,
  53. [](const QString &link) { QDesktopServices::openUrl(link); });
  54. connect(ui->helpMadeForKids, &QLabel::linkActivated, this,
  55. [](const QString &link) { QDesktopServices::openUrl(link); });
  56. ui->scheduledTime->setVisible(false);
  57. connect(ui->checkScheduledLater, &QCheckBox::stateChanged, this,
  58. [&](int state) {
  59. ui->scheduledTime->setVisible(state);
  60. if (state) {
  61. ui->checkAutoStart->setVisible(true);
  62. ui->checkAutoStop->setVisible(true);
  63. ui->helpAutoStartStop->setVisible(true);
  64. ui->checkAutoStart->setChecked(false);
  65. ui->checkAutoStop->setChecked(false);
  66. } else {
  67. ui->checkAutoStart->setVisible(false);
  68. ui->checkAutoStop->setVisible(false);
  69. ui->helpAutoStartStop->setVisible(false);
  70. ui->checkAutoStart->setChecked(true);
  71. ui->checkAutoStop->setChecked(true);
  72. }
  73. UpdateOkButtonStatus();
  74. });
  75. ui->checkAutoStart->setVisible(false);
  76. ui->checkAutoStop->setVisible(false);
  77. ui->helpAutoStartStop->setVisible(false);
  78. ui->scheduledTime->setDateTime(QDateTime::currentDateTime());
  79. if (!apiYouTube) {
  80. blog(LOG_DEBUG, "YouTube API auth NOT found.");
  81. Cancel();
  82. return;
  83. }
  84. ChannelDescription channel;
  85. if (!apiYouTube->GetChannelDescription(channel)) {
  86. blog(LOG_DEBUG, "Could not get channel description.");
  87. ShowErrorDialog(
  88. parent,
  89. apiYouTube->GetLastError().isEmpty()
  90. ? QTStr("YouTube.Actions.Error.General")
  91. : QTStr("YouTube.Actions.Error.Text")
  92. .arg(apiYouTube->GetLastError()));
  93. Cancel();
  94. return;
  95. }
  96. this->setWindowTitle(channel.title);
  97. QVector<CategoryDescription> category_list;
  98. if (!apiYouTube->GetVideoCategoriesList(category_list)) {
  99. ShowErrorDialog(
  100. parent,
  101. apiYouTube->GetLastError().isEmpty()
  102. ? QTStr("YouTube.Actions.Error.General")
  103. : QTStr("YouTube.Actions.Error.Text")
  104. .arg(apiYouTube->GetLastError()));
  105. Cancel();
  106. return;
  107. }
  108. for (auto &category : category_list) {
  109. ui->categoryBox->addItem(category.title, category.id);
  110. if (category.id == IndexOfGamingCategory) {
  111. ui->categoryBox->setCurrentText(category.title);
  112. }
  113. }
  114. connect(ui->okButton, &QPushButton::clicked, this,
  115. &OBSYoutubeActions::InitBroadcast);
  116. connect(ui->saveButton, &QPushButton::clicked, this,
  117. &OBSYoutubeActions::ReadyBroadcast);
  118. connect(ui->cancelButton, &QPushButton::clicked, this, [&]() {
  119. blog(LOG_DEBUG, "YouTube live broadcast creation cancelled.");
  120. // Close the dialog.
  121. Cancel();
  122. });
  123. qDeleteAll(ui->scrollAreaWidgetContents->findChildren<QWidget *>(
  124. QString(), Qt::FindDirectChildrenOnly));
  125. // Add label indicating loading state
  126. QLabel *loadingLabel = new QLabel();
  127. loadingLabel->setTextFormat(Qt::RichText);
  128. loadingLabel->setAlignment(Qt::AlignHCenter);
  129. loadingLabel->setText(
  130. QString("<big>%1</big>")
  131. .arg(QTStr("YouTube.Actions.EventsLoading")));
  132. ui->scrollAreaWidgetContents->layout()->addWidget(loadingLabel);
  133. // Delete "loading..." label on completion
  134. connect(workerThread, &WorkerThread::finished, this, [&] {
  135. QLayoutItem *item =
  136. ui->scrollAreaWidgetContents->layout()->takeAt(0);
  137. item->widget()->deleteLater();
  138. });
  139. connect(workerThread, &WorkerThread::failed, this, [&]() {
  140. auto last_error = apiYouTube->GetLastError();
  141. if (last_error.isEmpty())
  142. last_error = QTStr("YouTube.Actions.Error.YouTubeApi");
  143. if (!apiYouTube->GetTranslatedError(last_error))
  144. last_error = QTStr("YouTube.Actions.Error.Text")
  145. .arg(last_error);
  146. ShowErrorDialog(this, last_error);
  147. QDialog::reject();
  148. });
  149. connect(workerThread, &WorkerThread::new_item, this,
  150. [&](const QString &title, const QString &dateTimeString,
  151. const QString &broadcast, const QString &status,
  152. bool astart, bool astop) {
  153. ClickableLabel *label = new ClickableLabel();
  154. label->setTextFormat(Qt::RichText);
  155. if (status == "live" || status == "testing") {
  156. // Resumable stream
  157. label->setText(
  158. QString("<big>%1</big><br/>%2")
  159. .arg(title,
  160. QTStr("YouTube.Actions.Stream.Resume")));
  161. } else if (dateTimeString.isEmpty()) {
  162. // The broadcast created by YouTube Studio has no start time.
  163. // Yes this does violate the restrictions set in YouTube's API
  164. // But why would YouTube care about consistency?
  165. label->setText(
  166. QString("<big>%1</big><br/>%2")
  167. .arg(title,
  168. QTStr("YouTube.Actions.Stream.YTStudio")));
  169. } else {
  170. label->setText(
  171. QString("<big>%1</big><br/>%2")
  172. .arg(title,
  173. QTStr("YouTube.Actions.Stream.ScheduledFor")
  174. .arg(dateTimeString)));
  175. }
  176. label->setAlignment(Qt::AlignHCenter);
  177. label->setMargin(4);
  178. connect(label, &ClickableLabel::clicked, this,
  179. [&, label, broadcast, astart, astop]() {
  180. for (QWidget *i :
  181. ui->scrollAreaWidgetContents->findChildren<
  182. QWidget *>(
  183. QString(),
  184. Qt::FindDirectChildrenOnly)) {
  185. i->setProperty(
  186. "isSelectedEvent",
  187. "false");
  188. i->style()->unpolish(i);
  189. i->style()->polish(i);
  190. }
  191. label->setProperty("isSelectedEvent",
  192. "true");
  193. label->style()->unpolish(label);
  194. label->style()->polish(label);
  195. this->selectedBroadcast = broadcast;
  196. this->autostart = astart;
  197. this->autostop = astop;
  198. UpdateOkButtonStatus();
  199. });
  200. ui->scrollAreaWidgetContents->layout()->addWidget(
  201. label);
  202. });
  203. workerThread->start();
  204. #ifdef __APPLE__
  205. // MacOS theming issues
  206. this->resize(this->width() + 200, this->height() + 120);
  207. #endif
  208. valid = true;
  209. }
  210. OBSYoutubeActions::~OBSYoutubeActions()
  211. {
  212. workerThread->stop();
  213. workerThread->wait();
  214. delete workerThread;
  215. }
  216. void WorkerThread::run()
  217. {
  218. if (!pending)
  219. return;
  220. json11::Json broadcasts;
  221. for (QString broadcastStatus : {"active", "upcoming"}) {
  222. if (!apiYouTube->GetBroadcastsList(broadcasts, "",
  223. broadcastStatus)) {
  224. emit failed();
  225. return;
  226. }
  227. while (pending) {
  228. auto items = broadcasts["items"].array_items();
  229. for (auto item : items) {
  230. QString status = QString::fromStdString(
  231. item["status"]["lifeCycleStatus"]
  232. .string_value());
  233. if (status == "live" || status == "testing") {
  234. // Check that the attached liveStream is offline (reconnectable)
  235. QString stream_id = QString::fromStdString(
  236. item["contentDetails"]
  237. ["boundStreamId"]
  238. .string_value());
  239. json11::Json stream;
  240. if (!apiYouTube->FindStream(stream_id,
  241. stream))
  242. continue;
  243. if (stream["status"]["streamStatus"] ==
  244. "active")
  245. continue;
  246. }
  247. QString title = QString::fromStdString(
  248. item["snippet"]["title"].string_value());
  249. QString scheduledStartTime =
  250. QString::fromStdString(
  251. item["snippet"]
  252. ["scheduledStartTime"]
  253. .string_value());
  254. QString broadcast = QString::fromStdString(
  255. item["id"].string_value());
  256. // Treat already started streams as autostart for UI purposes
  257. bool astart =
  258. status == "live" ||
  259. item["contentDetails"]["enableAutoStart"]
  260. .bool_value();
  261. bool astop =
  262. item["contentDetails"]["enableAutoStop"]
  263. .bool_value();
  264. QDateTime utcDTime = QDateTime::fromString(
  265. scheduledStartTime,
  266. SchedulDateAndTimeFormat);
  267. // DateTime parser means that input datetime is a local, so we need to move it
  268. QDateTime dateTime = utcDTime.addSecs(
  269. utcDTime.offsetFromUtc());
  270. QString dateTimeString = QLocale().toString(
  271. dateTime,
  272. QString("%1 %2").arg(
  273. QLocale().dateFormat(
  274. QLocale::LongFormat),
  275. QLocale().timeFormat(
  276. QLocale::ShortFormat)));
  277. emit new_item(title, dateTimeString, broadcast,
  278. status, astart, astop);
  279. }
  280. auto nextPageToken =
  281. broadcasts["nextPageToken"].string_value();
  282. if (nextPageToken.empty() || items.empty())
  283. break;
  284. else {
  285. if (!pending)
  286. return;
  287. if (!apiYouTube->GetBroadcastsList(
  288. broadcasts,
  289. QString::fromStdString(
  290. nextPageToken),
  291. broadcastStatus)) {
  292. emit failed();
  293. return;
  294. }
  295. }
  296. }
  297. }
  298. emit ready();
  299. }
  300. void OBSYoutubeActions::UpdateOkButtonStatus()
  301. {
  302. bool enable = false;
  303. if (ui->tabWidget->currentIndex() == 0) {
  304. enable = !ui->title->text().isEmpty() &&
  305. !ui->privacyBox->currentText().isEmpty() &&
  306. (ui->yesMakeForKids->isChecked() ||
  307. ui->notMakeForKids->isChecked());
  308. ui->okButton->setEnabled(enable);
  309. ui->saveButton->setEnabled(enable);
  310. if (ui->checkScheduledLater->checkState() == Qt::Checked) {
  311. ui->okButton->setText(
  312. QTStr("YouTube.Actions.Create_Schedule"));
  313. ui->saveButton->setText(
  314. QTStr("YouTube.Actions.Create_Schedule_Ready"));
  315. } else {
  316. ui->okButton->setText(
  317. QTStr("YouTube.Actions.Create_GoLive"));
  318. ui->saveButton->setText(
  319. QTStr("YouTube.Actions.Create_Ready"));
  320. }
  321. ui->pushButton->setVisible(false);
  322. } else {
  323. enable = !selectedBroadcast.isEmpty();
  324. ui->okButton->setEnabled(enable);
  325. ui->saveButton->setEnabled(enable);
  326. ui->okButton->setText(QTStr("YouTube.Actions.Choose_GoLive"));
  327. ui->saveButton->setText(QTStr("YouTube.Actions.Choose_Ready"));
  328. ui->pushButton->setVisible(true);
  329. }
  330. }
  331. bool OBSYoutubeActions::CreateEventAction(YoutubeApiWrappers *api,
  332. StreamDescription &stream,
  333. bool stream_later,
  334. bool ready_broadcast)
  335. {
  336. YoutubeApiWrappers *apiYouTube = api;
  337. BroadcastDescription broadcast = {};
  338. UiToBroadcast(broadcast);
  339. if (stream_later) {
  340. // DateTime parser means that input datetime is a local, so we need to move it
  341. auto dateTime = ui->scheduledTime->dateTime();
  342. auto utcDTime = dateTime.addSecs(-dateTime.offsetFromUtc());
  343. broadcast.schedul_date_time =
  344. utcDTime.toString(SchedulDateAndTimeFormat);
  345. } else {
  346. // stream now is always autostart/autostop
  347. broadcast.auto_start = true;
  348. broadcast.auto_stop = true;
  349. broadcast.schedul_date_time =
  350. QDateTime::currentDateTimeUtc().toString(
  351. SchedulDateAndTimeFormat);
  352. }
  353. autostart = broadcast.auto_start;
  354. autostop = broadcast.auto_stop;
  355. blog(LOG_DEBUG, "Scheduled date and time: %s",
  356. broadcast.schedul_date_time.toStdString().c_str());
  357. if (!apiYouTube->InsertBroadcast(broadcast)) {
  358. blog(LOG_DEBUG, "No broadcast created.");
  359. return false;
  360. }
  361. if (!apiYouTube->SetVideoCategory(broadcast.id, broadcast.title,
  362. broadcast.description,
  363. broadcast.category.id)) {
  364. blog(LOG_DEBUG, "No category set.");
  365. return false;
  366. }
  367. if (!stream_later || ready_broadcast) {
  368. stream = {"", "", "OBS Studio Video Stream"};
  369. if (!apiYouTube->InsertStream(stream)) {
  370. blog(LOG_DEBUG, "No stream created.");
  371. return false;
  372. }
  373. if (!apiYouTube->BindStream(broadcast.id, stream.id)) {
  374. blog(LOG_DEBUG, "No stream binded.");
  375. return false;
  376. }
  377. if (broadcast.privacy != "private")
  378. apiYouTube->SetChatId(broadcast.id);
  379. else
  380. apiYouTube->ResetChat();
  381. }
  382. return true;
  383. }
  384. bool OBSYoutubeActions::ChooseAnEventAction(YoutubeApiWrappers *api,
  385. StreamDescription &stream)
  386. {
  387. YoutubeApiWrappers *apiYouTube = api;
  388. json11::Json json;
  389. if (!apiYouTube->FindBroadcast(selectedBroadcast, json)) {
  390. blog(LOG_DEBUG, "No broadcast found.");
  391. return false;
  392. }
  393. std::string boundStreamId =
  394. json["items"]
  395. .array_items()[0]["contentDetails"]["boundStreamId"]
  396. .string_value();
  397. std::string broadcastPrivacy =
  398. json["items"]
  399. .array_items()[0]["status"]["privacyStatus"]
  400. .string_value();
  401. stream.id = boundStreamId.c_str();
  402. if (!stream.id.isEmpty() && apiYouTube->FindStream(stream.id, json)) {
  403. auto item = json["items"].array_items()[0];
  404. auto streamName = item["cdn"]["ingestionInfo"]["streamName"]
  405. .string_value();
  406. auto title = item["snippet"]["title"].string_value();
  407. stream.name = streamName.c_str();
  408. stream.title = title.c_str();
  409. api->SetBroadcastId(selectedBroadcast);
  410. } else {
  411. stream = {"", "", "OBS Studio Video Stream"};
  412. if (!apiYouTube->InsertStream(stream)) {
  413. blog(LOG_DEBUG, "No stream created.");
  414. return false;
  415. }
  416. if (!apiYouTube->BindStream(selectedBroadcast, stream.id)) {
  417. blog(LOG_DEBUG, "No stream binded.");
  418. return false;
  419. }
  420. }
  421. if (broadcastPrivacy != "private")
  422. apiYouTube->SetChatId(selectedBroadcast);
  423. else
  424. apiYouTube->ResetChat();
  425. return true;
  426. }
  427. void OBSYoutubeActions::ShowErrorDialog(QWidget *parent, QString text)
  428. {
  429. QMessageBox dlg(parent);
  430. dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowCloseButtonHint);
  431. dlg.setWindowTitle(QTStr("YouTube.Actions.Error.Title"));
  432. dlg.setText(text);
  433. dlg.setTextFormat(Qt::RichText);
  434. dlg.setIcon(QMessageBox::Warning);
  435. dlg.setStandardButtons(QMessageBox::StandardButton::Ok);
  436. dlg.exec();
  437. }
  438. void OBSYoutubeActions::InitBroadcast()
  439. {
  440. StreamDescription stream;
  441. QMessageBox msgBox(this);
  442. msgBox.setWindowFlags(msgBox.windowFlags() &
  443. ~Qt::WindowCloseButtonHint);
  444. msgBox.setWindowTitle(QTStr("YouTube.Actions.Notify.Title"));
  445. msgBox.setText(QTStr("YouTube.Actions.Notify.CreatingBroadcast"));
  446. msgBox.setStandardButtons(QMessageBox::StandardButtons());
  447. bool success = false;
  448. auto action = [&]() {
  449. if (ui->tabWidget->currentIndex() == 0) {
  450. success = this->CreateEventAction(
  451. apiYouTube, stream,
  452. ui->checkScheduledLater->isChecked());
  453. } else {
  454. success = this->ChooseAnEventAction(apiYouTube, stream);
  455. };
  456. QMetaObject::invokeMethod(&msgBox, "accept",
  457. Qt::QueuedConnection);
  458. };
  459. QScopedPointer<QThread> thread(CreateQThread(action));
  460. thread->start();
  461. msgBox.exec();
  462. thread->wait();
  463. if (success) {
  464. if (ui->tabWidget->currentIndex() == 0) {
  465. // Stream later usecase.
  466. if (ui->checkScheduledLater->isChecked()) {
  467. QMessageBox msg(this);
  468. msg.setWindowTitle(QTStr(
  469. "YouTube.Actions.EventCreated.Title"));
  470. msg.setText(QTStr(
  471. "YouTube.Actions.EventCreated.Text"));
  472. msg.setStandardButtons(QMessageBox::Ok);
  473. msg.exec();
  474. // Close dialog without start streaming.
  475. Cancel();
  476. } else {
  477. // Stream now usecase.
  478. blog(LOG_DEBUG, "New valid stream: %s",
  479. QT_TO_UTF8(stream.name));
  480. emit ok(QT_TO_UTF8(stream.id),
  481. QT_TO_UTF8(stream.name), true, true,
  482. true);
  483. Accept();
  484. }
  485. } else {
  486. // Stream to precreated broadcast usecase.
  487. emit ok(QT_TO_UTF8(stream.id), QT_TO_UTF8(stream.name),
  488. autostart, autostop, true);
  489. Accept();
  490. }
  491. } else {
  492. // Fail.
  493. auto last_error = apiYouTube->GetLastError();
  494. if (last_error.isEmpty())
  495. last_error = QTStr("YouTube.Actions.Error.YouTubeApi");
  496. if (!apiYouTube->GetTranslatedError(last_error))
  497. last_error =
  498. QTStr("YouTube.Actions.Error.NoBroadcastCreated")
  499. .arg(last_error);
  500. ShowErrorDialog(this, last_error);
  501. }
  502. }
  503. void OBSYoutubeActions::ReadyBroadcast()
  504. {
  505. StreamDescription stream;
  506. QMessageBox msgBox(this);
  507. msgBox.setWindowFlags(msgBox.windowFlags() &
  508. ~Qt::WindowCloseButtonHint);
  509. msgBox.setWindowTitle(QTStr("YouTube.Actions.Notify.Title"));
  510. msgBox.setText(QTStr("YouTube.Actions.Notify.CreatingBroadcast"));
  511. msgBox.setStandardButtons(QMessageBox::StandardButtons());
  512. bool success = false;
  513. auto action = [&]() {
  514. if (ui->tabWidget->currentIndex() == 0) {
  515. success = this->CreateEventAction(
  516. apiYouTube, stream,
  517. ui->checkScheduledLater->isChecked(), true);
  518. } else {
  519. success = this->ChooseAnEventAction(apiYouTube, stream);
  520. };
  521. QMetaObject::invokeMethod(&msgBox, "accept",
  522. Qt::QueuedConnection);
  523. };
  524. QScopedPointer<QThread> thread(CreateQThread(action));
  525. thread->start();
  526. msgBox.exec();
  527. thread->wait();
  528. if (success) {
  529. emit ok(QT_TO_UTF8(stream.id), QT_TO_UTF8(stream.name),
  530. autostart, autostop, false);
  531. Accept();
  532. } else {
  533. // Fail.
  534. auto last_error = apiYouTube->GetLastError();
  535. if (last_error.isEmpty())
  536. last_error = QTStr("YouTube.Actions.Error.YouTubeApi");
  537. if (!apiYouTube->GetTranslatedError(last_error))
  538. last_error =
  539. QTStr("YouTube.Actions.Error.NoBroadcastCreated")
  540. .arg(last_error);
  541. ShowErrorDialog(this, last_error);
  542. }
  543. }
  544. void OBSYoutubeActions::UiToBroadcast(BroadcastDescription &broadcast)
  545. {
  546. broadcast.title = ui->title->text();
  547. // ToDo: UI warning rather than silent truncation
  548. broadcast.description = ui->description->toPlainText().left(5000);
  549. broadcast.privacy = ui->privacyBox->currentData().toString();
  550. broadcast.category.title = ui->categoryBox->currentText();
  551. broadcast.category.id = ui->categoryBox->currentData().toString();
  552. broadcast.made_for_kids = ui->yesMakeForKids->isChecked();
  553. broadcast.latency = ui->latencyBox->currentData().toString();
  554. broadcast.auto_start = ui->checkAutoStart->isChecked();
  555. broadcast.auto_stop = ui->checkAutoStop->isChecked();
  556. broadcast.dvr = ui->checkDVR->isChecked();
  557. broadcast.schedul_for_later = ui->checkScheduledLater->isChecked();
  558. broadcast.projection = ui->check360Video->isChecked() ? "360"
  559. : "rectangular";
  560. }
  561. void OBSYoutubeActions::OpenYouTubeDashboard()
  562. {
  563. ChannelDescription channel;
  564. if (!apiYouTube->GetChannelDescription(channel)) {
  565. blog(LOG_DEBUG, "Could not get channel description.");
  566. ShowErrorDialog(
  567. this,
  568. apiYouTube->GetLastError().isEmpty()
  569. ? QTStr("YouTube.Actions.Error.General")
  570. : QTStr("YouTube.Actions.Error.Text")
  571. .arg(apiYouTube->GetLastError()));
  572. return;
  573. }
  574. //https://studio.youtube.com/channel/UCA9bSfH3KL186kyiUsvi3IA/videos/live?filter=%5B%5D&sort=%7B%22columnType%22%3A%22date%22%2C%22sortOrder%22%3A%22DESCENDING%22%7D
  575. QString uri =
  576. QString("https://studio.youtube.com/channel/%1/videos/live?filter=[]&sort={\"columnType\"%3A\"date\"%2C\"sortOrder\"%3A\"DESCENDING\"}")
  577. .arg(channel.id);
  578. QDesktopServices::openUrl(uri);
  579. }
  580. void OBSYoutubeActions::Cancel()
  581. {
  582. workerThread->stop();
  583. reject();
  584. }
  585. void OBSYoutubeActions::Accept()
  586. {
  587. workerThread->stop();
  588. accept();
  589. }