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 jsonifier::vector<song> collectPlaylist(jsonifier::string_view string);
57
58 song collectSingleResult(jsonifier::string_view string);
59
60 jsonifier::string collectClientId();
61
62 virtual ~sound_cloud_request_builder() = default;
63 };
64
65 class DiscordCoreAPI_Dll sound_cloud_api : public sound_cloud_request_builder {
66 public:
67 sound_cloud_api(config_manager* configManagerNew, const snowflake guildId);
68
69 co_routine<void, false> downloadAndStreamAudio(const song songNew,
70 std::coroutine_handle<co_routine<void, false>::promise_type> threadHandle = std::coroutine_handle<co_routine<void, false>::promise_type>{},
71 uint64_t currentReconnectTries = 0);
72
73 void weFailedToDownloadOrDecode(const song& songNew, std::coroutine_handle<co_routine<void, false>::promise_type> threadHandle, uint64_t recursionDepth);
74
75 jsonifier::vector<song> searchForSong(jsonifier::string_view searchQuery, uint64_t limit);
76
77 bool areWeWorking();
78
79 protected:
80 std::atomic_bool areWeWorkingBool{ false };
81 snowflake guildId{};
82 };
83
84 enum class search_type { single_song_with_id = 0, single_song_without_id = 1, playlist = 2 };
85
86 struct transcoding {
87 jsonifier::string preset{};
88 jsonifier::string url{};
89 };
90
91 struct second_download_url {
92 jsonifier::string url{};
93 };
94
95 struct media {
96 std::vector<transcoding> transcodings{};
97 };
98
99 struct raw_sound_cloud_song {
100 jsonifier::string trackAuthorization{};
101 jsonifier::string description{};
102 jsonifier::string artworkUrl{};
103 jsonifier::string viewUrl{};
104 jsonifier::string title{};
105 uint64_t duration{};
106 media mediaVal{};
107 };
108
109 struct sound_cloud_search_results {
110 jsonifier::vector<raw_sound_cloud_song> collection{};
111 };
112
113 struct data_class {
114 jsonifier::string trackAuthorization{};
115 jsonifier::string description{};
116 jsonifier::string artworkUrl{};
117 jsonifier::string avatarUrl{};
118 jsonifier::string viewUrl{};
119 jsonifier::string title{};
120 int64_t duration{};
121 media mediaVal{};
122 };
123
124 struct welcome_element {
125 jsonifier::raw_json_data data{};
126 jsonifier::string hydratable{};
127 };
128
129 struct welcome {
130 std::vector<welcome_element> data{};
131 };
132 };
133};
The main namespace for the forward-facing interfaces.