DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
SoundCloudAPI.hpp
Go to the documentation of this file.
1/*
2 MIT License
3
4 DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines.
5
6 Copyright 2022, 2023 Chris M. (RealTimeChris)
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25*/
26/// SoundCloudAPI.hpp - Header for the SoundCloud api related stuff.
27/// Aug 25, 2021
28/// https://discordcoreapi.com
29/// \file SoundCloudAPI.hpp
30#pragma once
31
35
36namespace discord_core_api {
37
38 namespace discord_core_internal {
39
40 class DiscordCoreAPI_Dll sound_cloud_request_builder : public https_client_core {
41 public:
42 sound_cloud_request_builder(config_manager* configManagerNew);
43
44 song collectFinalSong(const song& songNew);
45
46 protected:
47 static jsonifier::string clientId;
48 static constexpr jsonifier::string_view baseUrl02{ "https://api-v2.soundcloud.com" };
49 static constexpr jsonifier::string_view baseUrl{ "https://soundcloud.com" };
50 static constexpr jsonifier::string_view appVersion{ "1681464840" };
51
52 jsonifier::vector<song> collectSearchResults(jsonifier::string_view songQuery, uint64_t limit = 20);
53
54 song constructDownloadInfo(const song& songNew, uint64_t currentRecursionDepth);
55
56 song collectSingleResult(jsonifier::string_view string);
57
58 jsonifier::string collectClientId();
59
60 virtual ~sound_cloud_request_builder() = default;
61 };
62
63 class DiscordCoreAPI_Dll sound_cloud_api : public sound_cloud_request_builder {
64 public:
65 sound_cloud_api(config_manager* configManagerNew, const snowflake guildId);
66
67 co_routine<void, false> downloadAndStreamAudio(const song songNew,
68 std::coroutine_handle<co_routine<void, false>::promise_type> threadHandle = std::coroutine_handle<co_routine<void, false>::promise_type>{},
69 uint64_t currentReconnectTries = 0);
70
71 void weFailedToDownloadOrDecode(const song& songNew, std::coroutine_handle<co_routine<void, false>::promise_type> threadHandle, uint64_t recursionDepth);
72
73 jsonifier::vector<song> searchForSong(jsonifier::string_view searchQuery, uint64_t limit);
74
75 bool areWeWorking();
76
77 protected:
78 std::atomic_bool areWeWorkingBool{ false };
79 snowflake guildId{};
80 };
81
82 struct transcoding {
83 jsonifier::string preset{};
84 jsonifier::string url{};
85 };
86
87 struct media {
88 jsonifier::vector<transcoding> transcodings{};
89 };
90
91 struct second_download_url {
92 jsonifier::string url{};
93 };
94
95 struct raw_sound_cloud_song {
96 jsonifier::string trackAuthorization{};
97 jsonifier::string description{};
98 jsonifier::string artworkUrl{};
99 jsonifier::string viewUrl{};
100 jsonifier::string title{};
101 uint64_t duration{};
102 media mediaVal{};
103 };
104
105 struct sound_cloud_search_results {
106 jsonifier::vector<raw_sound_cloud_song> collection{};
107 };
108
109 struct visual {
110 jsonifier::string visualUrl{};
111 int64_t entryTime{};
112 jsonifier::string urn{};
113 };
114
115 struct data_class {
116 discord_core_api::discord_core_internal::media media{};
117 jsonifier::string trackAuthorization{};
118 jsonifier::string description{};
119 jsonifier::string artworkUrl{};
120 jsonifier::string avatarUrl{};
121 jsonifier::string viewUrl{};
122 jsonifier::string title{};
123 int64_t duration{};
124 jsonifier::string url{};
125 int64_t id{};
126 };
127
128 struct welcome_element {
129 jsonifier::string hydratable{};
130 data_class data{};
131 };
132
133 struct final_data {
134 jsonifier::vector<welcome_element> data{};
135 };
136 };
137}
The main namespace for the forward-facing interfaces.