YouTube script seems to be working very well


sudo -i 

enter password 

cd /usr/local/bin

nano youtube.update.sh

paste the text from script and change IP

crtl x, yes to save

than: chmod a+x youtube.update.sh


./youtube.update.sh


pihole restartdns

thats it!








Thank you for your help. Looks like I'm blocking 144 YouTube URL's so far.

Glad it works for your users.

I haven’t had time over the weekend to merge in IPv6 or other functionality but hope to soon.

FWIW, I have a different method that seems to work better (only the very odd per-roll slips through), but it’s based on OpenBSD and pf. So it needs a different OS and it works down at the network layer.

Cheers!

It doesn't block, it redirects. :slight_smile:

Online lookup isn't optimal. Doing it locally will get you a geo-ip'd address closest to you (network-wise)

I was able to get the IP from using this command on my Raspberry Pi.

First of all - THANK you for finding this.

However, I'm still having some trouble.

What I did:

  • opened a YT video on my iPhone with the YouTube app which shows an ad in the beginning
  • grabbed the googlevideo string from PiHole log, ran nslookup on it and extracted the IPv4 and IPv6.
  • navigated to /usr/local/bin and created the youtube.update.sh with the following content:
#deleted the initial stuff to keep this post short
forceIP="172.217.132.10"
#added for ipv6
forceIP6="2a00:1450:400e:4::a"
# nothing below here should need changing

piLogs="/var/log/pihole.log"
ytHosts="/etc/hosts.youtube"

workFile=$(mktemp)
dnsmasqFile="/etc/dnsmasq.d/99-youtube.grublets.conf"

if [ ! -f $dnsmasqFile ]; then
    echo "addn-hosts=$ytHosts" > $dnsmasqFile
    touch $ytHosts
    piLogs="$piLogs*" # preload with results from all logs
    echo "Setup complete! Execute 'pihole restartdns' as root."
    echo "cron the script to run every minute or so for updates."
fi

cp $ytHosts $workFile
zgrep -e "reply.*-.*\.googlevideo.*\..*\..*\..*" $piLogs \
    | awk -v fIP=$forceIP '{ print fIP, $6 }' >> $workFile
#this section added for ipv6
zgrep -e "$forceIP" $workFile \
    | awk -v fIP6=$forceIP6 '{ print fIP6, $2 }' >> $workFile

sort -u $workFile -o $workFile

if ! cmp $workFile $ytHosts; then
    mv $workFile $ytHosts
    chmod 644 $ytHosts
    /usr/local/bin/pihole restartdns reload
else
    rm $workFile
fi


exit
  • ran the script, restarted the PiHole DNS
  • added the script to crontab
* * * * * /usr/local/bin/youtube.update.sh 2>&1

When I now open the YT video, the ads are skipped but the video doesn't load anymore. I checked the PiHole log and saw that s.youtube.com was blocked (??) but even whitelisting that didn't fix it.

What did I do wrong? :frowning: Thank you!

Use the query lists tool to see where it was blocked.

All were blocked on the iPhone. The behavior is totally random:
It:

  • either works fine and shows no ads
  • misses the ads completely, shows all ads and the video
  • already fails loading the ad (still shows Ad - 1 of 2) and gets stuck there

All with the the same two videos.

In the PiHole log, I can see it's blocking this for example:
image

None of those should be blocked. Are you using the script from the Gitlab page?

Yes, I took your script and just added the IPv6 pieces from this reply here:

Could it be the case that my ForceIP is actually directing to a video server?

The IPs are video and ads. What the hosts file does is prevent jumping to an IP where an "ad gun" is likely to be waiting for you to arrive. If you are seeing those IPs being blocked, then something messed up somewhere. Try cleaning out the hosts.youtube file and starting over.

I don't know how the IPv6 stuff in that comment is working, I have something else similar in the works.

Thanks! When can we expect your IPv6 solution, if it's okay to ask? I'm running a DS, so IPv4-only will not really block everything. :frowning:

EDIT: Okay, this is embarrassing. I found the issue. It was a blocklist that was colliding actually. I deleted the list and reinstalled your script with the IPv6 extensions and it's working fine. :slight_smile:

Very soon. I don't want to pour too much time into this as it should be easy for YT to swat this down.

The same will work on 5.0? I want to update to 5.0 today and the procedure would be the same to install/use this?

Also someone could comment on how this will affect the performance of the lookup if used on a RPi 3B?
I have a lot of blaclisted hosts and a full gravity update blocks the RPi for 2-3 minutes... I know this just only reloads the dns, but I don't know how an RPi can handle this.

Thanks!

It still works on 5.0 I can confirm. Just upgraded from 4.3 to 5.0 on my RPI 3B. 5.0 is so much quicker compared to 4.3, amazing. I use the RPI 3B as secondary DNS. I will upgrade my primary RPI 2B somewhere this week if no major bugs are found. Both RPI's are running this really nice youtube script.

@grublets We're going to ask people to use your GitLab issues to discuss this customization. Discourse is not good for monothreads and multiple topics.

1 Like

@DanSchaper Fantastic idea, thanks. I'm already too spread out as it is, I'll do the same thing in the Reddit post. Real Work suffers.

1 Like

Please use Issues · grub / YouTube updater for Pi-hole · GitLab for further discussion on this topic.