multi_embed_player 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build-and-deploy.yml +44 -0
- package/.gitmodules +3 -0
- package/CLAUDE.md +92 -0
- package/README.md +0 -24
- package/add_types.sh +61 -0
- package/browserExtention/chrome/background.js +55 -0
- package/browserExtention/chrome/extention.json +1 -0
- package/browserExtention/chrome/liteplayer.js +26439 -0
- package/browserExtention/chrome/manifest.json +31 -0
- package/browserExtention/chrome/player-selector.js +1854 -0
- package/browserExtention/firefox/background.js +27 -0
- package/browserExtention/firefox/extention.json +1 -0
- package/browserExtention/firefox/liteplayer.js +26439 -0
- package/browserExtention/firefox/manifest.json +19 -0
- package/browserExtention/firefox/player-selector.js +1854 -0
- package/documents/.hugo_build.lock +0 -0
- package/documents/archetypes/default.md +5 -0
- package/documents/assets/jsconfig.json +11 -0
- package/documents/content/docs/install.md +103 -0
- package/documents/content/docs/quickstart.md +51 -0
- package/documents/content/docs/reference/HTML.md +31 -0
- package/documents/content/docs/reference/_index.md +10 -0
- package/documents/content/docs/reference/error_code.md +23 -0
- package/documents/content/docs/reference/iframe_api.md +737 -0
- package/documents/content/docs/reference/iframe_class.md +230 -0
- package/documents/content/docs/reference/multi_embed_player_class.md +113 -0
- package/documents/content/docs/reference/reserved_words.md +71 -0
- package/documents/content/docs/usage/GDPR_mode.md +77 -0
- package/documents/content/docs/usage/_index.md +10 -0
- package/documents/content/docs/usage/custom_playlist.md +239 -0
- package/documents/content/docs/usage/embed_api.md +163 -0
- package/documents/content/docs/usage/embed_various_service.md +81 -0
- package/documents/content/docs/usage/thumbnail_click.md +57 -0
- package/documents/go.mod +8 -0
- package/documents/go.sum +14 -0
- package/documents/hugo.toml +18 -0
- package/documents/layouts/partials/docs/sidebar.html +117 -0
- package/documents/layouts/partials/landing/features.html +47 -0
- package/documents/layouts/robots.txt +4 -0
- package/documents/static/_headers +7 -0
- package/documents/static/localStorageCheck.html +27 -0
- package/documents/static/no_extention.json +1 -0
- package/example.html +27 -0
- package/extention.json +1 -0
- package/icon/video_not_found.odg +0 -0
- package/icon/video_not_found.svgz +0 -0
- package/iframe_api/bilibili.ts +1095 -0
- package/iframe_api/niconico.ts +429 -0
- package/iframe_api/soundcloud.ts +450 -0
- package/iframe_api/youtube.ts +311 -0
- package/multi_embed_player.ts +989 -0
- package/package.json +10 -41
- package/player_api_gate/bilibili-api-gate/cgi/cpp/bilibili-api-gate-cgi.cpp +281 -0
- package/player_api_gate/bilibili-api-gate/cgi/go/src.go +46 -0
- package/player_api_gate/bilibili-api-gate/cloudflare_workers/package-lock.json +1356 -0
- package/player_api_gate/bilibili-api-gate/cloudflare_workers/package.json +12 -0
- package/player_api_gate/bilibili-api-gate/cloudflare_workers/src/index.js +50 -0
- package/player_api_gate/bilibili-api-gate/cloudflare_workers/wrangler.toml +3 -0
- package/player_api_gate/iframe-api-ts/.editorconfig +12 -0
- package/player_api_gate/iframe-api-ts/.prettierrc +6 -0
- package/player_api_gate/iframe-api-ts/package-lock.json +3054 -0
- package/player_api_gate/iframe-api-ts/package.json +18 -0
- package/player_api_gate/iframe-api-ts/src/bilibili.ts +49 -0
- package/player_api_gate/iframe-api-ts/src/index.ts +35 -0
- package/player_api_gate/iframe-api-ts/src/niconico.ts +95 -0
- package/player_api_gate/iframe-api-ts/src/soundcloud.ts +38 -0
- package/player_api_gate/iframe-api-ts/src/types.ts +115 -0
- package/player_api_gate/iframe-api-ts/src/url-proxy.ts +29 -0
- package/player_api_gate/iframe-api-ts/src/utils.ts +82 -0
- package/player_api_gate/iframe-api-ts/src/youtube.ts +41 -0
- package/player_api_gate/iframe-api-ts/test/bilibili.spec.ts +47 -0
- package/player_api_gate/iframe-api-ts/test/env.d.ts +3 -0
- package/player_api_gate/iframe-api-ts/test/index.spec.ts +59 -0
- package/player_api_gate/iframe-api-ts/test/niconico.spec.ts +55 -0
- package/player_api_gate/iframe-api-ts/test/soundcloud.spec.ts +55 -0
- package/player_api_gate/iframe-api-ts/test/tsconfig.json +8 -0
- package/player_api_gate/iframe-api-ts/test/url-proxy.spec.ts +46 -0
- package/player_api_gate/iframe-api-ts/test/youtube.spec.ts +45 -0
- package/player_api_gate/iframe-api-ts/tsconfig.json +45 -0
- package/player_api_gate/iframe-api-ts/vitest.config.mts +11 -0
- package/player_api_gate/iframe-api-ts/worker-configuration.d.ts +5768 -0
- package/player_api_gate/iframe-api-ts/wrangler.jsonc +47 -0
- package/player_api_gate/iframe_api/.editorconfig +13 -0
- package/player_api_gate/iframe_api/.prettierrc +6 -0
- package/player_api_gate/iframe_api/package-lock.json +1307 -0
- package/player_api_gate/iframe_api/package.json +12 -0
- package/player_api_gate/iframe_api/src/bilibili_api.js +60 -0
- package/player_api_gate/iframe_api/src/index.js +47 -0
- package/player_api_gate/iframe_api/src/niconico_api.js +112 -0
- package/player_api_gate/iframe_api/src/soundcloud_api.js +57 -0
- package/player_api_gate/iframe_api/src/url_proxy.js +28 -0
- package/player_api_gate/iframe_api/src/youtube_api.js +44 -0
- package/player_api_gate/iframe_api/wrangler.toml +51 -0
- package/player_api_gate/niconico-imager/cgi/go/src.go +74 -0
- package/player_api_gate/niconico-imager/cloudflare_workers/package-lock.json +2175 -0
- package/player_api_gate/niconico-imager/cloudflare_workers/package.json +12 -0
- package/player_api_gate/niconico-imager/cloudflare_workers/src/index.js +78 -0
- package/player_api_gate/niconico-imager/cloudflare_workers/wrangler.toml +3 -0
- package/test_script.html +172 -0
- package/tsconfig.json +36 -0
- package/dist/iframe_api/bilibili.d.ts +0 -91
- package/dist/iframe_api/bilibili.d.ts.map +0 -1
- package/dist/iframe_api/bilibili.js +0 -451
- package/dist/iframe_api/bilibili.js.map +0 -1
- package/dist/iframe_api/index.d.ts +0 -6
- package/dist/iframe_api/index.d.ts.map +0 -1
- package/dist/iframe_api/index.js +0 -8
- package/dist/iframe_api/index.js.map +0 -1
- package/dist/iframe_api/niconico.d.ts +0 -42
- package/dist/iframe_api/niconico.d.ts.map +0 -1
- package/dist/iframe_api/niconico.js +0 -181
- package/dist/iframe_api/niconico.js.map +0 -1
- package/dist/iframe_api/soundcloud.d.ts +0 -80
- package/dist/iframe_api/soundcloud.d.ts.map +0 -1
- package/dist/iframe_api/soundcloud.js +0 -188
- package/dist/iframe_api/soundcloud.js.map +0 -1
- package/dist/iframe_api/youtube.d.ts +0 -133
- package/dist/iframe_api/youtube.d.ts.map +0 -1
- package/dist/iframe_api/youtube.js +0 -278
- package/dist/iframe_api/youtube.js.map +0 -1
- package/dist/multi_embed_player.d.ts +0 -48
- package/dist/multi_embed_player.d.ts.map +0 -1
- package/dist/multi_embed_player.js +0 -318
- package/dist/multi_embed_player.js.map +0 -1
- package/dist/types.d.ts +0 -126
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -22
- package/dist/types.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name":
|
|
3
|
-
"main":
|
|
4
|
-
"types":
|
|
5
|
-
"version": "3.0
|
|
2
|
+
"name":"multi_embed_player",
|
|
3
|
+
"main":"./dist/multi_embed_player.js",
|
|
4
|
+
"types":"./dist/multi_embed_player.d.ts",
|
|
5
|
+
"version": "3.1.0",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
-
"style":
|
|
8
|
-
"description": "
|
|
9
|
-
"keywords": [
|
|
10
|
-
"video",
|
|
11
|
-
"embed",
|
|
12
|
-
"player",
|
|
13
|
-
"youtube",
|
|
14
|
-
"bilibili",
|
|
15
|
-
"soundcloud",
|
|
16
|
-
"niconico",
|
|
17
|
-
"typescript"
|
|
18
|
-
],
|
|
19
|
-
"author": "bonjinnorenka",
|
|
20
|
-
"homepage": "https://github.com/bonjinnorenka/multi_embed_player#readme",
|
|
7
|
+
"style":"./multi_embed_player.css",
|
|
8
|
+
"description": "some video site embed and control playing",
|
|
21
9
|
"repository": {
|
|
22
10
|
"type": "git",
|
|
23
11
|
"url": "https://github.com/bonjinnorenka/multi_embed_player"
|
|
@@ -25,32 +13,13 @@
|
|
|
25
13
|
"bugs": {
|
|
26
14
|
"url": "https://github.com/bonjinnorenka/multi_embed_player/issues"
|
|
27
15
|
},
|
|
28
|
-
"files": [
|
|
29
|
-
"dist/**/*",
|
|
30
|
-
"multi_embed_player.css",
|
|
31
|
-
"README.md",
|
|
32
|
-
"LICENSE"
|
|
33
|
-
],
|
|
34
|
-
"engines": {
|
|
35
|
-
"node": ">=14.0.0"
|
|
36
|
-
},
|
|
37
|
-
"publishConfig": {
|
|
38
|
-
"access": "public"
|
|
39
|
-
},
|
|
40
16
|
"scripts": {
|
|
41
17
|
"build": "tsc",
|
|
42
|
-
"build:watch": "tsc --watch",
|
|
43
18
|
"dev": "tsc --watch",
|
|
44
|
-
"lint": "
|
|
45
|
-
"lint:fix": "
|
|
46
|
-
"prepublishOnly": "npm run build",
|
|
47
|
-
"prepack": "npm run build"
|
|
19
|
+
"lint": "tsc --noEmit",
|
|
20
|
+
"lint:fix": "tsc --noEmit"
|
|
48
21
|
},
|
|
49
22
|
"devDependencies": {
|
|
50
|
-
"typescript": "^5.0.0"
|
|
51
|
-
"@types/node": "^20.0.0",
|
|
52
|
-
"eslint": "^8.0.0",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
54
|
-
"@typescript-eslint/parser": "^6.0.0"
|
|
23
|
+
"typescript": "^5.0.0"
|
|
55
24
|
}
|
|
56
|
-
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
#include "curl/curl.h"
|
|
2
|
+
#include "json.hpp"
|
|
3
|
+
#include <iostream>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <unordered_map>
|
|
6
|
+
|
|
7
|
+
using json = nlohmann::json;
|
|
8
|
+
|
|
9
|
+
struct MemoryStructAdvance {
|
|
10
|
+
char *memory;
|
|
11
|
+
size_t size;
|
|
12
|
+
size_t reserved_size;
|
|
13
|
+
void free_memory(){
|
|
14
|
+
delete this->memory;
|
|
15
|
+
this->memory = NULL;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp){
|
|
20
|
+
MemoryStructAdvance *msp = (MemoryStructAdvance *)userp;
|
|
21
|
+
size_t realsize = size * nmemb;
|
|
22
|
+
bool memory_reserve_size_changed = false;
|
|
23
|
+
while(realsize+msp->size > msp->reserved_size){//メモリを拡大
|
|
24
|
+
memory_reserve_size_changed = true;
|
|
25
|
+
if(msp->reserved_size<=0){
|
|
26
|
+
msp->reserved_size = 1000;
|
|
27
|
+
}
|
|
28
|
+
msp->reserved_size = msp->reserved_size*2;
|
|
29
|
+
}
|
|
30
|
+
char* data_input_char;
|
|
31
|
+
if(memory_reserve_size_changed){
|
|
32
|
+
data_input_char = new char[msp->reserved_size];
|
|
33
|
+
memset(data_input_char,'\0',msp->reserved_size);
|
|
34
|
+
memcpy(data_input_char,msp->memory,msp->size);
|
|
35
|
+
delete msp->memory;
|
|
36
|
+
msp->memory = data_input_char;
|
|
37
|
+
}
|
|
38
|
+
else{
|
|
39
|
+
data_input_char = msp->memory;
|
|
40
|
+
}
|
|
41
|
+
memcpy(data_input_char+msp->size,contents,realsize);
|
|
42
|
+
msp->size += realsize;
|
|
43
|
+
return realsize;
|
|
44
|
+
}
|
|
45
|
+
MemoryStructAdvance downloadFileOnMemory(std::string url,std::vector<std::string> header={},std::string cookieFilePath="",std::string useragent=""){
|
|
46
|
+
CURL *curl_handle;
|
|
47
|
+
CURLcode res;
|
|
48
|
+
MemoryStructAdvance ms;
|
|
49
|
+
ms.reserved_size = 1000;
|
|
50
|
+
ms.size = 0;
|
|
51
|
+
ms.memory = new char[ms.reserved_size];
|
|
52
|
+
memset(ms.memory,'\0',ms.reserved_size);
|
|
53
|
+
curl_handle = curl_easy_init();
|
|
54
|
+
//オレオレ証明書対応
|
|
55
|
+
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER,0); //証明書の確認をしない
|
|
56
|
+
|
|
57
|
+
curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
|
|
58
|
+
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
|
|
59
|
+
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&ms);
|
|
60
|
+
if(useragent==(std::string)""){
|
|
61
|
+
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
|
|
62
|
+
}
|
|
63
|
+
else{
|
|
64
|
+
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, useragent.c_str());
|
|
65
|
+
}
|
|
66
|
+
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L);
|
|
67
|
+
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
|
|
68
|
+
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1L);
|
|
69
|
+
|
|
70
|
+
if(cookieFilePath!=(std::string)""){
|
|
71
|
+
curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, cookieFilePath.c_str());
|
|
72
|
+
}
|
|
73
|
+
if(header.size()!=0){
|
|
74
|
+
struct curl_slist *chunk = NULL;
|
|
75
|
+
for(int x=0;x<header.size();x++){
|
|
76
|
+
chunk = curl_slist_append(chunk, header[x].c_str());
|
|
77
|
+
}
|
|
78
|
+
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, chunk);
|
|
79
|
+
}
|
|
80
|
+
res = curl_easy_perform(curl_handle);
|
|
81
|
+
if(res != CURLE_OK) {
|
|
82
|
+
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
|
|
83
|
+
}
|
|
84
|
+
curl_easy_cleanup(curl_handle);
|
|
85
|
+
return ms;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
void return_data(json jsondata){
|
|
89
|
+
//std::cout << "Content-Type: application/json\nAccess-Control-Allow-Origin: *\ncache-control: max-age=2592000\n\n" << jsondata.dump() << std::endl;
|
|
90
|
+
std::cout << "Content-Type: application/json\n\n";
|
|
91
|
+
std::cout << jsondata.dump() << std::endl;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
typedef enum tagBASE64_TYPE {
|
|
95
|
+
BASE64_TYPE_STANDARD,
|
|
96
|
+
BASE64_TYPE_MIME,
|
|
97
|
+
BASE64_TYPE_URL
|
|
98
|
+
} BASE64_TYPE;
|
|
99
|
+
|
|
100
|
+
static const char BASE64_TABLE[] = {
|
|
101
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
|
102
|
+
};
|
|
103
|
+
static const char BASE64_TABLE_URL[] = {
|
|
104
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
|
|
105
|
+
};
|
|
106
|
+
static const int BASE64_TABLE_LENGTH = {
|
|
107
|
+
sizeof(BASE64_TABLE) / sizeof(BASE64_TABLE[0]) - 1
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
typedef struct tagBASE64_SPEC {
|
|
111
|
+
BASE64_TYPE type;
|
|
112
|
+
const char *table;
|
|
113
|
+
char pad;
|
|
114
|
+
int maxLineLength;
|
|
115
|
+
char *lineSep;
|
|
116
|
+
int lineSepLength;
|
|
117
|
+
} BASE64_SPEC;
|
|
118
|
+
static const BASE64_SPEC BASE64_SPECS[] = {
|
|
119
|
+
{ BASE64_TYPE_STANDARD, BASE64_TABLE, '=', 0, NULL, 0 },
|
|
120
|
+
{ BASE64_TYPE_MIME, BASE64_TABLE, '=', 76, "\r\n", 2 },
|
|
121
|
+
{ BASE64_TYPE_URL, BASE64_TABLE_URL, 0, 0, NULL, 0 }
|
|
122
|
+
};
|
|
123
|
+
static const size_t BASE64_SPECS_LENGTH = {
|
|
124
|
+
sizeof(BASE64_SPECS) / sizeof(BASE64_SPECS[0])
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
char *base64Encode(const char *data, const size_t size, const BASE64_TYPE type)
|
|
128
|
+
{
|
|
129
|
+
BASE64_SPEC spec;
|
|
130
|
+
size_t length;
|
|
131
|
+
char *base64;
|
|
132
|
+
char *cursor;
|
|
133
|
+
int lineLength;
|
|
134
|
+
int i;
|
|
135
|
+
int j;
|
|
136
|
+
|
|
137
|
+
if (data == NULL) {
|
|
138
|
+
return NULL;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
spec = BASE64_SPECS[0];
|
|
142
|
+
for (i = 0; i < (int)BASE64_SPECS_LENGTH; i++) {
|
|
143
|
+
if (BASE64_SPECS[i].type == type) {
|
|
144
|
+
spec = BASE64_SPECS[i];
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
length = size * 4 / 3 + 3 + 1;
|
|
150
|
+
if (spec.maxLineLength > 0) {
|
|
151
|
+
length += size / spec.maxLineLength * spec.lineSepLength;
|
|
152
|
+
}
|
|
153
|
+
//base64 = (char*)malloc(length);
|
|
154
|
+
base64 = new char[length];
|
|
155
|
+
if (base64 == NULL) {
|
|
156
|
+
return NULL;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
cursor = base64;
|
|
160
|
+
lineLength = 0;
|
|
161
|
+
for (i = 0, j = size; j > 0; i += 3, j -= 3) {
|
|
162
|
+
if (spec.maxLineLength > 0) {
|
|
163
|
+
if (lineLength >= spec.maxLineLength) {
|
|
164
|
+
char *sep;
|
|
165
|
+
|
|
166
|
+
for (sep = spec.lineSep; *sep != 0; sep++) {
|
|
167
|
+
*(cursor++) = *sep;
|
|
168
|
+
}
|
|
169
|
+
lineLength = 0;
|
|
170
|
+
}
|
|
171
|
+
lineLength += 4;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (j == 1) {
|
|
175
|
+
*(cursor++) = spec.table[(data[i + 0] >> 2 & 0x3f)];
|
|
176
|
+
*(cursor++) = spec.table[(data[i + 0] << 4 & 0x30)];
|
|
177
|
+
*(cursor++) = spec.pad;
|
|
178
|
+
*(cursor++) = spec.pad;
|
|
179
|
+
}
|
|
180
|
+
else if (j == 2) {
|
|
181
|
+
*(cursor++) = spec.table[(data[i + 0] >> 2 & 0x3f)];
|
|
182
|
+
*(cursor++) = spec.table[(data[i + 0] << 4 & 0x30) | (data[i + 1] >> 4 & 0x0f)];
|
|
183
|
+
*(cursor++) = spec.table[(data[i + 1] << 2 & 0x3c)];
|
|
184
|
+
*(cursor++) = spec.pad;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
*(cursor++) = spec.table[(data[i + 0] >> 2 & 0x3f)];
|
|
188
|
+
*(cursor++) = spec.table[(data[i + 0] << 4 & 0x30) | (data[i + 1] >> 4 & 0x0f)];
|
|
189
|
+
*(cursor++) = spec.table[(data[i + 1] << 2 & 0x3c) | (data[i + 2] >> 6 & 0x03)];
|
|
190
|
+
*(cursor++) = spec.table[(data[i + 2] << 0 & 0x3f)];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
*cursor = 0;
|
|
194
|
+
|
|
195
|
+
return base64;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
int main(){
|
|
199
|
+
json ret_js;
|
|
200
|
+
try{
|
|
201
|
+
const char* query_string = std::getenv("QUERY_STRING");
|
|
202
|
+
std::string query_string_str = query_string ? query_string : "";
|
|
203
|
+
if(query_string_str==""){
|
|
204
|
+
query_string_str = "bvid=BV1Yq4y1Z785&image_base64=1";
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// QUERY_STRINGをパースしてunordered_mapに格納する
|
|
208
|
+
std::unordered_map<std::string, std::string> params;
|
|
209
|
+
size_t pos = 0;
|
|
210
|
+
while (pos < query_string_str.size()) {
|
|
211
|
+
size_t end_pos = query_string_str.find('&', pos);
|
|
212
|
+
if (end_pos == std::string::npos) {
|
|
213
|
+
end_pos = query_string_str.size();
|
|
214
|
+
}
|
|
215
|
+
size_t sep_pos = query_string_str.find('=', pos);
|
|
216
|
+
if (sep_pos == std::string::npos || sep_pos > end_pos) {
|
|
217
|
+
sep_pos = end_pos;
|
|
218
|
+
}
|
|
219
|
+
std::string key = query_string_str.substr(pos, sep_pos - pos);
|
|
220
|
+
std::string value = "";
|
|
221
|
+
if (sep_pos < end_pos) {
|
|
222
|
+
value = query_string_str.substr(sep_pos + 1, end_pos - sep_pos - 1);
|
|
223
|
+
}
|
|
224
|
+
params[key] = value;
|
|
225
|
+
pos = end_pos + 1;
|
|
226
|
+
}
|
|
227
|
+
delete query_string;
|
|
228
|
+
if(params.count("bvid")!=1){//bvidが見つからないとき
|
|
229
|
+
ret_js["status"] = "failed";
|
|
230
|
+
ret_js["message"] = "plese set bvid in query string example ?bvid=BV1Yq4y1Z785";
|
|
231
|
+
ret_js["product_type"] = "bilibili api";
|
|
232
|
+
return_data(ret_js);
|
|
233
|
+
}
|
|
234
|
+
else{
|
|
235
|
+
std::string api_url = "https://api.bilibili.com/x/web-interface/view?bvid=" + params["bvid"];
|
|
236
|
+
//char* api_res_char = downloadFileOnMemory(api_url);
|
|
237
|
+
MemoryStructAdvance tmp_ms;
|
|
238
|
+
try{
|
|
239
|
+
tmp_ms = downloadFileOnMemory(api_url);
|
|
240
|
+
}
|
|
241
|
+
catch(...){
|
|
242
|
+
ret_js["status"] = "failed";
|
|
243
|
+
ret_js["message"] = "network access error";
|
|
244
|
+
ret_js["product_type"] = "bilibili api";
|
|
245
|
+
return_data(ret_js);
|
|
246
|
+
}
|
|
247
|
+
char* api_res_char = tmp_ms.memory;
|
|
248
|
+
std::string api_res_string = strdup(api_res_char);
|
|
249
|
+
delete api_res_char;
|
|
250
|
+
api_res_char = NULL;
|
|
251
|
+
//tmp_ms.free_memory();
|
|
252
|
+
ret_js = json::parse(api_res_string);
|
|
253
|
+
if(params.count("image_base64")==1&¶ms["image_base64"]=="1"){
|
|
254
|
+
std::string image_url = ret_js["data"]["pic"];
|
|
255
|
+
MemoryStructAdvance image_res_data_ms;
|
|
256
|
+
try{
|
|
257
|
+
image_res_data_ms = downloadFileOnMemory(image_url);
|
|
258
|
+
}
|
|
259
|
+
catch(...){
|
|
260
|
+
ret_js["status"] = "failed";
|
|
261
|
+
ret_js["message"] = "network access error";
|
|
262
|
+
ret_js["product_type"] = "bilibili api";
|
|
263
|
+
return_data(ret_js);
|
|
264
|
+
}
|
|
265
|
+
char* image_base64_char = base64Encode(image_res_data_ms.memory,image_res_data_ms.size,BASE64_TYPE_STANDARD);
|
|
266
|
+
std::string image_base64_string = image_base64_char;
|
|
267
|
+
ret_js["image_base64"] = "data:image/jpeg;base64," + image_base64_string;
|
|
268
|
+
delete image_base64_char;
|
|
269
|
+
image_base64_char = NULL;
|
|
270
|
+
image_res_data_ms.free_memory();
|
|
271
|
+
}
|
|
272
|
+
return_data(ret_js);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch(...){
|
|
276
|
+
ret_js["status"] = "failed";
|
|
277
|
+
ret_js["message"] = "internal server error";
|
|
278
|
+
ret_js["product_type"] = "bilibili api";
|
|
279
|
+
return_data(ret_js);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"encoding/base64"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"fmt"
|
|
7
|
+
"io"
|
|
8
|
+
"net/http"
|
|
9
|
+
"os"
|
|
10
|
+
"strings"
|
|
11
|
+
"unsafe"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
func main() {
|
|
15
|
+
queryString := os.Getenv("QUERY_STRING")
|
|
16
|
+
// QUERY_STRINGをパースして、値を取得
|
|
17
|
+
values := make(map[string]string)
|
|
18
|
+
pairs := strings.Split(queryString, "&")
|
|
19
|
+
for _, pair := range pairs {
|
|
20
|
+
kv := strings.Split(pair, "=")
|
|
21
|
+
if len(kv) == 2 {
|
|
22
|
+
values[kv[0]] = kv[1]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
url := "https://api.bilibili.com/x/web-interface/view?bvid=" + values["bvid"]
|
|
27
|
+
resp, _ := http.Get(url)
|
|
28
|
+
defer resp.Body.Close()
|
|
29
|
+
|
|
30
|
+
byteArray, _ := io.ReadAll(resp.Body)
|
|
31
|
+
var tmp_json interface{}
|
|
32
|
+
json.Unmarshal(byteArray, &tmp_json)
|
|
33
|
+
if val, ok := values["image_base64"]; ok {
|
|
34
|
+
if val == "1" {
|
|
35
|
+
pic_url := tmp_json.(map[string]interface{})["data"].(map[string]interface{})["pic"].(string)
|
|
36
|
+
resp, _ := http.Get(pic_url)
|
|
37
|
+
defer resp.Body.Close()
|
|
38
|
+
byteArray, _ := io.ReadAll(resp.Body)
|
|
39
|
+
base64_image := base64.StdEncoding.EncodeToString(byteArray)
|
|
40
|
+
tmp_json.(map[string]interface{})["image_base64"] = "data:image/jpeg;base64," + base64_image
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
json_st, _ := json.MarshalIndent(tmp_json, "", " ") //書き出し
|
|
44
|
+
fmt.Println("Content-Type: application/json\n\n")
|
|
45
|
+
fmt.Println(*(*string)(unsafe.Pointer(&json_st)))
|
|
46
|
+
}
|