How do I block ads on YouTube?

Hi and thanks for this script.
Right now I have about 150 domains in my list.

@itsme awesome, thank you for your help!

Is there a mistake in /etc/pihole/youtube-ads.sh ?
Line 10:
grep r*.googlevideo.com /var/log/pihole.log | awk '{print }'| grep -v '^googlevideo.com\|redirector' | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt
Isn't anything missing after the awk'{print }'? Because it pastes the whole log there and not just the hostnames.
My idea was to just add the "$6" so it takes the hosts:
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

Thank you for the great work and the idea!

Best Regards

Since I ruined the script, Pi-hole is keeping resolving “dnsdumpster.com11” is this expected?

I don’t know why, it’s seems to be coming from the Raspberry pi himself.

I don't understand why a such trafic and is that safe?

This is the original line from the script, but since the $ aren't escaped, the echo command tries to evaluate them. In short, the script line should be

echo "perl -i -ne 'print if ! \$x{\$_}++' /var/www/html/youtube-ads-list.txt" >> /etc/pihole/youtube-ads.sh

Likewise the reason for the missing $6 that Cheesman97 mentioned:

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

The escapes get swallowed by the echo otherwise...

I changed the script form @Joshua_joezoef_B_ZzO a bit (/etc/pihole/youtube-ads.s):

echo "" > /etc/dnsdumpster/youtube-domains.txt
echo "" > /etc/dnsdumpster/youtube-filtered.txt
echo "" > /etc/dnsdumpster/youtube-ads.txt
python /etc/dnsdumpster/dnsdumpster/ADS_youtube.py > /etc/dnsdumpster/youtube-domains.txt
grep ^r /etc/dnsdumpster/youtube-domains.txt >> /etc/dnsdumpster/youtube-filtered.txt
sed 's/\s.*$//' /etc/dnsdumpster/youtube-filtered.txt >> /etc/dnsdumpster/youtube-ads.txt
cat /etc/dnsdumpster/youtube-ads.txt > /var/www/html/youtube-ads-list.txt
#greps the log for youtube ads and appends to /var/www/html/youtube-ads-list.txt
grep r*.googlevideo.com /var/log/pihole.log /var/log/pihole.log.1 | awk '{print $6}'| grep -v '^googlevideo.com\|redirector' | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt
#removes duplicate lines from /var/www/html/youtube-ads-list.txt
perl -i -ne 'print if ! $x{$_}++' /var/www/html/youtube-ads-list.txt
#updates pihole blacklist/whitelist
pihole -g

@idgers : On my rasbian it works without any escaping

Also make sure that the cronjob has a PATH variable:

*/15 * * * * PATH="$PATH:/usr/local/bin:/usr/bin" /etc/pihole/youtube-ads.sh >/dev/null

Something I found out:
It works on PC, but the YouTube-App on my iPhone doesn't work anymore (doesn't load any video).
I think the App can't handle not avaiable ads.

Huh, I'm on raspbian also. Maybe you used single quotes? Or maybe a paste messed something up when I went though it the other day...that's probably the most likely reason.

I found the same problem, though, where it doesn't work for mobile devices...ended up disabling it all since I already have a browser extension that handles it on PC. Wish I had more time to dig into it.

My list ends up being empty after running the script of @Joshua_joezoef_B_ZzO.

I do get the following error:
Traceback (most recent call last):
File "/etc/dnsdumpster/dnsdumpster/ADS_youtube.py", line 35, in
print("\n\n\nRetrieved XLS hosts? {} (accessible in 'xls_data')".format(xls_retrieved))
NameError: name 'xls_retrieved' is not defined

I made the adjustments @idgers suggested:
changed the following lines:
echo "perl -i -ne 'print if ! $x{$_}++' /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

seems that dnsdumpster is failing (server code 500) when googlevideo.com is queried.
though it does appear to be working for others.

so if you folks see empty files, this is why :slight_smile:

First I will say thanks for the big work you all do

Are there any fix for line35 error

so, i remember fixing something, but unsure now what :confused:
but you are welcome to my copy of dnsdumpster folder ... getting an error from dnsdumpster site (but it happens if you go to dnsdumpster and query googlevideo.com regardless)

anyway, if you want - here is my dnsdumpster folder - http://buffalo.biodome.org/m/dnsdumpster.tgz

Hi,

Any option to share the end txt file for none bash capable users?....So we can add it to the lists on the config page.

Or add this feature into pihole with on/off toggle....lets go a step further.
Lets combine forces and upload all individual found lists. Combine and reshare?

yes... i think this is a nice idea.
unsure how to collect all the different submissions, i do this with 3 friends of mine through rsync
anyone have any suggestions on how to combine or at least host the different files ( i can combine via scripts )

you are welcome to use the ones i use -
http://buffalo.biodome.org/m/youtube-ads-list.txt
and
http://buffalo.biodome.org/m/youtube-hosts-list.txt (hosts file format)

updated every 10 mins.... but like i mentioned before, currently there is an issue with the dnsdumpster.com website, it craps out on googlevideo.com - so files are very small/empty.

We (you:)) could create/change the/a script that copies/renames the local files to something with a random name and upload every 24 hours..? Combing => pihole -g
Good question: where to upload...making something open will result in chaos or abuse.

Hi.

Thanks for the files..

Are this the error you get???

root@Pi-Hole-Server:/etc/pihole# ./youtube-ads.sh
Unexpected status code from https://dnsdumpster.com/: 500
Traceback (most recent call last):
File "/etc/dnsdumpster/dnsdumpster/ADS_youtube.py", line 10, in
print(res['domain'])
TypeError: list indices must be integers, not str
grep: /var/log/pihole.log.1: No such file or directory
root@Pi-Hole-Server:/etc/pihole#

@taxick - yes - exactly
if you go to the http://dnsdumpster.com website and try to look at googlevideo.com that's the error code you will get (500)

edit : i modified the youtube ads script slightly to look at /var/log/pihole.log.1 and pihole.log.2.gz (running 2 days worth of youtube queries) - get a bit more in the resulting file, unsure that they change this daily...
but it seems to be working a little better for me.

Ok :slight_smile:

Hope http://dnsdumpster.com fix the error.

But again, thanks for the files.

OK, how can i do the same on my pi? IM really a noob.

Btw. Here is a list of youtube blocks: https://github.com/HenningVanRaumle/pihole-ytadblock

that github link is really dated, and not updated, it seems.
since they change those domains often, i do not use it. just sayin, ymmv.

as to the other entries - i added two lines to my shell script :
after this line ...
grep r*.googlevideo.com /var/log/pihole.log | awk '{print $6}'| grep -v
^googlevideo.com|redirector.googlevideo.com' | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt

added these two :
grep r*.googlevideo.com /var/log/pihole.log.1 | awk '{print $6}'| grep -v '^googlevideo.com|redirector.googlevideo.com' | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt
zgrep r*.googlevideo.com /var/log/pihole.log.2.gz | awk '{print $6}'| grep -v '^googlevideo.com|redirector.googlevideo.com' | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt

Thx for your reply.

Yes, I can see the list i posted is over 10 months old.

Removed the list again!