How do I block ads on YouTube?

# Brace expanded array of Google Video fingerprints from sn-aaaaaaaa to sn-99999999
fingerprints=($(echo sn-{{a..z},{0..9}}{{a..z},{0..9}}{{a..z},{0..9}}{{a..z},{0..9}}{{a..z},{0..9}}{{a..z},{0..9}}{{a..z},{0..9}}{{a..z},{0..9}}))
# For each fingerpint, 
for ((i = 0; i < "${#fingerprints[@]}"; i++)); do
  # Generate the list based on https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/11?u=jacob.salmela
  echo r{1..20}---${fingerprints[$i]}.googlevideo.com
  echo r{1..20}.${fingerprints[$i]}.googlevideo.com
done

@jacob.salmela Can you humor me with this idea:

Create a script to generate the entire array from a more powerful machine (The one from above seems to be a good starting point). Then have a function that pings each of those domains. If the domain gets a response, the script writes that domain in a separate list. If the domain has no response, the script drops that domain.

The idea is to narrow down the list of possible ad-serving domains that actually responds, as opposed to having millions dud domains on the Pi.

After that is filtered out, upload it to the Pi and blacklist.


I want to actually do this but I don't know how to create shell scripts efficiently. I apologize if I sound so bossy and demanding :disappointed:.

2 Likes