I'm leave here the final script that worked for me after @Chipster suggestion.
#!/bin/sh
# This script will fetch the Googlevideo ad domains and append them to the Pi-hole block list.
# Run this script daily with a cron job (don't forget to chmod +x)
# More info here: https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/136
# File to store the YT ad domains
FILE=/etc/pihole/youtube.hosts
# Wolfram Alfa AppID
APPID=Your-AppID
# Fetch the list of domains, remove the ip's and save them
curl 'https://api.hackertarget.com/hostsearch/?q=googlevideo.com' \
| awk -F, 'NR>1{print $1}' \
| grep -vE "redirector|manifest" > $FILE
# Replace r*.sn*.googlevideo.com URLs to r*---sn-*.googlevideo.com
# and add those to the list too
curl "http://api.wolframalpha.com/v2/query?input=googlevideo.com&appid=${APPID}&format=plaintext&podstate=WebSiteStatisticsPod:InternetData__Subdomains&podstate=WebSiteStatisticsPod:InternetData__Subdomains_More" \
| grep -Po "r\d+---sn-.+.googlevideo.com" >> $FILE
# Scan log file for previously accessed domains
grep "r*\.googlevideo\.com" /var/log/pihole*.log \
| awk '{print $8}' \
| grep -vE "redirector|manifest" \
| sort | uniq >> $FILE
# Add to Pi-hole adlists if it's not there already
if ! grep $FILE < /etc/pihole/adlists.list; then echo "file://$FILE" >> /etc/pihole/adlists.list; fi;
I don't know but I have the feeling that this is going to end blocking the whole youtube.
All the googlevideo.com queries are r*.googlevideo.com. So sometimes I have to reload if I want to watch a video so it changes the domain (or something like that).
This feature is now implemented and available for early-on testing if you want to get your hands dirty. I guess that means the race is open for the best blocking regex!
I have the solution revealed here and it's not working. Even worse, sometimes it's blocking ads on mobile.
I'm not an expert in this field, but I think the real challenge is separare youtube's domains that bring to you videos you want to see and videos that are ads.
add-ons and applications like uBlock, and ABP use a slightly different technology to block ads. where pi-hole only looks at XXXYYY.com
applications like listed above are able to look at XXXYYY.com/ZZZ