• Stars
    star
    121
  • Rank 293,924 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A bot that post the first comment on every new video of specified channels.

Youtube Comment Bot

CircleCI GitHub license Buy Me A Coffee

Table of Contents

About

A bot that leaves the first comment on every new video of specified channels.

DISCLAIMER: This project is built for educational purposes. DO NOT use it to create spam-bots.

Current modules:

  • Commenter: Looks for new videos indefinitely and leaves a comment as soon as something is posted
  • Accumulator: Goes through all the comments posted and populates the comments table in the DB with metadata such as the likes and replies count
  • List Channels: It lists the Channels that are currently followed by the bot
  • List Comments: It lists all the Comments posted by the bot
  • Add Channel: It adds a new channel to the following list
  • Set Priority: It set the comment priority of a specified channel
  • Refresh Photo: It gathers and populates the channels table in the DB with URLs to the Channels' profile photos

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You need to have a machine with Python >= 3.8 and any Bash-like shell (e.g. zsh) installed.

$ python3.8 -V
Python 3.8

$ echo $SHELL
/usr/bin/zsh

This project requires a MySQL database and a YouTube API key. Optionally, you can also set up a Dropbox API key which is very useful when you use Heroku to deploy the bot.

References:

  • YouTube: Use the Google API Console to create OAuth 2.0 credentials:
    • Visit the developer console
    • Create a new project
    • Open the API Manager
      • Enable YouTube Data API v3
    • Go to Consent
      • Create a new OAuth client ID
      • Configure the OAuth consent screen
      • Use Type: External
      • Provide a client name (e.g. YoutubeBot)
      • Fill in the support email and developer contact information sections
      • Click Continue and add the youtube.force-ssl scope
      • Click Save and Continue again and go back to dashboard
      • Click Publish App in the consent section (testing only lasts for 10 days)
    • Go to Credentials
      • Type: Web Application
      • Authorized Redirect URIs: http://localhost:8080/
      • Copy Client ID and secret to the respective vars in your config file
    • The first time you use the credentials the app will redirect you to a webpage
      • Login with the Google account you used
      • Click Advanced -> "Go to (unsafe)"
      • Click Continue
    • Your Credentials are set up!
    • (Warning: The default quota limit per day is around 10,000 which is only enough for having 2 channels. You should request a quota increase if you want more.)
  • MySQL: If you don't ha DB already, you can create one for free with Amazon RDS: Reference 1, Reference 2
  • Dropbox: How to set up an API key for your Dropbox account: Reference 1, Reference 2

Build and prepare the project

This section will go through the installation steps, setting up the configuration files and comments, and preparing the DB tables.

Install the requirements

All the installation steps are handled by the Makefile. By default, it uses conda environments. If you want to use virtualenv instead, append to every make command the flag: env=venv. If you want to modify the name of the environment or use another python version, modify the first lines of the Makefile.

Deactivate and active Conda environment, install the requirements and load the newly created environment:

$ conda deactivate
$ make install
$ conda activate youbot

Create the config files

The project uses YML config files along with command-line arguments. There are three configs I am using:

  • generic.yml: Used for running the following commands:
    • list_channels
    • list_comments
    • add_channel
    • remove_channel
    • refresh_photos
    • set_priority
  • commenter.yml: Used to run the commenter command
    • One thing to bear in mind here is that the bot checks and comments only on videos not commented yet. So the first time your run it you don't want to comment on every single video in the past few days. So make sure you set the max_posted_hours option to 1 and increase it the next days if you want.
  • accumulator.yml: Used to run the accumulator command

I am not going to go into depth for each available setting because you can use the three YML files as templates. The only thing that should be mentioned is that I am using environmental variables to set most of the values. For example: db_name: !ENV ${MYSQL_DB_NAME}. You can replace the !ENV ${MYSQL_DB_NAME} part with the actual value, for example: db_name: My_Database. For more details on how to use env variables check these instructions.

Specify the pool of comments

Now, you don't want the bot to post the same comment over and over again. For that reason, I am using a pool of available comments, and the bot automatically picks one that hasn't been commented on to the respective channel yet, otherwise, it picks the one that was posted the longest time ago. Just create a default.txt file in a folder named comments and write one comment per line. If, for a specific channel, you want to have additional comments, create another txt file named after the channel's id. For example, you can create a UC-ImLFXGIe2FC4Wo5hOodnw.txt for the Veritasium YT channel that has that id.

Start following channels

We are now ready to add YT channels to our following list (stored in the DB). After ensuring you are in the Conda environment, use the following command to add channels:

Using the channel ID

$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m add_channel -i <channel id>

Using the channel username (Fails most of the time)

$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m add_channel -u <channel username>

To view the followed channels run:

$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m list_channels

Similarly, to remove a channel run:

$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m remove_channel -i <channel id>

There is also the option to set the priorities of each channel. If 2 or more channels post videos at the same time, the bot will leave comments first to the ones with the highest priority value. To do so run the following:

$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m set_priority --priority <priority num> -i <channel id>

After you're done, you can optionally populate the table with each channel's profile picture:

$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m refresh_photos

Run the Bot

Now we are ready to run the commenter module of the bot. Assuming you set up the channels, created the configuration, and you have the comments ready, run the following command:

python youbot/run.py -c confs/commenter.yml -l logs/commenter.log -m commenter

The bot will then run indefinitely until you stop it.

You can view all the comments posted at any point with the following command:

python youbot/run.py -c confs/generic.yml -l logs/generic.log -m list_comments --n-recent 10

Gathering statistics about the comments

Now that the bot is running, you probably want to gather statistics about the comments such as the number of likes and replies. There is another bot for that job, that also runs indefinitely and constantly updates the data in the comments table. To start it run the following command:

python youbot/run.py -c confs/accumulator.yml -l logs/accumulator.log -m accumulator

Using Dropbox

There is the option to also incorporate dropbox in the whole pipeline. Assuming you already created an API key and added a cloudstore section in the config, you can use the following options:

  • load_keys_from_cloud: true (under youtube config): If set to true, the bot will automatically copy the JSON keys from the defined keys_folder_path setting (in cloudstore config) to the defined keys setting (in youtube config). This is very useful if you deploy the bot to Heroku which is stateless and any newly created file can be deleted anytime. So you may have to manually recreate the keys.
  • upload_logs_every: 15 (under cloudstore config): If you configured the cloudstore config for the commenter, then the bot will automatically copy the log file to the cloudstore logs_folder_path every 15 While: True loops in the commenter function. Again, very useful for keeping the logs while running on Heroku.
  • comments: type: dropbox: If you set the type of the comments setting as dropbox then the commenter will download the comment txt files from dropbox_folder_name into local_folder_name before every While: True loop in the commenter. Useful for modifying the comments when running on Heroku.

Deployment on Heroku

The deployment is being done to Heroku. For more information, you can check the setup guide.

Make sure you check the defined Procfile (reference) and that you set the appropriate environmental variables (reference).

Continuous Integration

For the continuous integration, the CircleCI service is being used. For more information, you can check the setup guide.

Again, you should set the appropriate environmental variables (reference) and for any modifications, edit the circleci config.

TODO

Read the TODO to see the current task list.

License

This project is licensed under the MIT License - see the LICENSE file for details.

More Repositories

1

Minecraft-AI

A Reinforcement Learning agent that learns how to to solve maze missions in Minecraft.
Python
195
star
2

drkostas.github.io

VScode Portfolio
JavaScript
105
star
3

3D-Semantic-Segmentation

Semantic Segmentation with Transformers on 3D Medical Images
Jupyter Notebook
57
star
4

drkostas

53
star
5

Insta-Likes-Predict

First attempt on predicting the likes a photo will get on Instagram.
Python
42
star
6

JobApplicationBot

A bot that automatically sends emails to new ads posted in any desired xe.gr search url.
HTML
25
star
7

TuneCraft

Effortlessly create personalized Spotify playlists with fresh, undiscovered tracks tailored to your taste, by checking all your liked songs and existing playlists to provide you with truly new music.
Python
19
star
8

SpotiClick

An app that clicks a physical button whenever Spotify starts playing on the target device.
Python
18
star
9

Numpy-CNN

A Vanilla Numpy-only Convolutional Neural Network.
Python
16
star
10

HGN

Hybrid Girvan Newman. Code for the "A Distributed Hybrid Community Detection Methodology for Social Networks" paper.
Python
15
star
11

high-sql

A high-level sql command utility. Currently only MySQL is supported.
Python
12
star
12

Numpy-NeuralNet-1

A Vanilla Numpy-only Feed-Forward Neural Network.
Python
9
star
13

OnDemandMinecraft-Mirrored

An AWS hosted Minecraft server that will only run when players are active. Players can start the server through a simple UI accessed through free Heroku server hosting. Mirrored from the fork: https://github.com/drkostas/OnDemandMinecraft
Python
9
star
14

Pong-Q-Learning

Using Q-learning to beat a Pong game program
Jupyter Notebook
7
star
15

Cross-The-Floor

Uses Sankey Diagrams to visualize politicians that have "crossed the floor" from election to election.
HTML
7
star
16

pyemail-sender

A utility for sending emails with attachments. Currently only Gmail is supported.
Python
7
star
17

LSTMs-Training-Demo

RNNs and LSTMs
PureBasic
6
star
18

EESTech-BigData-Challenge

EESTech Challenge is a brand new competition organized by EESTEC, that has the aim to create opportunities for European students to gain knowledge in the field of EECS and develop a professional network. The technological topic of 2017-2018ths competition was Big Data. This is the code I sumbitted with my team (BFS), which consisted of 3 members in total.
Jupyter Notebook
6
star
19

Machine-Learning-Algorithms

Code for the Machine Learning Course (COSC-522) of the UTK.
Jupyter Notebook
5
star
20

Quantum-Mechanics-Quiz-App

Android app with 10 questions about Quantum Mechanics.
Java
5
star
21

bench-utils

A collection of benchmarking tools.
Python
4
star
22

shooter-game-with-p5js

Simple 2d shooter game written with JavaScript and the p5.js library.
JavaScript
4
star
23

covid19-vaccinations-predict

Simultaneous Time Series Forecasting on the global COVID-19 Daily Vaccinations
Jupyter Notebook
4
star
24

yaml-config-wrapper

A YAML configuration wrapper.
Python
3
star
25

Tensorflow-Training-Demo

Project 3 for the Deep Learning course (COSC 525). Training various networks with Tensorflow.
PureBasic
3
star
26

cloud-filemanager

A high-level filemanager utility for cloud services. Currently only Dropbox is supported.
Python
2
star
27

multi-docker-course

Part of a Docker Course.
JavaScript
2
star
28

python_search_engine

This is a search engine created for the Gutenberg Project archive. It is implemented in python and the front end part is created with the flask framework.
HTML
2
star
29

Bayesian-Statistics-Algorithms

Code for the Assignments of the Statistics I Course (MATH-525) of the UTK.
Jupyter Notebook
2
star
30

RL-Value-Iteration

Implementation of value iteration algorithm for calculating an optimal MDP policy.
Jupyter Notebook
1
star
31

termcolor-logger

A logger with text formatting using termcolor.
Python
1
star
32

Scripts

I will be saving here my scripts in various languages for future use and improvements.
PHP
1
star
33

multi-kubernetes-course

JavaScript
1
star
34

tda_examples

Exploratory code on topological data analysis
HTML
1
star
35

Data-Science-Methods

A playground repo for the DSE-512 course
Jupyter Notebook
1
star