Search for Rumble videos in the terminal


Rumble has some documentation suggesting the existence of an official API, but it appears all requests for API keys have fallen on deaf mailboxes. This is working, for now:



#!/usr/bin/env bash
#rts/oarion7

# Search for videos on rumble.com, returns url(s) for selected results; tab key to select multiple

# Dependencies: xmllint, rlwrap, jq, fzf https://github.com/junegunn/fzf
# Needs a recent enough fzf to support {n} placeholders and the become() event

# Recommended: https://github.com/yt-dlp/yt-dlp/

history_file="$HOME/.config/rumble_search_history"
UA=$(<"$HOME/scripts/UserAgent/string.txt") #Spoof an updated UA string just in case.

if [[ -z "$@" ]] ; then
    printf '\n%s\n' '=>> Search for Rumble videos'
    #read -p "> " readitem
    readitem=$(rlwrap -S '> ' -H "$history_file" -o cat) 
else
    readitem="$@"
fi

query="$( printf '%s\n' "$readitem" | tr -d '\n' | tr -d '!' | tr -d "'" | jq -sRr @uri )"

[[ -z "$query" ]] && exit

html=$(curl -A "$UA" -Ss "https://rumble.com/search/all?q=$query")

[[ -z "$html" ]] && { printf '%s\n' "Error fetching results." ; exit 1; } 

list=$(for i in $(seq "$(printf '%s\n' "$html" | xmllint --html --xpath 'count((//li/article//a/div/img))' - 2>/dev/null)") 
    
    do

        title="$(printf '%s\n' "$html" | xmllint --html --xpath "string((//img[@class='video-item--img']) [$i]/@alt)" - 2>/dev/null )"
        url="$(printf '%s\n' "$html" | xmllint --html --xpath "string((//a[@class='video-item--a']) [$i]/@href)" - 2>/dev/null )"
        time="$(printf '%s\n' "$html" | xmllint --html --xpath "string((//time[@class='video-item--meta video-item--time']) [$i]/@datetime)" - 2>/dev/null )"

        printf '%s:\t %s\n' "$(printf '%s\n' "$time" | cut -c-10)" "$title" | tr -cd '.,?!`!@#$%^&*()"-=_+[]{}|:;<>a-zA-Z0-9 \n'

    done)

[[ -z "$list" ]] && { printf '%s\n' "No results found." ; exit 1; } 

_conv() { printf '%s\n' $(( "$1" + 1 )) ; }

for i in $( printf '%s\n' "$list" |  fzf -m --bind 'enter:become(printf "%s\\n" {+n})') ; do 
    url_part="$(printf '%s\n' "$html" | \
        xmllint --html --xpath "string((//a[@class='video-item--a']) ["$(_conv "$i")"]/@href)" - 2>/dev/null )"
    printf 'https://rumble.com%s\n' "$url_part"
done