Simple Telegram Bot to Upload videos to Youtube written in Python3.
This is a simple hobby project which I was really curious about to implement. I Ankit Kumar have recently modified the code, incorporating additional functions, commands, and ensuring compatibility with the latest versions of libraries.
The project involves the development of a Telegram bot utilizing the Youtube Data API v3. The primary purpose of the bot is to facilitate the seamless uploading of videos to YouTube.
For more details about the original project, you can refer to the GitHub repository.
Note: The modifications made to the code aim to enhance its functionality and ensure compatibility with the most recent library versions.
STEP : 1 Clone the git repository with Runing :
git clone https://github.com/odysseusmax/utube.git
STEP : 2 Go to the repository directory.
cd utube
Now set Environment Variables in root folder with .env file.
STEP : 3 Create environment file to save environments.
cp .env.sample .env
Add the following lines to it, replacing API_ID
, API_HASH
, BOT_TOKEN
,CLIENT_ID
,CLIENT_SECRET
,BOT_OWNER
,AUTH_USERS
,UPLOAD_MODE
& VIDEO_CATEGORY
;
.env File Example:
BOT_TOKEN="YOUR_BOT_TOKEN_HERE"
SESSION_NAME="your_session_name_here"
API_ID="your_api_id_here"
API_HASH="your_api_hash_here"
CLIENT_ID="your_client_id_here"
CLIENT_SECRET="your_client_secret_here"
BOT_OWNER="your_bot_owner_user_id_here"
AUTH_USERS="comma_separated_list_of_user_ids"
VIDEO_DESCRIPTION="This video is uploaded from telegram bot (example)"
VIDEO_CATEGORY="your_video_category_id_here(specific if you needed)"
UPLOAD_MODE="your_upload_mode_here"
BOT_TOKEN
(Required) - Get your bot token from Bot Father.SESSION_NAME
(optional) - Your bot's username.API_ID
(Required) - Your telegram api id, get from Manage Apps.API_HASH
(Required) - Your telegram api hash, get from Manage Apps.CLIENT_ID
(Required) - Your google client id.CLIENT_SECRET
(Required) - Your google client secret.BOT_OWNER
(Required) - Telegram id of bot owner.AUTH_USERS
(optional) - Telegram id's of authorised users, separated by,
.VIDEO_DESCRIPTION
(optional) - Any default description to be aded to the video.VIDEO_CATEGORY
(optional) - YouTube's video category id. If not specified or specified id is invalid, category id will be selected randomly.VIDEO_TITLE_PREFIX
(optional) - Any prefix to be added to the video's title.VIDEO_TITLE_SUFFIX
(optional) - Any suffix to be added to the video's title.UPLOAD_MODE
(optional) - The video's privacy status. Valid values for this property are:private
,public
,unlisted
.DEBUG
(optional) - Whether to set logging level to DEBUG. If set logging will be set to DEBUG level, else INFO level.
Getting your CLIENT_ID
and CLIENT_SECRET
Certainly! To obtain the CLIENT_ID
and CLIENT_SECRET
for the YouTube Data API v3 from the Google Cloud Console, you can follow these steps:
- Open the Google Cloud Console.
- Click on the project drop-down menu at the top of the page and select New Project.
- Enter a name for your project - 'Youtube Uploader' and click Create.
- In the Google Cloud Console, navigate to the APIs & Services Dashboard.
- Click on + ENABLE APIS AND SERVICES.
- Search for "YouTube Data API v3" and select it.
- Click Enable.
- In the Google Cloud Console, navigate to the Credentials page.
- Click Create Credentials and select OAuth client ID.
- Choose Web Application as the application type.
- Enter a name -
Youtube Uploader
for your OAuth client. - Click Create.
- After creating the OAuth client, you will see a pop-up with your
CLIENT_ID
andCLIENT_SECRET
. It will also be available on the Credentials page under the "OAuth 2.0 Client IDs" section. - Copy the
CLIENT_ID
andCLIENT_SECRET
and store them securely. - Configure your application with this authorized redirect URIs
https://gogoauth.vercel.app
.
- On the Credentials page, click on the OAuth consent screen tab.
- Fill in the necessary information, including the Scopes required for your application.
- Save the changes.
Now you have obtained the CLIENT_ID
and CLIENT_SECRET
for the YouTube Data API v3. Include these credentials in your application code securely. Make sure to follow best practices for handling API keys and secrets to keep your application secure.
Activate Python virtual Environment
python3 -m venv venv
Go to Venv
source venv/bin/activate
Install requirements
pip3 install -r requirements.txt
Run bot
Lets run our bot for the first time!
python3 -m bot
If you did everything correctly, the bot should be running. Go do /start
to see if the bot is live or not. Follow the instructions provided by bot to setup authorisation and to start uploading.
-
Public Git Repository:
- Add this public Git repository URL:
https://github.com/odysseusmax/utube.git
- Add this public Git repository URL:
-
Name Your Service:
- Provide a name for your service.
- In the "Advanced" tab, add a secret file named
.env
with all required environment variables.
-
Create Web Service:
- Set up your web service configuration.
-
Wait for Deployment:
-
Configure Cron Job:
- Copy the deployed website URL.
- Create an account on CRON JOB if you haven't already.
- Create a new cron job, providing a title and pasting your website URL.
- Click on CREATE or firstly, test run the cron job and then Create.
Notes:
- Your bot is now live 24/7.
- A cron job is set up to address Render's free service limitations, which may cause the service to stop every 15 minutes.
🚀 Active Development: I am currently actively working on this project, implementing new features, fixing issues, and making continuous improvements. Your contributions and feedback are always welcome!
-
With the Youtube Data API you are awarded with 10,000 points of requests. For one video upload it costs 1605 points, regardless of file size, which calculates to about 6 uploads daily. Once you have exhausted your daily points, you have to wait till daily reset. Resets happens at 0:00 PST, i.e. 12:30 IST. So make your uploads count.
-
Uploading copyright contents will leads to immediate blocking of the video.
-
By default, all the videos are uploaded as private with random category id unless you provide
UPLOAD_MODE
andVIDEO_CATEGORY
. You may change it after youtube processes the video.
Edit the bot in BotFather with command /help
⮞ /mybots
⮞ choose your bot by the username ⮞ click on Edit bot ⮞ click on edit commands ⮞ copy the below code and paste there and save it.
start - Start the bot.
login - Log in to the bot
upload - Initiate the upload process of video
help - Get assistance or command information
logout - Log out from the bot
refresh - Refresh or update auth token
Visit Demo BotExample.md
Here's a YouTube tutorial video for deploying the bot on Heroku. Video Link.
-
Feel free to reach out to me on Telegram: @odysseusmax.
Code released under GNU General Public License v3.0.