@qwen-code/arena-agent 0.0.9-dev.28 → 0.0.9-dev.29
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/.env.example +2 -2
- package/README.md +8 -6
- package/dist/code-tools.js +6 -3
- package/dist/code-tools.js.map +1 -1
- package/dist/config.d.ts +14 -0
- package/dist/config.js +41 -0
- package/dist/config.js.map +1 -1
- package/dist/image.d.ts +2 -0
- package/dist/image.js +67 -1
- package/dist/image.js.map +1 -1
- package/dist/model-router-media.d.ts +7 -2
- package/dist/model-router-media.js +92 -127
- package/dist/model-router-media.js.map +1 -1
- package/dist/provider.js +7 -3
- package/dist/provider.js.map +1 -1
- package/dist/tools.js +18 -54
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
- package/dist/audit.d.ts +0 -14
- package/dist/audit.js +0 -31
- package/dist/audit.js.map +0 -1
- package/dist/dashscope.d.ts +0 -5
- package/dist/dashscope.js +0 -55
- package/dist/dashscope.js.map +0 -1
- package/dist/fetch-page/aparat.d.ts +0 -30
- package/dist/fetch-page/aparat.js +0 -209
- package/dist/fetch-page/aparat.js.map +0 -1
- package/dist/fetch-page/json-path.d.ts +0 -12
- package/dist/fetch-page/json-path.js +0 -111
- package/dist/fetch-page/json-path.js.map +0 -1
- package/dist/fetch-page/sites.d.ts +0 -26
- package/dist/fetch-page/sites.js +0 -39
- package/dist/fetch-page/sites.js.map +0 -1
- package/dist/fetch-page/text.d.ts +0 -5
- package/dist/fetch-page/text.js +0 -38
- package/dist/fetch-page/text.js.map +0 -1
- package/dist/fetch-page/types.d.ts +0 -17
- package/dist/fetch-page/types.js +0 -3
- package/dist/fetch-page/types.js.map +0 -1
- package/dist/fetch-page/youtube.d.ts +0 -35
- package/dist/fetch-page/youtube.js +0 -282
- package/dist/fetch-page/youtube.js.map +0 -1
- package/dist/web-search.d.ts +0 -5
- package/dist/web-search.js +0 -465
- package/dist/web-search.js.map +0 -1
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { jsonObject, recordArray, recordValue, stringField } from "./json-path.js";
|
|
2
|
-
import { normalizeMarkdown, requireReadableContent } from "./text.js";
|
|
3
|
-
export function matchAparat(url, hostname) {
|
|
4
|
-
if (hostname !== "aparat.com")
|
|
5
|
-
return undefined;
|
|
6
|
-
const match = url.pathname.match(/^\/([^/]+?)(?:\/(about|short-videos|videos))?\/?$/);
|
|
7
|
-
const username = match?.[1] || "";
|
|
8
|
-
if (!username || ["etc", "video", "v", "login"].includes(username)) {
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
return { kind: "aparat", username, tab: match?.[2] || "home" };
|
|
12
|
-
}
|
|
13
|
-
export function aparatShellReason(html) {
|
|
14
|
-
return /enable javascript/i.test(html) ||
|
|
15
|
-
/جاوا\s*اسکریپت[^<]{0,80}فعال/i.test(html)
|
|
16
|
-
? "requires JavaScript"
|
|
17
|
-
: undefined;
|
|
18
|
-
}
|
|
19
|
-
function aparatProfile(value) {
|
|
20
|
-
const legacyProfile = recordValue(value.profile);
|
|
21
|
-
const data = recordValue(value.data);
|
|
22
|
-
const attributes = recordValue(data?.attributes);
|
|
23
|
-
const fields = attributes || legacyProfile;
|
|
24
|
-
if (!fields)
|
|
25
|
-
return undefined;
|
|
26
|
-
return {
|
|
27
|
-
id: stringField(data || fields, "id") || stringField(fields, "userid"),
|
|
28
|
-
name: stringField(fields, "name"),
|
|
29
|
-
avatar: stringField(fields, "pic_m") || stringField(fields, "pic_b"),
|
|
30
|
-
followers: stringField(fields, "follower_cnt").trim(),
|
|
31
|
-
videoCount: stringField(fields, "video_cnt").trim(),
|
|
32
|
-
totalVisit: stringField(fields, "video_visit").trim() ||
|
|
33
|
-
stringField(fields, "total_visit").trim(),
|
|
34
|
-
description: stringField(fields, "description") || stringField(fields, "descr"),
|
|
35
|
-
startDate: stringField(fields, "start_date_jalali"),
|
|
36
|
-
monthVisit: stringField(fields, "month_visit").trim(),
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function mergeAparatAbout(profile, value) {
|
|
40
|
-
const meta = recordValue(value?.meta);
|
|
41
|
-
const data = recordValue(meta?.data);
|
|
42
|
-
if (!data)
|
|
43
|
-
return profile;
|
|
44
|
-
return {
|
|
45
|
-
...profile,
|
|
46
|
-
description: stringField(data, "description") || profile.description,
|
|
47
|
-
videoCount: stringField(data, "video_cnt").trim() || profile.videoCount,
|
|
48
|
-
totalVisit: stringField(data, "total_visit").trim() || profile.totalVisit,
|
|
49
|
-
startDate: stringField(data, "start_date_jalali") || profile.startDate,
|
|
50
|
-
monthVisit: stringField(data, "month_visit").trim() || profile.monthVisit,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function aparatVideos(value) {
|
|
54
|
-
if (!value)
|
|
55
|
-
return [];
|
|
56
|
-
const legacy = recordArray(value.videobyuser);
|
|
57
|
-
if (legacy.length)
|
|
58
|
-
return legacy;
|
|
59
|
-
return recordArray(value.included).flatMap((item) => {
|
|
60
|
-
if (item.type !== "Video")
|
|
61
|
-
return [];
|
|
62
|
-
const attributes = recordValue(item.attributes);
|
|
63
|
-
return attributes ? [attributes] : [];
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function aparatShorts(value) {
|
|
67
|
-
const data = recordValue(value?.data);
|
|
68
|
-
return recordArray(data?.posts);
|
|
69
|
-
}
|
|
70
|
-
export function aparatPage(target, profile, finalUrl, videos = [], shorts = []) {
|
|
71
|
-
const name = profile.name || target.username;
|
|
72
|
-
const root = `https://www.aparat.com/${encodeURIComponent(target.username)}`;
|
|
73
|
-
const lines = [
|
|
74
|
-
...(profile.avatar ? [``] : []),
|
|
75
|
-
"",
|
|
76
|
-
`## ${name}`,
|
|
77
|
-
"",
|
|
78
|
-
"دنبال کردن",
|
|
79
|
-
...(profile.followers ? ["", `${profile.followers} دنبالکننده`] : []),
|
|
80
|
-
...(profile.totalVisit ? ["", `${profile.totalVisit} بازدید کل`] : []),
|
|
81
|
-
"",
|
|
82
|
-
`- [خانه](${root})`,
|
|
83
|
-
`- [ویدیوها](${root}/videos)`,
|
|
84
|
-
`- [ویدیوهای کوتاه](${root}/short-videos)`,
|
|
85
|
-
`- [لیستهای پخش](${root}/playlists)`,
|
|
86
|
-
`- [درباره کانال](${root}/about)`,
|
|
87
|
-
];
|
|
88
|
-
if (target.tab === "about") {
|
|
89
|
-
lines.push("", "درباره کانال", "", profile.description);
|
|
90
|
-
if (profile.totalVisit)
|
|
91
|
-
lines.push("", `بازدید کل${profile.totalVisit}`);
|
|
92
|
-
if (profile.startDate)
|
|
93
|
-
lines.push("", `شروع فعالیت${profile.startDate}`);
|
|
94
|
-
if (profile.monthVisit)
|
|
95
|
-
lines.push("", `بازدید این ماه${profile.monthVisit}`);
|
|
96
|
-
if (profile.videoCount)
|
|
97
|
-
lines.push("", `تعداد ویدیو${profile.videoCount}`);
|
|
98
|
-
}
|
|
99
|
-
if (target.tab === "short-videos") {
|
|
100
|
-
lines.push("", "همه ویدیوهای کوتاه", "", "- تازهترین", "- پربازدید ترین");
|
|
101
|
-
for (const short of shorts) {
|
|
102
|
-
const title = stringField(short, "description") || "ویدیوی کوتاه";
|
|
103
|
-
const id = stringField(short, "id");
|
|
104
|
-
const cover = recordValue(short.cover);
|
|
105
|
-
const stats = recordValue(short.stats);
|
|
106
|
-
const poster = stringField(cover || {}, "cdn_link");
|
|
107
|
-
const views = stringField(stats || {}, "views");
|
|
108
|
-
if (!id)
|
|
109
|
-
continue;
|
|
110
|
-
const shortUrl = `https://aparat.com/shorts/${id}`;
|
|
111
|
-
if (poster) {
|
|
112
|
-
lines.push("", `[\\\\`, `\\\\`, `${views}](${shortUrl})`);
|
|
113
|
-
}
|
|
114
|
-
lines.push("", `[${title}](${shortUrl})`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (target.tab === "videos") {
|
|
118
|
-
lines.push("", "همه ویدیوها");
|
|
119
|
-
for (const video of videos) {
|
|
120
|
-
const videoTitle = stringField(video, "title");
|
|
121
|
-
const uid = stringField(video, "uid");
|
|
122
|
-
const poster = stringField(video, "big_poster") || stringField(video, "small_poster");
|
|
123
|
-
if (!videoTitle || !uid)
|
|
124
|
-
continue;
|
|
125
|
-
if (poster)
|
|
126
|
-
lines.push("", ``);
|
|
127
|
-
lines.push(`- [${videoTitle}](https://www.aparat.com/v/${uid})`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (target.tab === "home") {
|
|
131
|
-
if (!videos.length && profile.videoCount === "0") {
|
|
132
|
-
lines.push("", "", "", "### این کانال محتوایی ندارد!", "", "هنوز هیچ ویدیویی در این کانال منتشر نشده است.");
|
|
133
|
-
}
|
|
134
|
-
else if (videos.length) {
|
|
135
|
-
lines.push("", "آخرین ویدیوها");
|
|
136
|
-
for (const video of videos) {
|
|
137
|
-
const videoTitle = stringField(video, "title");
|
|
138
|
-
const uid = stringField(video, "uid");
|
|
139
|
-
const poster = stringField(video, "big_poster") || stringField(video, "small_poster");
|
|
140
|
-
if (!videoTitle || !uid)
|
|
141
|
-
continue;
|
|
142
|
-
if (poster)
|
|
143
|
-
lines.push("", ``);
|
|
144
|
-
lines.push(`[${videoTitle}](https://www.aparat.com/v/${uid})`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
finalUrl,
|
|
150
|
-
contentType: "text/html",
|
|
151
|
-
markdown: requireReadableContent(normalizeMarkdown(lines.join("\n"))),
|
|
152
|
-
title: `آپارات | ${name}`,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
export async function loadAparat(target, ctx) {
|
|
156
|
-
try {
|
|
157
|
-
const username = encodeURIComponent(target.username);
|
|
158
|
-
let profilePayload;
|
|
159
|
-
try {
|
|
160
|
-
const profileResponse = await ctx.download(`https://www.aparat.com/api/fa/v1/user/user/information/username/${username}`);
|
|
161
|
-
profilePayload = jsonObject(profileResponse.bytes, profileResponse.contentType);
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
ctx.throwIfAborted();
|
|
165
|
-
const profileResponse = await ctx.download(`https://www.aparat.com/etc/api/profile/username/${username}`);
|
|
166
|
-
profilePayload = jsonObject(profileResponse.bytes, profileResponse.contentType);
|
|
167
|
-
}
|
|
168
|
-
let profile = aparatProfile(profilePayload);
|
|
169
|
-
if (!profile)
|
|
170
|
-
return undefined;
|
|
171
|
-
let videos = [];
|
|
172
|
-
let shorts = [];
|
|
173
|
-
try {
|
|
174
|
-
if (target.tab === "about") {
|
|
175
|
-
const response = await ctx.download(`https://www.aparat.com/api/fa/v1/user/user/about/username/${username}`);
|
|
176
|
-
profile = mergeAparatAbout(profile, jsonObject(response.bytes, response.contentType));
|
|
177
|
-
}
|
|
178
|
-
else if (target.tab === "short-videos" && profile.id) {
|
|
179
|
-
const response = await ctx.download(`https://shorts.aparat.com/api/v1/web/profile/${encodeURIComponent(profile.id)}/posts`);
|
|
180
|
-
shorts = aparatShorts(jsonObject(response.bytes, response.contentType));
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
const endpoint = target.tab === "home"
|
|
184
|
-
? `user/user/profilehome_v2/username/${username}`
|
|
185
|
-
: `user/video/list/username/${username}`;
|
|
186
|
-
const response = await ctx.download(`https://www.aparat.com/api/fa/v1/${endpoint}`);
|
|
187
|
-
videos = aparatVideos(jsonObject(response.bytes, response.contentType));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
catch {
|
|
191
|
-
ctx.throwIfAborted();
|
|
192
|
-
if (target.tab === "videos") {
|
|
193
|
-
try {
|
|
194
|
-
const response = await ctx.download(`https://www.aparat.com/etc/api/videoByUser/username/${username}/perpage/10`);
|
|
195
|
-
videos = aparatVideos(jsonObject(response.bytes, response.contentType));
|
|
196
|
-
}
|
|
197
|
-
catch {
|
|
198
|
-
ctx.throwIfAborted();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return aparatPage(target, profile, ctx.finalUrl, videos, shorts);
|
|
203
|
-
}
|
|
204
|
-
catch {
|
|
205
|
-
ctx.throwIfAborted();
|
|
206
|
-
return undefined;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
//# sourceMappingURL=aparat.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aparat.js","sourceRoot":"","sources":["../../src/fetch-page/aparat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAkBtE,MAAM,UAAU,WAAW,CAAC,GAAQ,EAAE,QAAgB;IACpD,IAAI,QAAQ,KAAK,YAAY;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAC9B,mDAAmD,CACpD,CAAC;IACF,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAClC,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC;QAClC,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5C,CAAC,CAAC,qBAAqB;QACvB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAcD,SAAS,aAAa,CAAC,KAA8B;IACnD,MAAM,aAAa,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO,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CAAC;QAAC,MAAM,CAAC;YACP,GAAG,CAAC,cAAc,EAAE,CAAC;YACrB,IAAI,MAAM,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAC5B,IAAI,CAAC;oBACH,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CACjC,uDAAuD,QAAQ,aAAa,CAC7E,CAAC;oBACF,MAAM,GAAG,YAAY,CACnB,UAAU,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,CACjD,CAAC;gBACJ,CAAC;gBAAC,MAAM,CAAC;oBACP,GAAG,CAAC,cAAc,EAAE,CAAC;gBACvB,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,UAAU,CACf,MAAM,EACN,OAAO,EACP,GAAG,CAAC,QAAQ,EACZ,MAAM,EACN,MAAM,CACP,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,GAAG,CAAC,cAAc,EAAE,CAAC;QACrB,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Navigation helpers for the undocumented JSON blobs embedded in dynamic site
|
|
3
|
-
* pages. Every accessor is total: a missing or wrongly typed field yields an
|
|
4
|
-
* empty value rather than throwing, because these shapes change without notice.
|
|
5
|
-
*/
|
|
6
|
-
export declare function jsonObject(bytes: Uint8Array, contentType: string): Record<string, unknown>;
|
|
7
|
-
export declare function stringField(value: Record<string, unknown>, key: string): string;
|
|
8
|
-
export declare function recordValue(value: unknown): Record<string, unknown> | undefined;
|
|
9
|
-
export declare function recordArray(value: unknown): Record<string, unknown>[];
|
|
10
|
-
export declare function findNestedValue(value: unknown, key: string): unknown;
|
|
11
|
-
export declare function findNestedRecord(value: unknown, predicate: (record: Record<string, unknown>) => boolean): Record<string, unknown> | undefined;
|
|
12
|
-
export declare function extractAssignedJson(html: string, marker: string): Record<string, unknown> | undefined;
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { decodeText } from "./text.js";
|
|
2
|
-
/**
|
|
3
|
-
* Navigation helpers for the undocumented JSON blobs embedded in dynamic site
|
|
4
|
-
* pages. Every accessor is total: a missing or wrongly typed field yields an
|
|
5
|
-
* empty value rather than throwing, because these shapes change without notice.
|
|
6
|
-
*/
|
|
7
|
-
export function jsonObject(bytes, contentType) {
|
|
8
|
-
const value = JSON.parse(decodeText(bytes, contentType));
|
|
9
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
10
|
-
throw new Error("site adapter returned invalid JSON");
|
|
11
|
-
}
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
export function stringField(value, key) {
|
|
15
|
-
const field = value[key];
|
|
16
|
-
return typeof field === "string" || typeof field === "number"
|
|
17
|
-
? String(field)
|
|
18
|
-
: "";
|
|
19
|
-
}
|
|
20
|
-
export function recordValue(value) {
|
|
21
|
-
return value && typeof value === "object" && !Array.isArray(value)
|
|
22
|
-
? value
|
|
23
|
-
: undefined;
|
|
24
|
-
}
|
|
25
|
-
export function recordArray(value) {
|
|
26
|
-
return Array.isArray(value)
|
|
27
|
-
? value.flatMap((item) => {
|
|
28
|
-
const record = recordValue(item);
|
|
29
|
-
return record ? [record] : [];
|
|
30
|
-
})
|
|
31
|
-
: [];
|
|
32
|
-
}
|
|
33
|
-
export function findNestedValue(value, key) {
|
|
34
|
-
const record = recordValue(value);
|
|
35
|
-
if (!record)
|
|
36
|
-
return undefined;
|
|
37
|
-
if (Object.hasOwn(record, key))
|
|
38
|
-
return record[key];
|
|
39
|
-
for (const child of Object.values(record)) {
|
|
40
|
-
if (Array.isArray(child)) {
|
|
41
|
-
for (const item of child) {
|
|
42
|
-
const found = findNestedValue(item, key);
|
|
43
|
-
if (found !== undefined)
|
|
44
|
-
return found;
|
|
45
|
-
}
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
const found = findNestedValue(child, key);
|
|
49
|
-
if (found !== undefined)
|
|
50
|
-
return found;
|
|
51
|
-
}
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
export function findNestedRecord(value, predicate) {
|
|
55
|
-
const record = recordValue(value);
|
|
56
|
-
if (!record)
|
|
57
|
-
return undefined;
|
|
58
|
-
if (predicate(record))
|
|
59
|
-
return record;
|
|
60
|
-
for (const child of Object.values(record)) {
|
|
61
|
-
if (Array.isArray(child)) {
|
|
62
|
-
for (const item of child) {
|
|
63
|
-
const found = findNestedRecord(item, predicate);
|
|
64
|
-
if (found)
|
|
65
|
-
return found;
|
|
66
|
-
}
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const found = findNestedRecord(child, predicate);
|
|
70
|
-
if (found)
|
|
71
|
-
return found;
|
|
72
|
-
}
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
export function extractAssignedJson(html, marker) {
|
|
76
|
-
const markerIndex = html.indexOf(marker);
|
|
77
|
-
if (markerIndex < 0)
|
|
78
|
-
return undefined;
|
|
79
|
-
const start = html.indexOf("{", markerIndex + marker.length);
|
|
80
|
-
if (start < 0)
|
|
81
|
-
return undefined;
|
|
82
|
-
let depth = 0;
|
|
83
|
-
let inString = false;
|
|
84
|
-
let escaped = false;
|
|
85
|
-
for (let index = start; index < html.length; index += 1) {
|
|
86
|
-
const character = html[index];
|
|
87
|
-
if (inString) {
|
|
88
|
-
if (escaped)
|
|
89
|
-
escaped = false;
|
|
90
|
-
else if (character === "\\")
|
|
91
|
-
escaped = true;
|
|
92
|
-
else if (character === '"')
|
|
93
|
-
inString = false;
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (character === '"')
|
|
97
|
-
inString = true;
|
|
98
|
-
else if (character === "{")
|
|
99
|
-
depth += 1;
|
|
100
|
-
else if (character === "}" && --depth === 0) {
|
|
101
|
-
try {
|
|
102
|
-
return recordValue(JSON.parse(html.slice(start, index + 1)));
|
|
103
|
-
}
|
|
104
|
-
catch {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=json-path.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-path.js","sourceRoot":"","sources":["../../src/fetch-page/json-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;GAIG;AAEH,MAAM,UAAU,UAAU,CAAC,KAAiB,EAAE,WAAmB;IAC/D,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;IAClE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAA8B,EAAE,GAAW;IACrE,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;QAC3D,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QACf,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAChE,CAAC,CAAE,KAAiC;QACpC,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;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,KAAK,CAAC;YAC7C,SAAS;QACX,CAAC;QACD,IAAI,SAAS,KAAK,GAAG;YAAE,QAAQ,GAAG,IAAI,CAAC;aAClC,IAAI,SAAS,KAAK,GAAG;YAAE,KAAK,IAAI,CAAC,CAAC;aAClC,IAAI,SAAS,KAAK,GAAG,IAAI,EAAE,KAAK,KAAK,CAAC,EAAE,CAAC;YAC5C,IAAI,CAAC;gBACH,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/D,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type AparatTarget } from "./aparat.js";
|
|
2
|
-
import type { ParsedPage, SiteAdapterContext } from "./types.js";
|
|
3
|
-
import { type YoutubeTarget } from "./youtube.js";
|
|
4
|
-
/**
|
|
5
|
-
* Site-adapter seam.
|
|
6
|
-
*
|
|
7
|
-
* The core `fetch_page` contract — seven fields, the 8,000 UTF-16 window, the
|
|
8
|
-
* error envelope, the post-redirect URL — is graded [G] against the golden
|
|
9
|
-
* corpus and must not drift. Everything reachable from here is [H]: a local
|
|
10
|
-
* choice about pages the generic extractor cannot read, built on undocumented
|
|
11
|
-
* site internals that change without notice. Keeping the two apart is what
|
|
12
|
-
* makes the distinction auditable rather than a matter of reading 1,600 lines.
|
|
13
|
-
*/
|
|
14
|
-
export type DynamicSiteTarget = YoutubeTarget | AparatTarget;
|
|
15
|
-
export declare function dynamicSiteTarget(value: string): DynamicSiteTarget | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* Why the page cannot be read generically, when the site served a shell instead
|
|
18
|
-
* of content. Absent means the HTML is worth extracting normally.
|
|
19
|
-
*/
|
|
20
|
-
export declare function dynamicShellReason(html: string, target: DynamicSiteTarget | undefined): string | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* Returns an adapted page, or undefined to fall through to generic extraction.
|
|
23
|
-
* Throws when the page is a shell no adapter could recover, so an unreadable
|
|
24
|
-
* response never reports success.
|
|
25
|
-
*/
|
|
26
|
-
export declare function loadDynamicSite(target: DynamicSiteTarget, ctx: SiteAdapterContext): Promise<ParsedPage | undefined>;
|
package/dist/fetch-page/sites.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { aparatShellReason, loadAparat, matchAparat, } from "./aparat.js";
|
|
2
|
-
import { loadYoutube, matchYoutube, youtubeShellReason, } from "./youtube.js";
|
|
3
|
-
export function dynamicSiteTarget(value) {
|
|
4
|
-
const url = new URL(value);
|
|
5
|
-
const hostname = url.hostname.toLowerCase().replace(/^www\./, "");
|
|
6
|
-
return matchYoutube(url, hostname) || matchAparat(url, hostname);
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Why the page cannot be read generically, when the site served a shell instead
|
|
10
|
-
* of content. Absent means the HTML is worth extracting normally.
|
|
11
|
-
*/
|
|
12
|
-
export function dynamicShellReason(html, target) {
|
|
13
|
-
if (!target)
|
|
14
|
-
return undefined;
|
|
15
|
-
return target.kind === "youtube"
|
|
16
|
-
? youtubeShellReason(html)
|
|
17
|
-
: aparatShellReason(html);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Returns an adapted page, or undefined to fall through to generic extraction.
|
|
21
|
-
* Throws when the page is a shell no adapter could recover, so an unreadable
|
|
22
|
-
* response never reports success.
|
|
23
|
-
*/
|
|
24
|
-
export async function loadDynamicSite(target, ctx) {
|
|
25
|
-
const shellReason = dynamicShellReason(ctx.html, target);
|
|
26
|
-
// YouTube runs unconditionally: even a healthy watch page hides its metadata
|
|
27
|
-
// in embedded JSON. Aparat only runs once its shell has been detected.
|
|
28
|
-
if (target.kind !== "youtube" && !shellReason)
|
|
29
|
-
return undefined;
|
|
30
|
-
const adapted = target.kind === "youtube"
|
|
31
|
-
? await loadYoutube(target, ctx)
|
|
32
|
-
: await loadAparat(target, ctx);
|
|
33
|
-
if (adapted)
|
|
34
|
-
return adapted;
|
|
35
|
-
if (shellReason)
|
|
36
|
-
throw new Error(`Failed to fetch page: ${shellReason}`);
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=sites.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sites.js","sourceRoot":"","sources":["../../src/fetch-page/sites.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,UAAU,EACV,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,WAAW,EACX,YAAY,EAEZ,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAetB,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3B,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAClE,OAAO,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,WAAW,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AACnE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,MAAqC;IAErC,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,OAAO,MAAM,CAAC,IAAI,KAAK,SAAS;QAC9B,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC;QAC1B,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAyB,EACzB,GAAuB;IAEvB,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACzD,6EAA6E;IAC7E,uEAAuE;IACvE,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,WAAW;QAAE,OAAO,SAAS,CAAC;IAChE,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,KAAK,SAAS;QACvC,CAAC,CAAC,MAAM,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC;QAChC,CAAC,CAAC,MAAM,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,IAAI,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,WAAW,EAAE,CAAC,CAAC;IACzE,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/** Text helpers shared by the fetch_page core and its site adapters. */
|
|
2
|
-
export declare function decodeText(bytes: Uint8Array, contentType: string): string;
|
|
3
|
-
export declare function normalizeMarkdown(value: string): string;
|
|
4
|
-
export declare function decodeHtmlEntities(value: string): string;
|
|
5
|
-
export declare function requireReadableContent(markdown: string): string;
|
package/dist/fetch-page/text.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { parseHTML } from "linkedom";
|
|
2
|
-
/** Text helpers shared by the fetch_page core and its site adapters. */
|
|
3
|
-
export function decodeText(bytes, contentType) {
|
|
4
|
-
const charset = contentType.match(/charset\s*=\s*["']?([^;"'\s]+)/i)?.[1];
|
|
5
|
-
try {
|
|
6
|
-
return new TextDecoder(charset || "utf-8").decode(bytes);
|
|
7
|
-
}
|
|
8
|
-
catch {
|
|
9
|
-
return new TextDecoder("utf-8").decode(bytes);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export function normalizeMarkdown(value) {
|
|
13
|
-
return value
|
|
14
|
-
.replace(/\r\n?/g, "\n")
|
|
15
|
-
.replace(/[ \t]+\n/g, "\n")
|
|
16
|
-
.replace(/\n{4,}/g, "\n\n\n")
|
|
17
|
-
.trim();
|
|
18
|
-
}
|
|
19
|
-
let htmlEntityDecoder;
|
|
20
|
-
export function decodeHtmlEntities(value) {
|
|
21
|
-
if (!value.includes("&"))
|
|
22
|
-
return value;
|
|
23
|
-
if (!htmlEntityDecoder) {
|
|
24
|
-
const { document } = parseHTML("<html><body><span></span></body></html>");
|
|
25
|
-
htmlEntityDecoder = document.querySelector("span") || undefined;
|
|
26
|
-
}
|
|
27
|
-
if (!htmlEntityDecoder)
|
|
28
|
-
return value;
|
|
29
|
-
htmlEntityDecoder.innerHTML = value;
|
|
30
|
-
return htmlEntityDecoder.textContent || "";
|
|
31
|
-
}
|
|
32
|
-
export function requireReadableContent(markdown) {
|
|
33
|
-
if (!markdown.trim()) {
|
|
34
|
-
throw new Error("Failed to fetch page: no readable content");
|
|
35
|
-
}
|
|
36
|
-
return markdown;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=text.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/fetch-page/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,wEAAwE;AAExE,MAAM,UAAU,UAAU,CAAC,KAAiB,EAAE,WAAmB;IAC/D,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,iCAAiC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1E,IAAI,CAAC;QACH,OAAO,IAAI,WAAW,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,KAAK;SACT,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC;SACvB,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC;SAC1B,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC;SAC5B,IAAI,EAAE,CAAC;AACZ,CAAC;AAED,IAAI,iBAAsC,CAAC;AAE3C,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,yCAAyC,CAAC,CAAC;QAC1E,iBAAiB,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC;IAClE,CAAC;IACD,IAAI,CAAC,iBAAiB;QAAE,OAAO,KAAK,CAAC;IACrC,iBAAiB,CAAC,SAAS,GAAG,KAAK,CAAC;IACpC,OAAO,iBAAiB,CAAC,WAAW,IAAI,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** Shapes shared across the `fetch_page` modules. */
|
|
2
|
-
export interface ParsedPage {
|
|
3
|
-
finalUrl: string;
|
|
4
|
-
contentType: string;
|
|
5
|
-
markdown: string;
|
|
6
|
-
title?: string;
|
|
7
|
-
totalPages?: number;
|
|
8
|
-
pagesParsed?: number;
|
|
9
|
-
truncated?: boolean;
|
|
10
|
-
warning?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface DownloadedPage {
|
|
13
|
-
bytes: Uint8Array;
|
|
14
|
-
contentType: string;
|
|
15
|
-
finalUrl: string;
|
|
16
|
-
status: number;
|
|
17
|
-
}
|
package/dist/fetch-page/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/fetch-page/types.ts"],"names":[],"mappings":"AAAA,qDAAqD"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { ParsedPage, SiteAdapterContext } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* YouTube adapter.
|
|
4
|
-
*
|
|
5
|
-
* The watch page carries structured metadata the generic HTML extractor cannot
|
|
6
|
-
* see, so this adapter runs even on a healthy page rather than only on the bot
|
|
7
|
-
* shell. Everything it reads comes from the live response; nothing observed in
|
|
8
|
-
* the source history is hardcoded. Per the golden spec this is an [H] local
|
|
9
|
-
* choice, not a behavior the corpus proves the source tool implemented.
|
|
10
|
-
*/
|
|
11
|
-
export interface YoutubeTarget {
|
|
12
|
-
kind: "youtube";
|
|
13
|
-
canonicalUrl: string;
|
|
14
|
-
videoId: string;
|
|
15
|
-
}
|
|
16
|
-
export declare function matchYoutube(url: URL, hostname: string): YoutubeTarget | undefined;
|
|
17
|
-
export declare function youtubeShellReason(html: string): string | undefined;
|
|
18
|
-
interface YoutubeMetadata {
|
|
19
|
-
title: string;
|
|
20
|
-
thumbnail: string;
|
|
21
|
-
thumbnailWidth: string;
|
|
22
|
-
thumbnailHeight: string;
|
|
23
|
-
author: string;
|
|
24
|
-
authorUrl: string;
|
|
25
|
-
uploadedAt: string;
|
|
26
|
-
length: string;
|
|
27
|
-
views: string;
|
|
28
|
-
likes: string;
|
|
29
|
-
category: string;
|
|
30
|
-
description: string;
|
|
31
|
-
transcript: string;
|
|
32
|
-
}
|
|
33
|
-
export declare function youtubePage(target: YoutubeTarget, metadata: YoutubeMetadata): ParsedPage | undefined;
|
|
34
|
-
export declare function loadYoutube(target: YoutubeTarget, ctx: SiteAdapterContext): Promise<ParsedPage | undefined>;
|
|
35
|
-
export {};
|