@finch_ren/x-scraper 0.1.3 → 0.1.5
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/dist/src/utils/api.d.ts +5 -5
- package/dist/src/utils/api.js +68 -13
- package/package.json +1 -1
package/dist/src/utils/api.d.ts
CHANGED
|
@@ -11,15 +11,15 @@ export declare const getKwargs: (flag: {
|
|
|
11
11
|
export declare const errorCheck: <T>(data: T | undefined, error: i.ErrorResponse[] | undefined) => T;
|
|
12
12
|
export declare const instructionToEntry: (item: i.InstructionUnion[]) => i.TimelineAddEntry[];
|
|
13
13
|
export declare const instructionConverter: (item: i.InstructionUnion[]) => TweetApiUtilsData[];
|
|
14
|
-
export declare const tweetEntriesConverter: (item: i.TimelineAddEntry[]) => TweetApiUtilsData[];
|
|
15
|
-
export declare const moduleConverter: (item: i.ModuleItem[]) => TweetApiUtilsData[];
|
|
14
|
+
export declare const tweetEntriesConverter: (item: i.TimelineAddEntry[] | any) => TweetApiUtilsData[];
|
|
15
|
+
export declare const moduleConverter: (item: i.ModuleItem[] | any) => TweetApiUtilsData[];
|
|
16
16
|
type buildTweetApiUtilsArgs = {
|
|
17
|
-
result: i.ItemResult;
|
|
17
|
+
result: i.ItemResult | any;
|
|
18
18
|
promotedMetadata?: any;
|
|
19
|
-
reply?: i.TimelineTweet
|
|
19
|
+
reply?: Array<i.TimelineTweet | any>;
|
|
20
20
|
};
|
|
21
21
|
export declare const buildTweetApiUtils: (args: buildTweetApiUtilsArgs) => TweetApiUtilsData | undefined;
|
|
22
|
-
export declare const tweetResultsConverter: (tweetResults: i.ItemResult) => i.Tweet | undefined;
|
|
22
|
+
export declare const tweetResultsConverter: (tweetResults: i.ItemResult | any) => i.Tweet | undefined;
|
|
23
23
|
export declare const userOrNullConverter: (userResults: i.UserUnion) => i.User | undefined;
|
|
24
24
|
export declare const userEntriesConverter: (item: i.TimelineAddEntry[]) => i.UserResults[];
|
|
25
25
|
export declare const userResultConverter: (user: i.UserResults[]) => UserApiUtilsData[];
|
package/dist/src/utils/api.js
CHANGED
|
@@ -90,8 +90,44 @@ const instructionConverter = (item) => {
|
|
|
90
90
|
.flat();
|
|
91
91
|
};
|
|
92
92
|
exports.instructionConverter = instructionConverter;
|
|
93
|
+
const isTimelineAddEntry = (value) => {
|
|
94
|
+
return value != undefined && typeof value == 'object' && 'content' in value && 'entryId' in value;
|
|
95
|
+
};
|
|
96
|
+
const isInstructionLike = (value) => {
|
|
97
|
+
return value != undefined && typeof value == 'object' && typeof value.type == 'string';
|
|
98
|
+
};
|
|
99
|
+
const normalizeTimelineEntries = (value) => {
|
|
100
|
+
if (value == undefined)
|
|
101
|
+
return [];
|
|
102
|
+
if (Array.isArray(value)) {
|
|
103
|
+
if (value.length == 0)
|
|
104
|
+
return [];
|
|
105
|
+
if (value.every(isTimelineAddEntry)) {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
if (value.every(isInstructionLike)) {
|
|
109
|
+
return (0, exports.instructionToEntry)(value);
|
|
110
|
+
}
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
if (typeof value != 'object')
|
|
114
|
+
return [];
|
|
115
|
+
if (Array.isArray(value.instructions)) {
|
|
116
|
+
return (0, exports.instructionToEntry)(value.instructions);
|
|
117
|
+
}
|
|
118
|
+
if (Array.isArray(value.entries)) {
|
|
119
|
+
return value.entries;
|
|
120
|
+
}
|
|
121
|
+
if (value.entry != undefined) {
|
|
122
|
+
return [value.entry];
|
|
123
|
+
}
|
|
124
|
+
if (isTimelineAddEntry(value)) {
|
|
125
|
+
return [value];
|
|
126
|
+
}
|
|
127
|
+
return [];
|
|
128
|
+
};
|
|
93
129
|
const tweetEntriesConverter = (item) => {
|
|
94
|
-
return item
|
|
130
|
+
return normalizeTimelineEntries(item)
|
|
95
131
|
.map((e) => {
|
|
96
132
|
if (e.content.entryType == i.ContentEntryType.TimelineTimelineItem) {
|
|
97
133
|
const item = e.content.itemContent;
|
|
@@ -100,8 +136,8 @@ const tweetEntriesConverter = (item) => {
|
|
|
100
136
|
return undefined;
|
|
101
137
|
return [
|
|
102
138
|
(0, exports.buildTweetApiUtils)({
|
|
103
|
-
result: timeline
|
|
104
|
-
promotedMetadata: timeline
|
|
139
|
+
result: getTimelineTweetResult(timeline),
|
|
140
|
+
promotedMetadata: getTimelinePromotedMetadata(timeline),
|
|
105
141
|
}),
|
|
106
142
|
];
|
|
107
143
|
}
|
|
@@ -117,16 +153,16 @@ const tweetEntriesConverter = (item) => {
|
|
|
117
153
|
};
|
|
118
154
|
exports.tweetEntriesConverter = tweetEntriesConverter;
|
|
119
155
|
const moduleConverter = (item) => {
|
|
120
|
-
const timelineList = item
|
|
121
|
-
.filter((e) => e
|
|
156
|
+
const timelineList = (item ?? [])
|
|
157
|
+
.filter((e) => e?.item?.itemContent?.itemType == i.ContentItemType.TimelineTweet)
|
|
122
158
|
.map((e) => e.item.itemContent);
|
|
123
159
|
if (timelineList.length == 0)
|
|
124
160
|
return [];
|
|
125
161
|
if (timelineList[0].tweetDisplayType == i.TimelineTweetTweetDisplayTypeEnum.MediaGrid) {
|
|
126
162
|
return timelineList
|
|
127
163
|
.map((e) => (0, exports.buildTweetApiUtils)({
|
|
128
|
-
result: e
|
|
129
|
-
promotedMetadata: e
|
|
164
|
+
result: getTimelineTweetResult(e),
|
|
165
|
+
promotedMetadata: getTimelinePromotedMetadata(e),
|
|
130
166
|
}))
|
|
131
167
|
.filter((e) => e != undefined);
|
|
132
168
|
}
|
|
@@ -134,26 +170,43 @@ const moduleConverter = (item) => {
|
|
|
134
170
|
const timeline = timelineList[0];
|
|
135
171
|
return [
|
|
136
172
|
(0, exports.buildTweetApiUtils)({
|
|
137
|
-
result: timeline
|
|
138
|
-
promotedMetadata: timeline
|
|
173
|
+
result: getTimelineTweetResult(timeline),
|
|
174
|
+
promotedMetadata: getTimelinePromotedMetadata(timeline),
|
|
139
175
|
reply: timelineList.slice(1),
|
|
140
176
|
}),
|
|
141
177
|
].filter((e) => e != undefined);
|
|
142
178
|
}
|
|
143
179
|
};
|
|
144
180
|
exports.moduleConverter = moduleConverter;
|
|
181
|
+
const getTimelineTweetResult = (timeline) => {
|
|
182
|
+
return timeline?.tweetResults ?? timeline?.tweet_results;
|
|
183
|
+
};
|
|
184
|
+
const getTimelinePromotedMetadata = (timeline) => {
|
|
185
|
+
return timeline?.promotedMetadata ?? timeline?.promoted_metadata;
|
|
186
|
+
};
|
|
187
|
+
const getTweetUserResult = (tweet) => {
|
|
188
|
+
return tweet?.core?.userResults?.result ?? tweet?.core?.user_results?.result;
|
|
189
|
+
};
|
|
190
|
+
const getQuotedStatusResult = (tweet) => {
|
|
191
|
+
return tweet?.quotedStatusResult ?? tweet?.quoted_status_result;
|
|
192
|
+
};
|
|
193
|
+
const getRetweetedStatusResult = (tweet) => {
|
|
194
|
+
return tweet?.legacy?.retweetedStatusResult ?? tweet?.legacy?.retweeted_status_result;
|
|
195
|
+
};
|
|
145
196
|
const buildTweetApiUtils = (args) => {
|
|
197
|
+
if (args.result == undefined)
|
|
198
|
+
return undefined;
|
|
146
199
|
const tweet = (0, exports.tweetResultsConverter)(args.result);
|
|
147
200
|
if (tweet == undefined)
|
|
148
201
|
return undefined;
|
|
149
|
-
const result = tweet
|
|
202
|
+
const result = getTweetUserResult(tweet);
|
|
150
203
|
const user = result && (0, exports.userOrNullConverter)(result);
|
|
151
204
|
if (user == undefined)
|
|
152
205
|
return undefined;
|
|
153
|
-
const quoted = tweet
|
|
154
|
-
const retweeted = tweet
|
|
206
|
+
const quoted = getQuotedStatusResult(tweet);
|
|
207
|
+
const retweeted = getRetweetedStatusResult(tweet);
|
|
155
208
|
const reply = args.reply
|
|
156
|
-
?.map((e) => (0, exports.buildTweetApiUtils)({ result: e
|
|
209
|
+
?.map((e) => (0, exports.buildTweetApiUtils)({ result: getTimelineTweetResult(e), promotedMetadata: getTimelinePromotedMetadata(e) }))
|
|
157
210
|
.filter((e) => e != undefined) ?? [];
|
|
158
211
|
return {
|
|
159
212
|
raw: args.result,
|
|
@@ -167,6 +220,8 @@ const buildTweetApiUtils = (args) => {
|
|
|
167
220
|
};
|
|
168
221
|
exports.buildTweetApiUtils = buildTweetApiUtils;
|
|
169
222
|
const tweetResultsConverter = (tweetResults) => {
|
|
223
|
+
if (tweetResults == undefined)
|
|
224
|
+
return undefined;
|
|
170
225
|
if (tweetResults.result == undefined)
|
|
171
226
|
return undefined;
|
|
172
227
|
switch (tweetResults.result.typename) {
|