diff --git a/lib/v2/twitter/web-api/constants.js b/lib/v2/twitter/web-api/constants.js index fe18ac2aa..65d36deb0 100644 --- a/lib/v2/twitter/web-api/constants.js +++ b/lib/v2/twitter/web-api/constants.js @@ -67,8 +67,11 @@ const featuresMap = { }), }; +const auth = 'Bearer AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF'; + module.exports = { tokens, graphQLMap, featuresMap, + auth, }; diff --git a/lib/v2/twitter/web-api/twitter-api.js b/lib/v2/twitter/web-api/twitter-api.js index e3ad4a9a8..ecc4a7f5b 100644 --- a/lib/v2/twitter/web-api/twitter-api.js +++ b/lib/v2/twitter/web-api/twitter-api.js @@ -1,6 +1,7 @@ const twitterGot = require('./twitter-got'); -const { graphQLMap, featuresMap } = require('./constants'); +const { graphQLMap, featuresMap, auth } = require('./constants'); const config = require('@/config').value; +const got = require('@/utils/got'); // https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L727-L755 const _params = { @@ -104,13 +105,17 @@ const timelineLikes = (userId, params = {}) => paginationTweets(graphQLMap.Likes // https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L858-L866 const timelineKeywords = (keywords, params = {}) => - twitterGot('https://twitter.com/i/api/2/search/adaptive.json', { - ..._params, - ...params, - q: keywords, - tweet_search_mode: 'live', - query_source: 'typed_query', - pc: 1, + got('https://api.twitter.com/1.1/search/universal.json', { + headers: { + Authorization: auth, + }, + searchParams: { + ..._params, + ...params, + q: keywords, + modules: 'status', + result_type: 'recent', + }, }); // https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L795-L805 @@ -180,35 +185,6 @@ function gatherLegacyFromData(entries, filter = 'tweet-') { return tweets; } -function pickLegacyByID(id, tweets_dict, users_dict) { - function pickLegacyFromTweet(tweet) { - tweet.user = users_dict[tweet.user_id_str]; - if (tweet.retweeted_status_id_str) { - tweet.retweeted_status = pickLegacyFromTweet(tweets_dict[tweet.retweeted_status_id_str]); - } - return tweet; - } - - if (tweets_dict[id]) { - return pickLegacyFromTweet(tweets_dict[id]); - } -} - -function gatherLegacyFromLegacyApiData(data, filter = 'tweet-') { - const tweets_dict = data.globalObjects.tweets; - const users_dict = data.globalObjects.users; - const tweets = []; - data.timeline.instructions[0].addEntries.entries.forEach((entry) => { - if (entry.entryId && entry.entryId.indexOf(filter) !== -1) { - const tweet = pickLegacyByID(entry.content.item.content.tweet.id, tweets_dict, users_dict); - if (tweet) { - tweets.push(tweet); - } - } - }); - return tweets; -} - const getUserTweetsByID = async (id, params = {}) => gatherLegacyFromData(await timelineTweets(id, params)); const getUserTweetsAndRepliesByID = async (id, params = {}) => gatherLegacyFromData(await timelineTweetsAndReplies(id, params)); const getUserMediaByID = async (id, params = {}) => gatherLegacyFromData(await timelineMedia(id, params)); @@ -262,7 +238,7 @@ const getUserMedia = (cache, id, params = {}) => cacheTryGet(cache, id, params, const getUserLikes = (cache, id, params = {}) => cacheTryGet(cache, id, params, getUserLikesByID); const getUserTweet = (cache, id, params) => cacheTryGet(cache, id, params, getUserTweetByStatus); -const getSearch = async (keywords, params = {}) => gatherLegacyFromLegacyApiData(await timelineKeywords(keywords, params), 'sq-I-t-'); +const getSearch = async (keywords, params = {}) => (await timelineKeywords(keywords, params)).data.modules.map((module) => module.status.data); module.exports = { getUser,