{"id":16431793,"url":"https://github.com/drkostas/youtube-firstcommentbot","last_synced_at":"2025-04-09T19:20:40.585Z","repository":{"id":39644520,"uuid":"158716181","full_name":"drkostas/Youtube-FirstCommentBot","owner":"drkostas","description":"A bot that post the first comment on every new video of specified channels.","archived":false,"fork":false,"pushed_at":"2024-02-05T13:03:23.000Z","size":206,"stargazers_count":227,"open_issues_count":4,"forks_count":32,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-02T09:46:57.621Z","etag":null,"topics":["bot","comment-bot","commenter","python","youtube-api","youtube-api-v3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drkostas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-22T15:09:09.000Z","updated_at":"2025-03-27T19:53:17.000Z","dependencies_parsed_at":"2023-12-07T21:27:26.921Z","dependency_job_id":"0c567a98-addd-4867-9b14-f6241c607e4c","html_url":"https://github.com/drkostas/Youtube-FirstCommentBot","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drkostas%2FYoutube-FirstCommentBot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drkostas%2FYoutube-FirstCommentBot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drkostas%2FYoutube-FirstCommentBot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drkostas%2FYoutube-FirstCommentBot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drkostas","download_url":"https://codeload.github.com/drkostas/Youtube-FirstCommentBot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094992,"owners_count":21046770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","comment-bot","commenter","python","youtube-api","youtube-api-v3"],"created_at":"2024-10-11T08:32:35.826Z","updated_at":"2025-04-09T19:20:40.562Z","avatar_url":"https://github.com/drkostas.png","language":"Python","funding_links":["https://www.buymeacoffee.com/drkostas"],"categories":[],"sub_categories":[],"readme":"# Youtube Comment Bot\n\n[![CircleCI](https://circleci.com/gh/drkostas/Youtube-FirstCommentBot/tree/master.svg?style=svg)](https://circleci.com/gh/drkostas/Youtube-FirstCommentBot/tree/master)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/drkostas/Youtube-FirstCommentBot/master/LICENSE)\n\u003ca href=\"https://www.buymeacoffee.com/drkostas\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"25\" \u003e\u003c/a\u003e\n\n## Table of Contents\n\n+ [About](#about)\n+ [Getting Started](#getting_started)\n    + [Prerequisites](#prerequisites)\n+ [Build and prepare the project](#build_prepare)\n    + [Install the requirements](#install)\n    + [Create the config files](#configs)\n    + [Specify the pool of comments](#comments_pool)\n    + [Start following channels](#add_channels)\n+ [Run the Bot](#commenter)\n+ [Gathering statistics about the comments](#accumulator)\n+ [Using Dropbox](#dropbox)\n+ [Deployment on Heroku](#heroku)\n+ [Continuous Ιntegration](#ci)\n+ [Todo](#todo)\n+ [Built With](#built_with)\n+ [License](#license)\n+ [Acknowledgments](#acknowledgments)\n\n## About \u003ca name = \"about\"\u003e\u003c/a\u003e\n\nA bot that leaves the first comment on every new video of specified channels.\n\n\u003cb\u003e\u003cu\u003eDISCLAIMER: This project is built for educational purposes. DO NOT use it to create spam-bots.\u003c/u\u003e\u003cb\u003e\n\nCurrent modules:\n\n- Commenter: Looks for new videos indefinitely and leaves a comment as soon as something is posted\n- Accumulator: Goes through all the comments posted and populates the `comments` table in the DB with\n  metadata such as the likes and replies count\n- List Channels: It lists the Channels that are currently followed by the bot\n- List Comments: It lists all the Comments posted by the bot\n- Add Channel: It adds a new channel to the following list\n- Set Priority: It set the comment priority of a specified channel\n- Refresh Photo: It gathers and populates the `channels` table in the DB with URLs to the Channels'\n  profile photos\n\n## Getting Started \u003ca name = \"getting_started\"\u003e\u003c/a\u003e\n\nThese instructions will get you a copy of the project up and running on your local machine for\ndevelopment and testing purposes. See deployment for notes on how to deploy the project on a live\nsystem.\n\n### Prerequisites \u003ca name = \"prerequisites\"\u003e\u003c/a\u003e\n\nYou need to have a machine with Python \u003e= 3.8 and any Bash-like shell (e.g. zsh) installed.\n\n```ShellSession\n\n$ python3.8 -V\nPython 3.8\n\n$ echo $SHELL\n/usr/bin/zsh\n\n```\n\nThis project requires a MySQL database and a YouTube API key. Optionally, you can also set up a Dropbox\nAPI key which is very useful when you use Heroku to deploy the bot.\n\nReferences:\n\n- YouTube: Use the Google API Console to create OAuth 2.0 credentials:\n    + Visit the [developer console](https://console.cloud.google.com/apis/dashboard)\n    + Create a new project\n    + Open the [API Manager](https://console.developers.google.com/apis/)\n      + Enable YouTube Data API v3\n    + Go to [Consent](https://console.cloud.google.com/apis/credentials/consent)\n      + Create a new OAuth client ID\n      + Configure the OAuth consent screen\n      + Use Type: External\n      + Provide a client name (e.g. YoutubeBot)\n      + Fill in the support email and developer contact information sections\n      + Click Continue and add the youtube.force-ssl scope\n      + Click Save and Continue again and go back to dashboard\n      + Click Publish App in the consent section (testing only lasts for 10 days)\n    + Go to [Credentials](https://console.cloud.google.com/apis/credentials)\n      + Type: Web Application\n      + Authorized Redirect URIs: http://localhost:8080/\n      + Copy Client ID and secret to the respective vars in your config file\n    + The first time you use the credentials the app will redirect you to a webpage\n      + Login with the Google account you used\n      + Click Advanced -\u003e \"Go to \u003cname\u003e (unsafe)\"\n      + Click Continue\n    + Your Credentials are set up!\n    + (*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.)\n- MySQL: If you don't have DB already, you can create one for free with Amazon RDS:\n  [Reference 1](https://aws.amazon.com/rds/free/),\n  [Reference 2](https://bigdataenthusiast.wordpress.com/2016/03/05/aws-rds-instance-setup-oracle-db-on-cloud-free-tier/)\n- Dropbox: How to set up an API key for your Dropbox account:\n  [Reference 1](http://99rabbits.com/get-dropbox-access-token/),\n  [Reference 2](https://dropbox.tech/developers/generate-an-access-token-for-your-own-account)\n\n## Build and prepare the project \u003ca name = \"build_prepare\"\u003e\u003c/a\u003e\n\nThis section will go through the installation steps, setting up the configuration files and comments,\nand preparing the DB tables.\n\n### Install the requirements \u003ca name = \"install\"\u003e\u003c/a\u003e\n\nAll the installation steps are handled by the [Makefile](Makefile). By default, it uses `conda`\nenvironments. If you want to use `virtualenv` instead, append to every `make` command the flag:\n`env=venv`. If you want to modify the name of the environment or use another python version, modify the\nfirst lines of the [Makefile](Makefile).\n\nDeactivate and active Conda environment, install the requirements and load the newly created\nenvironment:\n\n```ShellSession\n$ conda deactivate\n$ make install\n$ conda activate youbot\n```\n\n### Create the config files \u003ca name = \"configs\"\u003e\u003c/a\u003e\n\nThe project uses YML config files along with command-line arguments. There are three configs I am using:\n\n- [generic.yml](confs/generic.yml): Used for running the following commands:\n    - list_channels\n    - list_comments\n    - add_channel\n    - remove_channel\n    - refresh_photos\n    - set_priority\n- [commenter.yml](confs/commenter.yml): Used to run the `commenter` command\n  - One thing to bear in mind here is that the bot checks and comments only on videos not commented \n  yet. So  the first time your run it you don't want to comment on every single video in the past few \n  days. So make sure you set the `max_posted_hours` option to 1 and increase it the next days \n  if you want.\n- [accumulator.yml](confs/accumulator.yml): Used to run the `accumulator` command\n\nI am not going to go into depth for each available setting because you can use the three YML files as\ntemplates. The only thing that should be mentioned is that I am using environmental variables to set\nmost of the values. For example: `db_name: !ENV ${MYSQL_DB_NAME}`. You can replace\nthe `!ENV ${MYSQL_DB_NAME}`\npart with the actual value, for example: `db_name: My_Database`. For more details on how to use env\nvariables check [these instructions](https://pypi.org/project/yaml-config-wrapper/).\n\n### Specify the pool of comments \u003ca name = \"comments_pool\"\u003e\u003c/a\u003e\n\nNow, you don't want the bot to post the same comment over and over again. For that reason, I am using a\npool of available comments, and the bot automatically picks one that hasn't been commented on to the\nrespective channel yet, otherwise, it picks the one that was posted the longest time ago. Just create\na `default.txt` file in a folder named `comments` and write one comment per line. If, for a specific\nchannel, you want to have additional comments, create another txt file named after the channel's id.\nFor example, you can create a `UC-ImLFXGIe2FC4Wo5hOodnw.txt` for the Veritasium YT channel that \nhas that id.\n\n### Start following channels \u003ca name = \"add_channels\"\u003e\u003c/a\u003e\n\nWe are now ready to add YT channels to our following list (stored in the DB). After ensuring you are in\nthe Conda environment, use the following command to add channels:\n\nUsing the channel ID\n\n```ShellSession\n$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m add_channel -i \u003cchannel id\u003e\n```\n\nUsing the channel username (Fails most of the time)\n\n```ShellSession\n$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m add_channel -u \u003cchannel username\u003e\n```\n\nTo view the followed channels run:\n\n```ShellSession\n$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m list_channels\n```\n\nSimilarly, to remove a channel run:\n```ShellSession\n$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m remove_channel -i \u003cchannel id\u003e\n```\n\nThere is also the option to set the priorities of each channel. If 2 or more channels post videos at\nthe same time, the bot will leave comments first to the ones with the highest priority value. To do so\nrun the following:\n\n```ShellSession\n$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m set_priority --priority \u003cpriority num\u003e -i \u003cchannel id\u003e\n```\n\nAfter you're done, you can optionally populate the table with each channel's profile picture:\n\n```ShellSession\n$ python youbot/run.py -c confs/generic.yml -l logs/generic.log -m refresh_photos\n```\n\n## Run the Bot \u003ca name = \"commenter\"\u003e\u003c/a\u003e\n\nNow we are ready to run the commenter module of the bot. Assuming you set up the channels, created the\nconfiguration, and you have the comments ready, run the following command:\n\n```ShellSession\npython youbot/run.py -c confs/commenter.yml -l logs/commenter.log -m commenter\n```\n\nThe bot will then run indefinitely until you stop it.\n\nYou can view all the comments posted at any point with the following command:\n\n```ShellSession\npython youbot/run.py -c confs/generic.yml -l logs/generic.log -m list_comments --n-recent 10\n```\n\n## Gathering statistics about the comments \u003ca name = \"accumulator\"\u003e\u003c/a\u003e\n\nNow that the bot is running, you probably want to gather statistics about the comments such as the\nnumber of likes and replies. There is another bot for that job, that also runs indefinitely and\nconstantly updates the data in the `comments` table. To start it run the following command:\n\n```ShellSession\npython youbot/run.py -c confs/accumulator.yml -l logs/accumulator.log -m accumulator\n```\n\n## Using Dropbox \u003ca name = \"dropbox\"\u003e\u003c/a\u003e\n\nThere is the option to also incorporate dropbox in the whole pipeline. Assuming you already created an\nAPI key and added a cloudstore section in the config, you can use the following options:\n\n- `load_keys_from_cloud: true` (under youtube config): If set to true, the bot will automatically copy\n  the JSON keys from the defined `keys_folder_path` setting (in cloudstore config) to the defined\n  `keys` setting (in youtube config). This is very useful if you deploy the bot to Heroku which is\n  stateless and any newly created file can be deleted anytime. So you may have to manually recreate the\n  keys.\n- `upload_logs_every: 15` (under cloudstore config): If you configured the cloudstore config for the\n  commenter, then the bot will automatically copy the log file to the cloudstore `logs_folder_path`\n  every 15 `While: True` loops in the commenter function. Again, very useful for keeping the logs while\n  running on Heroku.\n- `comments: type: dropbox`: If you set the type of the `comments` setting as `dropbox` then the\n  commenter will download the comment txt files from `dropbox_folder_name` into `local_folder_name`\n  before every `While: True` loop in the commenter. Useful for modifying the comments when running on\n  Heroku.\n\n## Deployment on Heroku \u003ca name = \"heroku\"\u003e\u003c/a\u003e\n\nThe deployment is being done to \u003cb\u003eHeroku\u003c/b\u003e. For more information, you can check\nthe [setup guide](https://devcenter.heroku.com/articles/getting-started-with-python).\n\nMake sure you check the defined [Procfile](Procfile)\n([reference](https://devcenter.heroku.com/articles/getting-started-with-python#define-a-procfile))\nand that you set the appropriate environmental variables\n([reference](https://devcenter.heroku.com/articles/config-vars)).\n\n## Continuous Integration \u003ca name = \"ci\"\u003e\u003c/a\u003e\n\nFor the continuous integration, the \u003cb\u003eCircleCI\u003c/b\u003e service is being used. For more information, you can\ncheck the [setup guide](https://circleci.com/docs/2.0/language-python/).\n\nAgain, you should set the appropriate environmental variables \n([reference](https://circleci.com/docs/2.0/env-vars/#setting-an-environment-variable-in-a-context))\nand for any modifications, edit the [circleci config](/.circleci/config.yml).\n\n## TODO \u003ca name = \"todo\"\u003e\u003c/a\u003e\n\nRead the [TODO](TODO.md) to see the current task list.\n\n## License \u003ca name = \"license\"\u003e\u003c/a\u003e\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrkostas%2Fyoutube-firstcommentbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrkostas%2Fyoutube-firstcommentbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrkostas%2Fyoutube-firstcommentbot/lists"}