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
"/CloudServices/AudioCom/AuthWithRedirectURL",
59 L
"https://audio.com/auth/check-and-redirect"
63 L
"https://audio.com" };
66 L
"/CloudServices/AudioCom/DownloadMimeType", L
"audio/x-wav"
71 std::initializer_list<std::pair<std::string_view, std::string_view>>
74 for (
auto& [
key, value] : substitutions)
76 auto pos = pattern.find(
key);
82 if (pattern[pos - 1] ==
'{' && pattern[pos +
key.size()] ==
'}')
83 pattern.replace(pos - 1,
key.size() + 2, value);
85 pos = pattern.find(
key, pos + 1);
89 return std::move(pattern);
99 return "Share_Audio_Button";
101 return "Share_Audio_Menu";
103 return "Share_Audio_Export_Menu";
105 return "Share_Audio_Export_Extra_Menu";
107 return "Save_to_Cloud_Menu";
109 return "Save_Project_Save_to_Cloud_Menu";
111 return "Prefs_Panel";
113 return "Project_Opened_And_Upload_Resumed";
115 return "Update_Cloud_Audio_Preview_Menu";
117 return "Link_Audiocom_Account_Help_Menu";
119 return "Open_From_Cloud_Menu";
180 std::string_view audioID, std::string_view token,
AudiocomTrace trace)
const
184 { {
"audio_id", audioID },
185 {
"auth_token", token },
192 std::string_view userSlug, std::string_view audioSlug,
196 "{frontend_url}/{user_slug}/audio/{audio_slug}/edit?" MTM_CAMPAIGN,
198 {
"user_slug", userSlug },
199 {
"audio_slug", audioSlug },
206 return std::chrono::seconds(3);
209std::vector<std::string>
213 return {
"audio/x-wavpack",
"audio/x-flac",
"audio/x-wav" };
215 return {
"audio/mpeg" };
221 if (mimeType ==
"audio/x-wavpack")
223 rapidjson::Document config;
225 config.AddMember(
"quality", rapidjson::Value(2), config.GetAllocator());
226 config.AddMember(
"bit_rate", rapidjson::Value(40), config.GetAllocator());
227 config.AddMember(
"bit_depth", 24, config.GetAllocator());
228 config.AddMember(
"hybrid_mode",
false, config.GetAllocator());
231 else if (mimeType ==
"audio/x-flac")
233 rapidjson::Document config;
236 "bit_depth", rapidjson::Value(24), config.GetAllocator());
237 config.AddMember(
"level", rapidjson::Value(5), config.GetAllocator());
239 else if (mimeType ==
"audio/x-wav")
243 else if (mimeType ==
"audio/mpeg")
245 rapidjson::Document config;
247 config.AddMember(
"mode", rapidjson::Value(
"VBR"), config.GetAllocator());
248 config.AddMember(
"quality", rapidjson::Value(5), config.GetAllocator());
252 throw std::invalid_argument(
"unknown mime-type");
264 if (language.Contains(L
"-") && language.Length() > 2)
265 return wxString::Format(
266 "%s;q=1.0, %s;q=0.7, *;q=0.5", language, language.Left(2))
269 return wxString::Format(
"%s;q=1.0, *;q=0.5", language).ToStdString();
281 "{api_url}/project/{project_id}/snapshot",
282 { {
"api_url",
mApiEndpoint }, {
"project_id", projectId } });
286 std::string_view projectId, std::string_view snapshotId)
const
289 "{api_url}/project/{project_id}/snapshot/{snapshot_id}/sync",
291 {
"project_id", projectId },
292 {
"snapshot_id", snapshotId } });
296 int page,
int pageSize, std::string_view searchTerm)
const
298 if (searchTerm.empty())
300 "{api_url}/project?page={page}&per-page={page_size}",
302 {
"page", std::to_string(page) },
303 {
"page_size", std::to_string(pageSize) }, });
306 "{api_url}/project?page={page}&per-page={page_size}&q={search_term}",
308 {
"page", std::to_string(page) },
309 {
"page_size", std::to_string(pageSize) },
310 {
"search_term", searchTerm }, });
316 "{api_url}/project/{project_id}", {
318 {
"project_id", projectId },
323 std::string_view projectId, std::string_view snapshotId)
const
326 "{api_url}/project/{project_id}/snapshot/{snapshot_id}?expand=blocks,file_url",
329 {
"project_id", projectId },
330 {
"snapshot_id", snapshotId },
335 std::string_view projectId, std::string_view snapshotId)
const
338 "{api_url}/project/{project_id}/snapshot/{snapshot_id}",
341 {
"project_id", projectId },
342 {
"snapshot_id", snapshotId },
349 "{api_url}/project/{project_id}/network-stats",
352 {
"project_id", projectId },
357 std::string_view userSlug, std::string_view projectSlug,
363 {
"user_slug", userSlug },
364 {
"project_slug", projectSlug },
376 {
"user_slug", userSlug },
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 GetOAuthRedirectURL() const
OAuth2 redirect URL. Only used to satisfy the protocol.
std::string GetProjectsPagePath(std::string_view userSlug, AudiocomTrace) const
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 GetProjectPagePath(std::string_view userSlug, std::string_view projectSlug, AudiocomTrace) 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 GetAuthWithRedirectURL() const
Audio.com authorization API to automatically login current user.
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 GetOAuthClientID() const
OAuth2 client ID.
std::string mAuthWithRedirectURL
constexpr size_t npos(-1)
StringSetting audioComAuthWithRedirectURL
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 audioComFrontendURL
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)