18#include <rapidjson/document.h>
28 L
"https://api.audio.com" };
31 L
"1741964426607541" };
34 L
"/CloudServices/AudioCom/OAuthClientSecret",
35 L
"shKqnY2sLTfRK7hztwzNEVxnmhJfOy1i"
39 L
"/CloudServices/AudioCom/OAuthRedirectURL",
40 L
"https://audio.com/auth/sign-in/success"
44 L
"/CloudServices/AudioCom/OAuthLoginPage",
45 L
"https://audio.com/audacity/link?clientId={auth_client_id}"
49 L
"/CloudServices/AudioCom/FinishUploadPage",
50 L
"https://audio.com/audacity/upload?audioId={audio_id}&token={auth_token}&clientId={auth_client_id}"
54 L
"https://audio.com" };
57 L
"/CloudServices/AudioCom/DownloadMimeType", L
"audio/x-wav"
62 std::initializer_list<std::pair<std::string_view, std::string_view>>
65 for (
auto& [
key, value] : substitutions)
67 auto pos = pattern.find(
key);
73 if (pattern[pos - 1] ==
'{' && pattern[pos +
key.size()] ==
'}')
74 pattern.replace(pos - 1,
key.size() + 2, value);
76 pos = pattern.find(
key, pos + 1);
80 return std::move(pattern);
129 std::string_view audioID, std::string_view token)
const
133 {
"auth_token", token },
138 std::string_view userSlug, std::string_view audioSlug)
const
141 "{frontend_url}/{user_slug}/audio/{audio_slug}/edit",
143 {
"user_slug", userSlug },
144 {
"audio_slug", audioSlug } });
149 return std::chrono::seconds(3);
152std::vector<std::string>
156 return {
"audio/x-wavpack",
"audio/x-flac",
"audio/x-wav" };
158 return {
"audio/mpeg" };
164 if (mimeType ==
"audio/x-wavpack")
166 rapidjson::Document config;
168 config.AddMember(
"quality", rapidjson::Value(2), config.GetAllocator());
169 config.AddMember(
"bit_rate", rapidjson::Value(40), config.GetAllocator());
170 config.AddMember(
"bit_depth", 24, config.GetAllocator());
171 config.AddMember(
"hybrid_mode",
false, config.GetAllocator());
174 else if (mimeType ==
"audio/x-flac")
176 rapidjson::Document config;
179 "bit_depth", rapidjson::Value(24), config.GetAllocator());
180 config.AddMember(
"level", rapidjson::Value(5), config.GetAllocator());
182 else if (mimeType ==
"audio/x-wav")
186 else if (mimeType ==
"audio/mpeg")
188 rapidjson::Document config;
190 config.AddMember(
"mode", rapidjson::Value(
"VBR"), config.GetAllocator());
191 config.AddMember(
"quality", rapidjson::Value(5), config.GetAllocator());
195 throw std::invalid_argument(
"unknown mime-type");
207 if (language.Contains(L
"-") && language.Length() > 2)
208 return wxString::Format(
209 "%s;q=1.0, %s;q=0.7, *;q=0.5", language, language.Left(2))
212 return wxString::Format(
"%s;q=1.0, *;q=0.5", language).ToStdString();
224 "{api_url}/project/{project_id}/snapshot",
225 { {
"api_url",
mApiEndpoint }, {
"project_id", projectId } });
229 std::string_view projectId, std::string_view snapshotId)
const
232 "{api_url}/project/{project_id}/snapshot/{snapshot_id}/sync",
234 {
"project_id", projectId },
235 {
"snapshot_id", snapshotId } });
239 int page,
int pageSize, std::string_view searchTerm)
const
241 if (searchTerm.empty())
243 "{api_url}/project?page={page}&per-page={page_size}",
245 {
"page", std::to_string(page) },
246 {
"page_size", std::to_string(pageSize) }, });
249 "{api_url}/project?page={page}&per-page={page_size}&q={search_term}",
251 {
"page", std::to_string(page) },
252 {
"page_size", std::to_string(pageSize) },
253 {
"search_term", searchTerm }, });
259 "{api_url}/project/{project_id}", {
261 {
"project_id", projectId },
266 std::string_view projectId, std::string_view snapshotId)
const
269 "{api_url}/project/{project_id}/snapshot/{snapshot_id}?expand=blocks,file_url",
272 {
"project_id", projectId },
273 {
"snapshot_id", snapshotId },
278 std::string_view projectId, std::string_view snapshotId)
const
281 "{api_url}/project/{project_id}/snapshot/{snapshot_id}",
284 {
"project_id", projectId },
285 {
"snapshot_id", snapshotId },
292 "{api_url}/project/{project_id}/network-stats",
295 {
"project_id", projectId },
300 std::string_view userId, std::string_view projectId)
const
303 "{frontend_url}/{user_slug}/projects/{project_id}",
306 {
"user_slug", userId },
307 {
"project_id", projectId },
314 "{frontend_url}/{user_slug}/projects",
317 {
"user_slug", userId },
Declare functions to perform UTF-8 to std::wstring conversions.
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 GetProjectsUrl(int page, int pageSize, std::string_view searchTerm) const
std::string GetProjectPageUrl(std::string_view userId, std::string_view projectId) const
std::vector< std::string > GetPreferredAudioFormats(bool preferLossless=true) const
Preferred audio format.
std::string GetOAuthLoginPage() const
Page to open in browser to initiate OAuth.
std::string mOAuthLoginPage
std::string GetNetworkStatsUrl(std::string_view projectId) const
std::string GetOAuthRedirectURL() const
OAuth2 redirect URL. Only used to satisfy the protocol.
std::string mOAuthRedirectURL
std::string GetCreateSnapshotUrl(std::string_view projectId) const
std::string GetCreateProjectUrl() const
std::string GetFinishUploadPage(std::string_view audioID, std::string_view token) const
Helper to construct the page URL for the anonymous upload last stage.
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 GetProjectsPageUrl(std::string_view userId) const
std::string GetAudioURL(std::string_view userSlug, std::string_view audioSlug) const
Helper to construct the page URL for the authorised upload.
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.
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
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.
std::string ToUTF8(const std::wstring &wstr)