npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

xdl-node

v1.0.17

Published

A library for retrieving audio streams and other data from X Spaces, built on Node.js and TypeScript.

Readme

xdl-node

xdl-node is a TypeScript library for interacting with Twitter’s unofficial APIs—specifically for working with Twitter Spaces. This library is based on the Twspace-dl library by HoloArchivists and has been completely rewritten in TypeScript for improved type safety and maintainability.

Features

  • Twitter API Clients:
    Interact with Twitter’s GraphQL, Fleets, and Live Video Stream endpoints.

  • Space Metadata:
    Retrieve detailed metadata about Twitter Spaces.

  • Space Downloading:
    Download Twitter Space audio streams via ffmpeg, with support for embedding cover images (e.g., user avatars).

  • Live Recording:
    Record live Twitter Spaces with the ability to stop the recording gracefully.

  • TypeScript Support:
    Fully typed with TypeScript, including declaration files for an improved developer experience.

Installation

Install the library via npm:

npm install xdl-node

Or with yarn:

yarn add xdl-node

Usage Guide

This guide provides examples on how to initialize the API, download a Twitter Space, and record a live Space.

1. Importing the Library

The library exports several modules:

  • API: An instance of the TwitterAPI class for initializing and accessing various Twitter endpoints.
  • loadCookies: A helper function to load cookies from a file (in Netscape format).
  • Twspace: A class representing a Twitter Space.
  • TwspaceDL: A class for downloading and processing Twitter Spaces.

2. Initializing the API

Before using any API endpoints, you need to load your cookies and initialize the API clients. Your cookies file must be in Netscape format.

import { API, loadCookies } from 'xdl-node';

// Load cookies from a file
const cookies = loadCookies('path/to/cookies.txt');

// Initialize the API clients with your cookies
API.initApis(cookies);

3. Downloading a Twitter Space

Below is an example of how to download a Twitter Space:

import { API, Twspace, TwspaceDL } from 'xdl-node';

async function downloadSpace() {
  try {
    // Create a Twspace instance from a Twitter Space URL.
    // Example URL: "https://x.com/i/spaces/SPACE_ID"
    const spaceUrl = 'https://x.com/i/spaces/SPACE_ID';
    const space = await Twspace.fromSpaceUrl(spaceUrl, API);
    console.log("Retrieved space metadata:", space);

    // Create a downloader instance with a desired filename format.
    const downloader = new TwspaceDL(space, "(%(creator_name)s)%(title)s-%(id)s");

    // Download the space audio using ffmpeg.
    await downloader.download();

    // Optionally, embed the user's profile image as cover art.
    await downloader.embedCover();

    // Clean up any temporary files created during download.
    await downloader.cleanup();

    console.log("Download complete!");
  } catch (error) {
    console.error("Error during download:", error);
  }
}

downloadSpace();

4. Live Recording a Twitter Space

To record a live Twitter Space, use the live recording functionality. The recording will continue until you explicitly stop it.

import { API, loadCookies, Twspace, TwspaceDL } from 'xdl-node';

async function recordLiveSpace() {
  try {
    // Load cookies and initialize API endpoints.
    const cookies = loadCookies('path/to/cookies.txt');
    API.initApis(cookies);

    // Create a Twspace instance from a user's profile URL.
    // This example attempts to detect a live space from the user's account.
    const userUrl = 'https://x.com/username';
    const space = await Twspace.fromUserAvatar(userUrl, API);

    // Create a downloader instance.
    const downloader = new TwspaceDL(space);

    // Start live recording; the recording will run until you stop it.
    await downloader.startLiveRecording();
    console.log("Live recording started. Use downloader.stopLiveRecording() to stop.");

    // To stop live recording, you can later call:
    // downloader.stopLiveRecording();
  } catch (error) {
    console.error("Error during live recording:", error);
  }
}

recordLiveSpace();

API Overview

TwitterAPI

Aggregates clients for different Twitter endpoints:

  • graphql_api for GraphQL queries.
  • fleets_api for Fleets endpoints.
  • live_video_stream_api for live video stream endpoints.

Initialization:
Call API.initApis(cookies) to initialize these clients.

Twspace

Represents a Twitter Space and provides static methods:

  • fromSpaceUrl(url, apiInstance): Creates a Twspace instance from a Space URL.
  • fromUserAvatar(user_url, apiInstance): Creates a Twspace instance from a user’s profile URL (to detect live spaces).
  • fromFile(filePath): Creates a Twspace instance from a local metadata file.

TwspaceDL

Manages downloading and processing of Twitter Space audio.

  • download(): Downloads the audio stream via ffmpeg.
  • embedCover(): Embeds a cover image (such as a user’s avatar) into the audio file.
  • startLiveRecording(): Begins live recording of a Twitter Space.
  • stopLiveRecording(): Stops an ongoing live recording.
  • cleanup(): Removes temporary files created during the download process.

Contributing

Contributions are welcome! For collaboration or if you have any ideas or issues, please contact t.me/norilover.

License

This project is licensed under the MIT License.