How do I block ads on YouTube?

I noticed the same thing using googlevideo.com as a wildcard. You can load a video and then watch the query log and it will load 5-6 variations of rxxxsnxxx.googlevideo.com before it quits loading entirely. Some of those variations are the video, some are the advertisement. If you right click on the ad when it loads in Firefox and copy the debug info to notepad you can see which domain is the ad by scrolling down to ad_lvh (or is it ad_lbh?) near the bottom.

I am still getting youtube video ads on my videos using the default settings but all the other site ads are gone so im not sure what you are doing differently than me to get rid of them. At this point I've reached the limit of what I can accomplish with my current abilities so i've kinda given up for now.

Really hope we can figure out a way to bypass these ads, good luck!

have you tryed to load the video with disabled javascript?
your regex is correct i ve tested it with https://regex101.com/

# "r\d+\W+sn\-.*\.googlevideo\.com" 
/:r\d+\W+sn\-.*\.googlevideo\.com:/192.168.1.5
1 Like

The video ads on Youtube are no longer being blocked for me even though I am using the list that was linked to earlier.

I would look at how Kodi does it.

I haven't ever seen a single ad when watching a youtube video via the YT plugin in Kodi.
so there has to be a way that it can source just the video and not play the ads. Either that or the overlays are blocked by kodi somehow? But I'm watching kodi on an android box connected to my TV and it should be able to play adverts just the same way that my mobile phone can... but it doesn't... it strips them out completely. I wonder how they do it ?

The Kodi youtube plugin is simply coded in such a way as to not show ads. Pi-hole cannot reprogram your youtube player or the website itself, so it can't work in the same way that Kodi does it.

I'm using YouTube adway apk. No ads whatsoever. You can download it on http://arter97.com/browse/youtube/adaway/ apk is clean. All credit goes to the respective developer.

1 Like

So how I remove YouTube ads?

So how I remove YouTube ads on PC and tablets ...?

pihole removes most of the youtube ads but not all. If you combine uBlock with pihole you can get rid off all ads. Another way is to use a firewall like pfSense with e.g. pfBlockerNG. You can pick the one which matches your needs best :wink:

Yes, I know that.
Thought without using AdBlock and uBlock software.

Recipe on youtube i think at the beginning of the video. You know what I mean?

No it doesn't, as I have tested videos are delivered using rX---sn-cnoa-cage.googlevideo.com blocking these will prevent videos from loading. Also these are region specific (in my case India). Also ad domains have some sort of commonality, for example I get ads from rX---sn-h557sn7r.googlevideo.com and from 6 other domains, so I blacklisted from r1 to r20 for each domain. I haven't seen any ads from a couple of days.

Mod Edit: Removed link to site that has AUP's and Terms that are not compatible with the Pi-hole. Please do not link to sites that are bulk downloaders or circumvent the Acceptable Use of a service.

I know what you mean - until now I was not able to block the ads at the beginning of the video only with pihole :disappointed:

How can I use these commands? Or how can I actually implement them, I have no idea how to use it. And ADS are everywhere in YouTube.

I use that too works great whit youtube ads :smile:

Hi guys! Is there any additional software I can install on raspberry to help pihole to kill youtube ads?
Raspberry pi3 with raspbian

If you're using Android take a look at this thread on XDA, it's a modified version of YouTube app. Works well and has some other cool features too!

1 Like

Well i combined some ideas and small improvements found on this topic into a install script

Requirements: Pi-hole Version v3.2.1 Web Interface Version v3.2.1 FTL Version.

Default scriptcode: ubuntu / debian.
You can convert the script to other platforms by simple replace the scriptcode line:

"apt-get python-pip install"

Replace it with the install command required to install python pip on your distro.

create file as following:

  • sudo -i (and login)

  • nano /etc/pihole/youtube-adblock-install.sh

  • paste the scriptcode below:

  • exit nano with ctrl+x and save the install script

  • chmod +x /etc/pihole/youtube-adblock-install.sh

  • run /etc/pihole/youtube-adblock-install.sh

scriptcode:

echo "created for public use and use."
echo "Start with re-install cleanup."
rm -r /etc/dnsdumpster
rm /var/www/html/youtube-ads-list.txt
rm /etc/pihole/youtube-ads.sh
echo "cleanup done."
echo "installing python-pip and dnsdumpster."
apt-get install python-pip
pip install --upgrade pip
pip uninstall dnsdumpster
mkdir /etc/dnsdumpster
echo "" > /etc/dnsdumpster/youtube-domains.txt
echo "" > /etc/dnsdumpster/youtube-filtered.txt
echo "" > /etc/dnsdumpster/youtube-ads.txt
cd /etc/dnsdumpster
pip install https://github.com/PaulSec/API-dnsdumpster.com/archive/master.zip --target /etc/dnsdumpster/
pip install https://github.com/PaulSec/API-dnsdumpster.com/archive/master.zip --user
echo "copying dnsdumpster API_example.py script and modify it as ADS_youtube.py."
echo "replacing API_example.py domain 'tsebo.com' with 'googlevideo.com'."
sed 's/tsebo.com/googlevideo.com/g' /etc/dnsdumpster/dnsdumpster/API_example.py > /etc/dnsdumpster/dnsdumpster/ADS_youtube-temp.py
echo "remove some script lines from script to resolve XLS base64 errors as it is not required"
awk 'NR!~/^(35|36|37|38)$/' /etc/dnsdumpster/dnsdumpster/ADS_youtube-temp.py > /etc/dnsdumpster/dnsdumpster/ADS_youtube.py
echo "ADS_youtube.py script created."
echo "cleanup temp script file."
rm /etc/dnsdumpster/dnsdumpster/ADS_youtube-temp.py
echo "create update script /etc/pihole/youtube-ads.sh."
echo "youtube-ads.sh is used for maintaining youtube generated list youtube-ads-list.txt in pihole webroot for pihole update access."
echo "echo off" >> /etc/pihole/youtube-ads.sh
echo "rm /etc/dnsdumpster/youtube-domains.txt" >> /etc/pihole/youtube-ads.sh
echo "rm /etc/dnsdumpster/youtube-filtered.txt" >> /etc/pihole/youtube-ads.sh
echo "rm /etc/dnsdumpster/youtube-ads.txt" >> /etc/pihole/youtube-ads.sh
echo "python /etc/dnsdumpster/dnsdumpster/ADS_youtube.py > /etc/dnsdumpster/youtube-domains.txt" >> /etc/pihole/youtube-ads.sh
echo "grep ^r /etc/dnsdumpster/youtube-domains.txt >> /etc/dnsdumpster/youtube-filtered.txt" >> /etc/pihole/youtube-ads.sh
echo "sed 's/\s.*$//' /etc/dnsdumpster/youtube-filtered.txt >> /etc/dnsdumpster/youtube-ads.txt" >> /etc/pihole/youtube-ads.sh
echo "cat /etc/dnsdumpster/youtube-ads.txt > /var/www/html/youtube-ads-list.txt" >> /etc/pihole/youtube-ads.sh
echo "#greps the log for youtube ads and appends to /var/www/html/youtube-ads-list.txt" >> /etc/pihole/youtube-ads.sh
echo "grep r*.googlevideo.com /var/log/pihole.log | awk '{print $6}'| grep -v '^googlevideo.com\|redirector' | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt" >> /etc/pihole/youtube-ads.sh
echo "#removes duplicate lines from /var/www/html/youtube-ads-list.txt" >> /etc/pihole/youtube-ads.sh
echo "perl -i -ne 'print if ! $x{$_}++' /var/www/html/youtube-ads-list.txt" >> /etc/pihole/youtube-ads.sh
echo "#updates pihole blacklist/whitelist" >> /etc/pihole/youtube-ads.sh
echo "pihole -g" >> /etc/pihole/youtube-ads.sh
echo "youtube-ads.sh script created."
echo "chmod script to executable."
chmod +x /etc/pihole/youtube-ads.sh
echo "add youtube-ads.sh maintained list youtube-ads-list.txt from local webroot: http://localhost/youtube-ads-list.txt to pihole lists."
echo "http://localhost/youtube-ads-list.txt" >> /etc/pihole/adlists.list
echo "save current crontab to mycron.sav, add crontab job, to run youtube-ads.sh updater every 15 minutes."
crontab -l > mycron.sav
echo "*/15 * * * * /etc/pihole/youtube-ads.sh" > mycron
crontab mycron
rm mycron
echo "manual update first."
/etc/pihole/youtube-ads.sh
echo "done, now enjoy youtube ad free, thru your pihole."

Test or View generated youtube ads list in your webbrowser:

http://< pihole weburl >/youtube-ads-list.txt

Here you go: :popcorn::popcorn::popcorn:

use it free,it works for me :slight_smile:

3 Likes

@Joshua_joezoef_B_ZzO

Awesome work man. Can you please make it work on rasbian, too?

@Schrauber47
Have you tried it? If so, which command fails? Although I haven't tried it there seems to be nothing that's obvious why it shouldn't just work on Raspbian.