UI: Use OBS locale for YouTube categories API

This commit is contained in:
derrod 2021-08-31 18:08:30 +02:00 committed by Jim
parent 1eb20ad5aa
commit a04bd742d7
3 changed files with 21 additions and 9 deletions

View File

@ -109,8 +109,7 @@ OBSYoutubeActions::OBSYoutubeActions(QWidget *parent, Auth *auth)
this->setWindowTitle(channel.title);
QVector<CategoryDescription> 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(

View File

@ -304,7 +304,6 @@ bool YoutubeApiWrappers::GetBroadcastsList(Json &json_out, const QString &page,
}
bool YoutubeApiWrappers::GetVideoCategoriesList(
const QString &country, const QString &language,
QVector<CategoryDescription> &category_list_out)
{
lastErrorMessage.clear();
@ -313,13 +312,28 @@ bool YoutubeApiWrappers::GetVideoCategoriesList(
"?part=snippet"
"&regionCode=%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()) {

View File

@ -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<CategoryDescription> &category_list_out);
GetVideoCategoriesList(QVector<CategoryDescription> &category_list_out);
bool SetVideoCategory(const QString &video_id,
const QString &video_title,
const QString &video_description,