DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
YouTubeAPI.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/// YouTubeAPI.hpp - Header for the you_tube api related stuff.
27/// Jun 30, 2021
28/// https://discordcoreapi.com
29/// \file YouTubeAPI.hpp
30#pragma once
31
35
36namespace discord_core_api {
37
38 namespace discord_core_internal {
39
40 class DiscordCoreAPI_Dll you_tube_request_builder : public https_client_core {
41 public:
42 you_tube_request_builder(config_manager* configManagerNew);
43
44 song collectFinalSong(const song& songNew);
45
46 protected:
47 static constexpr jsonifier::string_view baseUrl{ "https://www.youtube.com" };
48
49 song constructDownloadInfo(const song& songNew, uint64_t currentRecursionDepth);
50
51 jsonifier::vector<song> collectSearchResults(jsonifier::string_view string, uint64_t limit = 20);
52
53 song collectSingleResult(jsonifier::string_view string);
54
55 virtual ~you_tube_request_builder() = default;
56 };
57
58 class DiscordCoreAPI_Dll you_tube_api : public you_tube_request_builder {
59 public:
60 you_tube_api(config_manager* configManagerNew, const snowflake guildId);
61
62 co_routine<void, false> downloadAndStreamAudio(const song songNew,
63 std::coroutine_handle<co_routine<void, false>::promise_type> threadHandle = std::coroutine_handle<co_routine<void, false>::promise_type>{},
64 uint64_t currentReconnectTries = 0);
65
66 void weFailedToDownloadOrDecode(const song& songNew, std::coroutine_handle<co_routine<void, false>::promise_type> threadHandle, uint64_t recursionDepth);
67
68 jsonifier::vector<song> searchForSong(jsonifier::string_view searchQuery, uint64_t limit);
69
70 bool areWeWorking();
71
72 protected:
73 std::atomic_bool areWeWorkingBool{ false };
74 snowflake guildId{};
75 };
76
77 struct you_tube_request_client {
78 static constexpr jsonifier::string_view clientVersion{ "17.10.35" };
79 static constexpr jsonifier::string_view androidSdkVersion{ "31" };
80 static constexpr jsonifier::string_view clientName{ "android" };
81 static constexpr jsonifier::string_view platform{ "mobile" };
82 static constexpr jsonifier::string_view osName{ "android" };
83 static constexpr jsonifier::string_view osVersion{ "12" };
84 static constexpr jsonifier::string_view hl{ "en-gb" };
85 static constexpr jsonifier::string_view gl{ "us" };
86 };
87
88 struct request {
89 const bool useSsl{ true };
90 };
91
92 struct user {
93 const bool lockedSafetyMode{};
94 };
95
96 struct you_tube_request_context {
97 unordered_map<jsonifier::string, jsonifier::string> captionParams{};
98 you_tube_request_client client{};
99 request requestVal{};
100 user userVal{};
101 };
102
103 struct format {
104 jsonifier::string contentLength{};
105 jsonifier::string audioQuality{};
106 jsonifier::string mimeType{};
107 int64_t averageBitrate{};
108 jsonifier::string url{};
109 int64_t bitrate{};
110 int64_t itag{};
111 };
112
113 struct streaming_data {
114 jsonifier::vector<format> adaptiveFormats{};
115 };
116
117 struct thumbnail_element {
118 jsonifier::string url{};
119 int64_t width{};
120 };
121
122 struct video_details_thumbnail {
123 jsonifier::vector<thumbnail_element> thumbnails{};
124 };
125
126 struct video_details {
127 jsonifier::string shortDescription{};
128 video_details_thumbnail thumbnail{};
129 jsonifier::string lengthSeconds{};
130 jsonifier::string videoId{};
131 jsonifier::string title{};
132 };
133
134 struct data {
135 streaming_data streamingData{};
136 video_details videoDetails{};
137 };
138
139 struct you_tube_request {
140 const jsonifier::string playlistId{};
141 you_tube_request_context context{};
142 const bool contentCheckOk{ true };
143 const jsonifier::string params{};
144 const bool racyCheckOk{ true };
145 jsonifier::string videoId{};
146 };
147
148 struct video_renderer {
149 jsonifier::string videoId{};
150 };
151
152 struct video_renderer_type {
153 video_renderer videoRenderer{};
154 };
155
156 struct item_section_renderer_contents {
157 jsonifier::vector<discord_core_internal::video_renderer_type> contents{};
158 };
159
160 struct item_section_renderer {
161 item_section_renderer_contents itemSectionRendererContents{};
162 };
163
164 struct section_list_renderer {
165 jsonifier::vector<item_section_renderer> contents{};
166 };
167
168 struct primary_contents {
169 section_list_renderer sectionListRenderer{};
170 };
171
172 struct two_column_search_results_renderer {
173 primary_contents primaryContents{};
174 };
175
176 struct contents01 {
177 two_column_search_results_renderer twoColumnSearchResultsRenderer{};
178 };
179
180 struct you_tube_search_results {
181 contents01 contents{};
182 };
183 }
184}
The main namespace for the forward-facing interfaces.