@finch_ren/x-scraper 0.1.2 → 0.1.4
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 +3 -3
- package/dist/src/utils/api.js +32 -12
- package/package.json +1 -1
package/dist/src/utils/api.d.ts
CHANGED
|
@@ -14,12 +14,12 @@ export declare const instructionConverter: (item: i.InstructionUnion[]) => Tweet
|
|
|
14
14
|
export declare const tweetEntriesConverter: (item: i.TimelineAddEntry[]) => TweetApiUtilsData[];
|
|
15
15
|
export declare const moduleConverter: (item: i.ModuleItem[]) => 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
|
@@ -75,14 +75,14 @@ const instructionConverter = (item) => {
|
|
|
75
75
|
return item
|
|
76
76
|
.flatMap((e) => {
|
|
77
77
|
if (e.type == i.InstructionType.TimelineAddEntries) {
|
|
78
|
-
return
|
|
78
|
+
return (0, exports.tweetEntriesConverter)(e.entries);
|
|
79
79
|
}
|
|
80
80
|
else if (e.type == i.InstructionType.TimelineAddToModule) {
|
|
81
81
|
const item = e.moduleItems ?? [];
|
|
82
82
|
return (0, exports.moduleConverter)(item);
|
|
83
83
|
}
|
|
84
84
|
else if (e.type == i.InstructionType.TimelineReplaceEntry) {
|
|
85
|
-
return [];
|
|
85
|
+
return (0, exports.tweetEntriesConverter)([e.entry]);
|
|
86
86
|
}
|
|
87
87
|
return [];
|
|
88
88
|
})
|
|
@@ -100,8 +100,8 @@ const tweetEntriesConverter = (item) => {
|
|
|
100
100
|
return undefined;
|
|
101
101
|
return [
|
|
102
102
|
(0, exports.buildTweetApiUtils)({
|
|
103
|
-
result: timeline
|
|
104
|
-
promotedMetadata: timeline
|
|
103
|
+
result: getTimelineTweetResult(timeline),
|
|
104
|
+
promotedMetadata: getTimelinePromotedMetadata(timeline),
|
|
105
105
|
}),
|
|
106
106
|
];
|
|
107
107
|
}
|
|
@@ -109,6 +109,7 @@ const tweetEntriesConverter = (item) => {
|
|
|
109
109
|
const item = e.content.items ?? [];
|
|
110
110
|
return (0, exports.moduleConverter)(item);
|
|
111
111
|
}
|
|
112
|
+
return undefined;
|
|
112
113
|
})
|
|
113
114
|
.filter((e) => e != undefined)
|
|
114
115
|
.map((e) => e.filter((e) => e != undefined))
|
|
@@ -124,8 +125,8 @@ const moduleConverter = (item) => {
|
|
|
124
125
|
if (timelineList[0].tweetDisplayType == i.TimelineTweetTweetDisplayTypeEnum.MediaGrid) {
|
|
125
126
|
return timelineList
|
|
126
127
|
.map((e) => (0, exports.buildTweetApiUtils)({
|
|
127
|
-
result: e
|
|
128
|
-
promotedMetadata: e
|
|
128
|
+
result: getTimelineTweetResult(e),
|
|
129
|
+
promotedMetadata: getTimelinePromotedMetadata(e),
|
|
129
130
|
}))
|
|
130
131
|
.filter((e) => e != undefined);
|
|
131
132
|
}
|
|
@@ -133,26 +134,43 @@ const moduleConverter = (item) => {
|
|
|
133
134
|
const timeline = timelineList[0];
|
|
134
135
|
return [
|
|
135
136
|
(0, exports.buildTweetApiUtils)({
|
|
136
|
-
result: timeline
|
|
137
|
-
promotedMetadata: timeline
|
|
137
|
+
result: getTimelineTweetResult(timeline),
|
|
138
|
+
promotedMetadata: getTimelinePromotedMetadata(timeline),
|
|
138
139
|
reply: timelineList.slice(1),
|
|
139
140
|
}),
|
|
140
141
|
].filter((e) => e != undefined);
|
|
141
142
|
}
|
|
142
143
|
};
|
|
143
144
|
exports.moduleConverter = moduleConverter;
|
|
145
|
+
const getTimelineTweetResult = (timeline) => {
|
|
146
|
+
return timeline?.tweetResults ?? timeline?.tweet_results;
|
|
147
|
+
};
|
|
148
|
+
const getTimelinePromotedMetadata = (timeline) => {
|
|
149
|
+
return timeline?.promotedMetadata ?? timeline?.promoted_metadata;
|
|
150
|
+
};
|
|
151
|
+
const getTweetUserResult = (tweet) => {
|
|
152
|
+
return tweet?.core?.userResults?.result ?? tweet?.core?.user_results?.result;
|
|
153
|
+
};
|
|
154
|
+
const getQuotedStatusResult = (tweet) => {
|
|
155
|
+
return tweet?.quotedStatusResult ?? tweet?.quoted_status_result;
|
|
156
|
+
};
|
|
157
|
+
const getRetweetedStatusResult = (tweet) => {
|
|
158
|
+
return tweet?.legacy?.retweetedStatusResult ?? tweet?.legacy?.retweeted_status_result;
|
|
159
|
+
};
|
|
144
160
|
const buildTweetApiUtils = (args) => {
|
|
161
|
+
if (args.result == undefined)
|
|
162
|
+
return undefined;
|
|
145
163
|
const tweet = (0, exports.tweetResultsConverter)(args.result);
|
|
146
164
|
if (tweet == undefined)
|
|
147
165
|
return undefined;
|
|
148
|
-
const result = tweet
|
|
166
|
+
const result = getTweetUserResult(tweet);
|
|
149
167
|
const user = result && (0, exports.userOrNullConverter)(result);
|
|
150
168
|
if (user == undefined)
|
|
151
169
|
return undefined;
|
|
152
|
-
const quoted = tweet
|
|
153
|
-
const retweeted = tweet
|
|
170
|
+
const quoted = getQuotedStatusResult(tweet);
|
|
171
|
+
const retweeted = getRetweetedStatusResult(tweet);
|
|
154
172
|
const reply = args.reply
|
|
155
|
-
?.map((e) => (0, exports.buildTweetApiUtils)({ result: e
|
|
173
|
+
?.map((e) => (0, exports.buildTweetApiUtils)({ result: getTimelineTweetResult(e), promotedMetadata: getTimelinePromotedMetadata(e) }))
|
|
156
174
|
.filter((e) => e != undefined) ?? [];
|
|
157
175
|
return {
|
|
158
176
|
raw: args.result,
|
|
@@ -166,6 +184,8 @@ const buildTweetApiUtils = (args) => {
|
|
|
166
184
|
};
|
|
167
185
|
exports.buildTweetApiUtils = buildTweetApiUtils;
|
|
168
186
|
const tweetResultsConverter = (tweetResults) => {
|
|
187
|
+
if (tweetResults == undefined)
|
|
188
|
+
return undefined;
|
|
169
189
|
if (tweetResults.result == undefined)
|
|
170
190
|
return undefined;
|
|
171
191
|
switch (tweetResults.result.typename) {
|