Automated script for selecting fast TOR circuit?

Tor Asked on September 28, 2021

I noticed a significant variance in bandwidth with different TOR circuits. Some are fast enough for streaming HD videos, while others take ages just loading web pages unless Javascript is deactivated. Therefore, when first launching the TOR browser, I usually keep hitting the "New Identity" button (which AFAIK builds a new circuit) until the loading time for a certain web page is reasonably short. In most cases, this takes 4-5 attempts. The difference in speed can be huge, so I always do this before streaming media or browsing script-heavy sites.

Is it possible to automatize this startup procedure, i.e. have the TOR browser start, build a circuit, gauge the bandwidth, and build a new circuit if a certain bandwidth threshold isn’t reached? Could this, for instance, be done with a Bash or Python script?

Something along the lines of:

i==0;
WHILE i < 10:
START tor_browser
IF bw > bw_min:    #e.g. 2 Mbps
BREAK
ELSE:
QUIT tor_browser
i++1
END


Where would one even start? Does the TOR browser have an API that can interface e.g. with Python? How does one make the browser download a file (in contrast to using curl or the like) and how measure the bandwidth? Is it something like "TOR uses a certain port and there exists a Python package that can monitor the traffic through it"?

Related Questions

Setting up relay on Ubuntu 16.04

1  Asked on August 1, 2020 by jenni

How to run the tor browser through a second proxy after Tor?

1  Asked on July 22, 2020 by 14987355