Skip to content

Instantly share code, notes, and snippets.

@rodrigopolo
Last active December 23, 2024 22:43
Show Gist options
  • Save rodrigopolo/40029718a85963399784ae35b06adcaf to your computer and use it in GitHub Desktop.
Save rodrigopolo/40029718a85963399784ae35b06adcaf to your computer and use it in GitHub Desktop.
Twitter/X Space Downloader
#!/usr/bin/env bash
#
# Twitter/X Space Downloader Bash Script
# Copyright (c) 2024 Rodrigo Polo - rodrigopolo.com - The MIT License (MIT)
#
# Check if a stream URL is provided
if [ -z "$1" ]; then
echo "Usage: $0 <stream_url>"
exit 1
fi
# Modifying the internal field separator
IFS=$'\t\n'
SPACEURL="$1"
STREAM=$(yt-dlp --cookies-from-browser opera -g $SPACEURL)
FILE_NAME=$(yt-dlp --cookies-from-browser opera --get-filename -o "%(upload_date)s - %(uploader_id)s.%(title)s.%(id)s.%(ext)s" $SPACEURL)
# Get the stream path
STREAMPATH=$(echo "$STREAM" | grep -Eo "(^.*[\/])")
# Download the stream
if ! wget "$STREAM" -O stream.m3u8; then
echo "Failed to download the stream."
exit 1
fi
# Prefix the URLs for the chunks
cat stream.m3u8 | sed -E "s|(^[^.#]+.aac$)|$STREAMPATH\1|g" > modified.m3u8
# Download the chunks
aria2c -x 10 --console-log-level warn -i modified.m3u8
# Join the chunks
ffmpeg -i stream.m3u8 -vn -acodec copy -movflags +faststart "$FILE_NAME"
# Clean-up temporary files
eval "$(cat stream.m3u8| grep -Eo "(^[^.#]+.aac$)" | sed 's/^/rm /')"
rm stream.m3u8 modified.m3u8
@giulioprisco
Copy link

Works well! You may have to change the browser name in lines 19 and 20.

@redblocklabshq
Copy link

Works really well. Appreciate you sharing this to the public.

@rodrigopolo
Copy link
Author

BTW, you can also use yt-dlp, already supports it
https://github.com/yt-dlp/yt-dlp

It is a fork of youtube-dl, here is a cheat sheet
https://github.com/rodrigopolo/cheatsheets/blob/master/youtube-dl.md

@redblocklabshq
Copy link

Thanks! I’m looking for a way to transcribe the Twitter spaces next and then summarize the Twitter spaces using a local LLM like Ollama. Do you have any suggestions?

@rodrigopolo
Copy link
Author

Thanks! I’m looking for a way to transcribe the Twitter spaces next and then summarize the Twitter spaces using a local LLM like Ollama. Do you have any suggestions?

  1. Whisper: https://github.com/rodrigopolo/cheatsheets/blob/master/whisper.md
  2. Adobe Photoshop
  3. DaVinci Resolve
  4. Subtitle Edit (PC Only) that uses Whisper or Vosk/Kaldi https://www.nikse.dk/subtitleedit

@redblocklabshq
Copy link

redblocklabshq commented Dec 23, 2024

Thank you for the suggestions! Appreciate you.

The cheatsheets are really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment