This project is designed to download Twitter Spaces using the twitterspace_dl.js
module, with axios
for HTTP requests and ffmpeg
for audio processing.
- Node.js and npm (for JavaScript dependencies)
- ffmpeg: Place
ffmpeg.exe
in the same folder astwitterspace_dl.js
or add it to the system environment path.
-
Install required Node.js dependencies:
npm install axios
-
Place
ffmpeg.exe
in the project directory or configure it in the system environment.
The main function for downloading Twitter Spaces is TwitterSpace(whoseSpace, auth_data, configObj)
.
-
whoseSpace
- Twitter username or rest_id (string or number). -
auth_data
- Twitter authentication details in an object format:auth_data = { "ct0": "xxxxxxxxxxxxxxxxxxx", "auth": "xxxxxxxxxxxxxxxxxxxxx" }
- These values are available in the browser's Developer Tools under the "Cookies" section.
-
configObj
(optional) - Configuration object:configObj = { "record": true, // Start recording if true "outputPath": "./", // Directory to save output files "searchByName": true, // Search by username (true) or by rest_id (false) "saveIds": false // Save downloaded Space IDs }
- On success, returns an object with details about the Twitter Space:
{ "title": broadcastTitle, "m3u8": Spacem3u8, "nameOrId": userName_or_userId, "spaceId": spaceId, "broadcastId": broadcastId, "spaceData": spaceData, "userData": userData }
- If the Space is not live, it returns
2
. - On error, it returns
-1
.
const twitterSpace = new TwitterSpace(auth_data, configObj);
twitterSpace.execute("omarupolka").then((result) => {
console.log(result);
}).catch((error) => {
console.error("Error:", error);
});
const twitterSpace = new TwitterSpace(auth_data, { record: false });
twitterSpace.execute("omarupolka").then((result) => {
console.log(result);
}).catch((error) => {
console.error("Error:", error);
});
const twitterSpace = new TwitterSpace(auth_data, { record: true, outputPath: "./spacesave", searchByName: false });
twitterSpace.execute("1270551806993547265").then((result) => {
console.log(result);
}).catch((error) => {
console.error("Error:", error);
});
const twitterSpace = new TwitterSpace(auth_data, { record: true, outputPath: "./spacesave", searchByName: false, saveIds: true });
twitterSpace.execute("1270551806993547265").then((result) => {
console.log(result);
}).catch((error) => {
console.error("Error:", error);
});
TwitterSpace
offers shortcut functions for specific data retrieval:
TwitterSpace.getM3u8_FromBroadcastId(broadcastId)
TwitterSpace.getM3u8_FromSpaceId(spaceId)
TwitterSpace.getSpaceData_FromSpaceId(spaceId)
The GetQueryId.js
module is used to retrieve GraphQL query IDs for Twitter's API.
const getQueryId = new GetQueryId(botConfig);
getQueryId.getQueryId("HomeTimeline").then((queryId) => {
console.log("HomeTimeline's queryId:", queryId);
}).catch((error) => {
console.error("Failed to retrieve queryId:", error);
});
GraphQLName
: Name of the GraphQL query (string or array).noCheck
: Skip version check (boolean).forcedUpdate
: Force update of Token.json (boolean).
Retrieve data for multiple GraphQL queries:
const getQueryId = new GetQueryId(botConfig);
getQueryId.getQueryId(["HomeTimeline", "BizProfileFetchUser", "UsersByRestIds"]).then((result) => {
console.log(result);
}).catch((error) => {
console.error("Failed to retrieve queryId:", error);
});
Retrieve data for a single query:
const getQueryId = new GetQueryId(botConfig);
getQueryId.getQueryId("HomeTimeline").then((queryId) => {
console.log("HomeTimeline's queryId:", queryId);
}).catch((error) => {
console.error("Failed to retrieve queryId:", error);
});