19#include <rapidjson/document.h>
29 "mtm_campaign=Audacity&mtm_source=Audacity-{version_number}&mtm_content={button_name}"
32 L
"https://api.audio.com" };
35 L
"1741964426607541" };
38 L
"/CloudServices/AudioCom/OAuthClientSecret",
39 L
"shKqnY2sLTfRK7hztwzNEVxnmhJfOy1i"
43 L
"/CloudServices/AudioCom/OAuthRedirectURL",
44 L
"https://audio.com/auth/sign-in/success"
48 L
"/CloudServices/AudioCom/OAuthLoginPage",
49 L
"https://audio.com/audacity/link?clientId={auth_client_id}&" MTM_CAMPAIGN
53 L
"/CloudServices/AudioCom/FinishUploadPage",
54 L
"https://audio.com/audacity/upload?audioId={audio_id}&token={auth_token}&clientId={auth_client_id}&" MTM_CAMPAIGN
58 L
"https://audio.com" };
61 L
"/CloudServices/AudioCom/DownloadMimeType", L
"audio/x-wav"
66 std::initializer_list<std::pair<std::string_view, std::string_view>>
69 for (
auto& [
key, value] : substitutions)
71 auto pos = pattern.find(
key);
77 if (pattern[pos - 1] ==
'{' && pattern[pos +
key.size()] ==
'}')
78 pattern.replace(pos - 1,
key.size() + 2, value);
80 pos = pattern.find(
key, pos + 1);
84 return std::move(pattern);
94 return "Share_Audio_Button";
96 return "Share_Audio_Menu";
98 return "Share_Audio_Export_Menu";
100 return "Share_Audio_Export_Extra_Menu";
102 return "Save_to_Cloud_Menu";
104 return "Save_Project_Save_to_Cloud_Menu";
106 return "Prefs_Panel";
108 return "Project_Opened_And_Upload_Resumed";
110 return "Update_Cloud_Audio_Preview_Menu";
112 return "Link_Audiocom_Account_Help_Menu";
114 return "Open_From_Cloud_Menu";
169 std::string_view audioID, std::string_view token,
AudiocomTrace trace)
const
173 { {
"audio_id", audioID },
174 {
"auth_token", token },
181 std::string_view userSlug, std::string_view audioSlug,
185 "{frontend_url}/{user_slug}/audio/{audio_slug}/edit?" MTM_CAMPAIGN,
187 {
"user_slug", userSlug },
188 {
"audio_slug", audioSlug },
195 return std::chrono::seconds(3);
198std::vector<std::string>
202 return {
"audio/x-wavpack",
"audio/x-flac",
"audio/x-wav" };
204 return {
"audio/mpeg" };
210 if (mimeType ==
"audio/x-wavpack")
212 rapidjson::Document config;
214 config.AddMember(
"quality", rapidjson::Value(2), config.GetAllocator());
215 config.AddMember(
"bit_rate", rapidjson::Value(40), config.GetAllocator());
216 config.AddMember(
"bit_depth", 24, config.GetAllocator());
217 config.AddMember(
"hybrid_mode",
false, config.GetAllocator());
220 else if (mimeType ==
"audio/x-flac")
222 rapidjson::Document config;
225 "bit_depth", rapidjson::Value(24), config.GetAllocator());
226 config.AddMember(
"level", rapidjson::Value(5), config.GetAllocator());
228 else if (mimeType ==
"audio/x-wav")
232 else if (mimeType ==
"audio/mpeg")
234 rapidjson::Document config;
236 config.AddMember(
"mode", rapidjson::Value(
"VBR"), config.GetAllocator());
237 config.AddMember(
"quality", rapidjson::Value(5), config.GetAllocator());
241 throw std::invalid_argument(
"unknown mime-type");
253 if (language.Contains(L
"-") && language.Length() > 2)
254 return wxString::Format(
255 "%s;q=1.0, %s;q=0.7, *;q=0.5", language, language.Left(2))
258 return wxString::Format(
"%s;q=1.0, *;q=0.5", language).ToStdString();
270 "{api_url}/project/{project_id}/snapshot",
271 { {
"api_url",
mApiEndpoint }, {
"project_id", projectId } });
275 std::string_view projectId, std::string_view snapshotId)
const
278 "{api_url}/project/{project_id}/snapshot/{snapshot_id}/sync",
280 {
"project_id", projectId },
281 {
"snapshot_id", snapshotId } });
285 int page,
int pageSize, std::string_view searchTerm)
const
287 if (searchTerm.empty())
289 "{api_url}/project?page={page}&per-page={page_size}",
291 {
"page", std::to_string(page) },
292 {
"page_size", std::to_string(pageSize) }, });
295 "{api_url}/project?page={page}&per-page={page_size}&q={search_term}",
297 {
"page", std::to_string(page) },
298 {
"page_size", std::to_string(pageSize) },
299 {
"search_term", searchTerm }, });
305 "{api_url}/project/{project_id}", {
307 {
"project_id", projectId },
312 std::string_view projectId, std::string_view snapshotId)
const
315 "{api_url}/project/{project_id}/snapshot/{snapshot_id}?expand=blocks,file_url",
318 {
"project_id", projectId },
319 {
"snapshot_id", snapshotId },
324 std::string_view projectId, std::string_view snapshotId)
const
327 "{api_url}/project/{project_id}/snapshot/{snapshot_id}",
330 {
"project_id", projectId },
331 {
"snapshot_id", snapshotId },
338 "{api_url}/project/{project_id}/network-stats",
341 {
"project_id", projectId },
346 std::string_view userId, std::string_view projectId,
350 "{frontend_url}/{user_slug}/projects/{project_id}?" MTM_CAMPAIGN,
353 {
"user_slug", userId },
354 {
"project_id", projectId },
367 {
"user_slug", userId },
Declare functions to perform UTF-8 to std::wstring conversions.
@ LinkAudiocomAccountHelpMenu
@ UpdateCloudAudioPreviewMenu
@ SaveProjectSaveToCloudMenu
@ ShareAudioExportExtraMenu
@ ProjectOpenedAndUploadResumed
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
Specialization of Setting for strings.
Configuration for the audio.com.
std::string GetOAuthLoginPage(AudiocomTrace) const
Page to open in browser to initiate OAuth.
std::string GetProjectsUrl(int page, int pageSize, std::string_view searchTerm) const
std::vector< std::string > GetPreferredAudioFormats(bool preferLossless=true) const
Preferred audio format.
std::string mOAuthLoginPage
std::string GetNetworkStatsUrl(std::string_view projectId) const
std::string GetAudioURL(std::string_view userSlug, std::string_view audioSlug, AudiocomTrace) const
Helper to construct the page URL for the authorised upload.
std::string GetProjectsPageUrl(std::string_view userId, AudiocomTrace) const
std::string GetOAuthRedirectURL() const
OAuth2 redirect URL. Only used to satisfy the protocol.
std::string GetFinishUploadPage(std::string_view audioID, std::string_view token, AudiocomTrace) const
Helper to construct the page URL for the anonymous upload last stage.
std::string mOAuthRedirectURL
std::string GetCreateSnapshotUrl(std::string_view projectId) const
std::string GetCreateProjectUrl() const
std::string GetOAuthClientSecret() const
OAuth2 client secret.
std::string GetAPIEndpoint() const
API endpoint.
std::string mFinishUploadPage
std::string mOAuthClientSecret
rapidjson::Document GetExportConfig(const std::string &exporterName) const
Export configuration suitable for the mime type provided.
std::string GetSnapshotInfoUrl(std::string_view projectId, std::string_view snapshotId) const
std::chrono::milliseconds GetProgressCallbackTimeout() const
Timeout between progress callbacks.
std::string GetDownloadMime() const
std::string GetAPIUrl(std::string_view apiURI) const
Helper to construct the full URLs for the API.
std::string GetDeleteSnapshotUrl(std::string_view projectId, std::string_view snapshotId) const
std::string GetProjectInfoUrl(std::string_view projectId) const
std::string mPreferredMimeType
std::string GetAcceptLanguageValue() const
Returns the preferred language.
std::string mOAuthClientID
std::string GetSnapshotSyncUrl(std::string_view projectId, std::string_view snapshotId) const
std::string GetProjectPageUrl(std::string_view userId, std::string_view projectId, AudiocomTrace) const
std::string GetOAuthClientID() const
OAuth2 client ID.
constexpr size_t npos(-1)
StringSetting audioComFrontendUrl
StringSetting audioComOAuthClientID
std::string Substitute(std::string pattern, std::initializer_list< std::pair< std::string_view, std::string_view > > substitutions)
StringSetting audioComOAuthClientSecret
StringSetting audioComAudioDownloadMimeType
StringSetting audioComFinishUploadPage
StringSetting audioComOAuthLoginPage
StringSetting audioComApiEndpoint
StringSetting audioComOAuthRedirectURL
std::string GetButtonName(AudiocomTrace trace)
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.
std::string ToUTF8(const std::wstring &wstr)