diff --git a/UI/window-youtube-actions.cpp b/UI/window-youtube-actions.cpp index 3dbe0317c..cf792ea0b 100644 --- a/UI/window-youtube-actions.cpp +++ b/UI/window-youtube-actions.cpp @@ -109,8 +109,7 @@ OBSYoutubeActions::OBSYoutubeActions(QWidget *parent, Auth *auth) this->setWindowTitle(channel.title); QVector category_list; - if (!apiYouTube->GetVideoCategoriesList( - channel.country, channel.language, category_list)) { + if (!apiYouTube->GetVideoCategoriesList(category_list)) { blog(LOG_DEBUG, "Could not get video category for country; %s.", channel.country.toStdString().c_str()); ShowErrorDialog( diff --git a/UI/youtube-api-wrappers.cpp b/UI/youtube-api-wrappers.cpp index c32a94d99..18e9d8875 100644 --- a/UI/youtube-api-wrappers.cpp +++ b/UI/youtube-api-wrappers.cpp @@ -304,7 +304,6 @@ bool YoutubeApiWrappers::GetBroadcastsList(Json &json_out, const QString &page, } bool YoutubeApiWrappers::GetVideoCategoriesList( - const QString &country, const QString &language, QVector &category_list_out) { lastErrorMessage.clear(); @@ -313,13 +312,28 @@ bool YoutubeApiWrappers::GetVideoCategoriesList( "?part=snippet" "®ionCode=%1" "&hl=%2"; - const QString url = - url_template.arg(country.isEmpty() ? "US" : country, - language.isEmpty() ? "en" : language); + /* + * All OBS locale regions aside from "US" are missing category id 29 + * ("Nonprofits & Activism"), but it is still available to channels + * set to those regions via the YouTube Studio website. + * To work around this inconsistency with the API all locales will + * use the "US" region and only set the language part for localisation. + * It is worth noting that none of the regions available on YouTube + * feature any category not also available to the "US" region. + */ + QString url = url_template.arg("US", QLocale().name()); + Json json_out; if (!InsertCommand(QT_TO_UTF8(url), "application/json", "", nullptr, json_out)) { - return false; + if (lastErrorReason != "unsupportedLanguageCode" && + lastErrorReason != "invalidLanguage") + return false; + // Try again with en-US if YouTube error indicates an unsupported locale + url = url_template.arg("US", "en_US"); + if (!InsertCommand(QT_TO_UTF8(url), "application/json", "", + nullptr, json_out)) + return false; } category_list_out = {}; for (auto &j : json_out["items"].array_items()) { diff --git a/UI/youtube-api-wrappers.hpp b/UI/youtube-api-wrappers.hpp index 220c1af74..871ea77b8 100644 --- a/UI/youtube-api-wrappers.hpp +++ b/UI/youtube-api-wrappers.hpp @@ -68,8 +68,7 @@ public: bool GetBroadcastsList(json11::Json &json_out, const QString &page, const QString &status); bool - GetVideoCategoriesList(const QString &country, const QString &language, - QVector &category_list_out); + GetVideoCategoriesList(QVector &category_list_out); bool SetVideoCategory(const QString &video_id, const QString &video_title, const QString &video_description,