← Back to Guides
Profile image for Tom Snelling
Published 27th June 2022

Deploy YT-Spammer-Purge to automatically remove spam comments on your YouTube videos

YT-Spammer-Purge is an open source Python tool that can detect and delete spam comments on YouTube videos. It can be run locally as an executable, but in this guide we will demonstrate how to deploy it as a cron job on Northflank to run automatically on a schedule to keep your videos spam free.

Generate an API key

The first thing you will need is a YouTube API key, so that the YT-Spammer-Purge tool can interact with your channel and videos. The GitHub repo provides a how to guide on doing this, so follow all of the steps there to generate your credentials first.

Install locally and generate config files

The next step is to generate the config files you will need to run the tool on Northflank. To do this, you will need to install YT-Spammer-Purge locally on your own computer. If you are on Windows, you can download the latest .exe file from the releases page. If you are on macOS or Linux, then you can follow the installation instructions on the wiki.

Once you have installed the tool locally, copy your downloaded YouTube credentials and place them in the same directory, in a file named client_secrets.json. Once you’ve done that, run the tool and it will take you through the Google OAuth login process. You will then be presented with the main menu, where you can select option 6 to generate config files. When this is done, you can exit the program.

Screenshot 2022-06-22 at 11.48.50.png

Modify config to run autonomously

By default, the tool will require you to enter things like channel, video(s), mode etc. each time it is run. But this is no good if we want it to run automatically in the background — so we need to modify some configuration values to tell the tool exactly what we want it to do. In the SpamPurgeConfig.ini file that was generated in the previous step, update the following values:

[config-meta]
use_this_config = True

[general]
your_channel_id = <CHANNEL ID HERE>
auto_close = True

[scanning]
scan_mode = EntireChannel
max_comments = 1000
channel_to_scan = Mine

[filtering]
filter_mode = AutoSmart

[removal]
delete_without_reviewing = True

It may be easiest to Ctrl+f/Cmd+f to find the values you need to change. The section labels are displayed above so that the required values are easier to find.

You can tweak other values if you want the tool to behave differently. In this configuration, it will look at recent comments across all of your videos. However you can tell it to look at specific videos, only your recent videos, or many other options. For the full list of config options, see the ‘config file settings’ page.

Bear in mind that all of the options you choose must allow the tool to run without your input — setting any options to Ask will mean that it cannot run autonomously as it will be awaiting your input before it can run.

Create your job

In a new Northflank project, select ‘Create new’ at the top of the screen and choose ‘Job’. Once on the job creation form, select ‘cron’ as the type if you want your job to run automatically on a schedule, or ‘manual’ if you want the program to run only when you tell it to.

Give your job a sensible name, and if you selected cron, set the job schedule. Depending on the amount of traffic and comments your videos receive, you might want to run the tool once a day, once a week, or once a month. Just be aware that API limits apply — you can read more about them on the YT-Spammer-Purge wiki.

When you get to the ‘job source’ section, select external image and enter ghcr.io/thiojoe/yt-spammer-purge:latest. This is the public Docker image for the YT-Spammer-Purge tool.

Finally, select a plan. We recommend at least nf-compute-50 to run the tool smoothly. Hit the ‘create job’ button to finish.

app.salvo.sh_u_tdjsnelling_project_spam-remover_create_job.png

Add config files

You will be taken to your newly created job. In the left hand menu, select ‘Environment’ and scroll down to see the ‘secret files’ section.

You will need to add 3 files:

  • /usr/src/app/SpamPurgeConfig.ini
  • /usr/src/app/client_secrets.json
  • /usr/src/app/token.pickle

For each of these, click ‘add file’, enter the mount path as you see it above, and use the ‘import from file’ button to upload the 3 config files, which will all be in the same directory you ran the YT-Spammer-Purge tool in earlier.

Screenshot 2022-06-21 at 16.36.26.png

Conclusion

Now that your config files are added, you should be good to go! You can manually run your job using the play button in the job header, or if you have created a cron job you can wait for the schedule to trigger the job automatically. When the job runs, you can view the running container and see the log output, where the tool will tell you how many spam comments it has detected and deleted.

Share this article with your network
X