Python creates a fully automatic and profitable Youtube video publishing system with monthly revenue of over 10,000 (passive revenue)

Preface

This article will show you how to use Python to build a system that automatically publishes YouTube videos and offers special benefits in US dollars.

image

Python builds automatic Youtube channel system earns over $2,000 per month (passive income)

At present, the system I use has basically been running stably for three months. It only took one month for one of the YouTube channels to reach the minimum threshold of opening profits from scratch. The day before yesterday, I successfully opened the Adsense account and put in video advertisements. Today, the advertising revenue on the first day of viewing the channel is about $90. Calculated based on this benchmark value, there are about 18,000 Earnings per month.

image

Basically, manual intervention is not required in the production, uploading, publishing, and earning of the entire video. The whole system runs in full-automatic mode, and only needs to be fixed when bugs occur. For example, due to the opening of advertising revenue recently, the program module responsible for uploading needs to be adjusted, which took me three or four hours before and after, but this is also a sweet worry (in the words of one of my friends).

The copyright of this article belongs to the original Zhihu author. @李南瓜 All, since the original author has deleted all the articles under the Observer column of Zhihu project including the public account project operated by himself, this article exists as a backup, saluting to the Great God! At present, this article cannot be searched, and its original author was suspected to be criticized by netizens, so all published contents were deleted.

image
image

Remarks:

  • This article does not include the complete code implementation, only for sharing ideas
  • This system is for personal use only, not for sale, not for rent, not for the development of similar systems
  • I don't accept apprentices, leave no contact information, no group, no charged courses
  • I only share knowledge, but I have no obligation to answer any of your personal questions.

If you can accept all of the above prerequisites, then we can officially start the journey of building the system of automatically earning dollars.

Technology stack

  • Programming Language: Python 3
  • Server: Google Cloud Platform
  • Database: Firestore
  • Program hosting: Github and Google Cloud Source Repositories
  • Automatic task scheduling: Cloud Scheduler
  • Third-party libraries and software: FFmpeg, Requests, PIL, and Selenium
  • IM: Telegram

System function module decomposition

A system that automatically publishes YouTube videos generally needs to include the following modules, which may vary depending on the category and raw materials you choose.

Task Assignment Module

Raw image, audio, and video material extraction and production module

YouTube video Upload module

Automatic server deployment module

Program running result notification module

Automatic Program Update module

Next, we will explain each module one by one.

Task Assignment Module

For a system that automatically produces and uploads videos, the first step of the whole system operation is that the system needs to know from which task it needs to start.

For a simple task system, if the entire task is a linearly increasing task ID, the task allocation module is equivalent to a database field with an auto-increment ID.

For a real task allocation module, it must be more complicated than this, but the core is to tell the program which task to perform next.

Because the whole system is basically built on the powerful and easy-to-use Google Cloud Platform (GCP) Platform, I directly use the NoSQL database on the GCP Platform in the task allocation module: Cloud Firestore.

What is Cloud Firestore?

Use Firestore official website to make a brief introduction:

Cloud Firestore is a NoSQL document database that allows you to easily store, synchronize, and query data of your mobile applications and Web applications worldwide.

I use Firestore to do many things. In the task assignment module, you only need to create a dedicated Collection and the Document corresponding to each tag, such as the following demo.

It contains three Document: counter, task, and taskID. The status value in the task Document is set to on, indicating that the current task status is executable. If a task is completed at a certain stage or a serious bug needs to be manually fixed, this value is set to off.

taskID is a temporary Document added only for demonstration. In fact, the task allocation module is in another dedicated Collection, which is much more complex, but the core is the same.

The specific execution process of the task assignment module is as follows:

  • The program reads the status value in the task document. If the value is on, the task continues. If the value is off, the program exits directly and sends a notification message.
  • The program randomly extracts a taskID document, parses the task ID to be executed, and parses it into the original material URL to be downloaded according to certain rules.
  • After the program successfully uploads a YouTube video in subsequent actions, update the task ID in taskID.
  • When the number of tasks reaches online within a certain period of time, set the task Wen Dangzhong status to off.

Video production module

Unlike most other people, my goal is to realize automatic video production and uploading without manual participation in the whole process, therefore, this premise makes me directly abandon the types of videos that cannot be generated by programs, such as selfie explanation, real-life shooting, film and television editing, etc.

Here, take the video production of one of my own channels as an example. The process of automatically generating videos by using the program is as follows:

1. Download the original audio MP3 materials

2. Make a cover picture

3. Use audio MP3 and thumbnail programs to automatically produce a complete video

Download MP3 material

You can use the Python Requests library, or use the command line tools wget and curl in Linux.

Create a thumbnail

Use the Python PIL Library.

Prepare the background, font, and title text in advance, and use PIL to automatically generate any required images. The specific implementation idea can be Google by myself. At the beginning, I also spent a lot of time studying this library that made me crazy (in order to automatically center the text on the picture).

The following code is for reference only (this is the original code used in my program)

avatar = Image.open(BG_PATH)
drawAvatar = ImageDraw.Draw(avatar)
# 背景图尺寸
xSize, ySize = avatar.size
#字体大小,根据背景图尺寸 和 字数个数而定 最大 400
fontSize = min((xSize - 300) // len(cover_title), 400)
myFont = ImageFont.truetype(FONTS_PATH, fontSize)  # 中文字体
# print('font Size = {}'.format(fontSize))
# 放置文字的坐标
xPos = (xSize - fontSize * len(cover_title)) / 2
yPos = (ySize - 400 - fontSize) / 2
# print('xPos = {}, yPos = {}'.format(xPos, yPos))
# 生成封面图
drawAvatar.text([xPos, yPos], cover_title, fill=(255, 224, 41), font=myFont)
del drawAvatar
avatar.save(COVER_PATH)  # 保存封面图

Video production

Use the artifact FFmpeg

This tool tormented me so much that my hair dropped a lot, but I was very satisfied with the final result.

For example, if a 16.8M audio is matched with a background image, the size of the 1080P definition video generated is only 16.9M.

image

The following is the FFmpeg command that I used to generate videos with countless painstaking efforts for your reference. For more information about how to use FFmpeg, see Google.

command = f'ffmpeg -loglevel panic -r 0.01 -loop 1 -i {cover_path} -i {mp3_file_path} -c:v libx264 -t {mp3_length} {video_file_path}'
subprocess.run(command, shell=True)

YouTube Upload module

Another module that makes me spend countless days and nights.

At first, I used the official API Upload API of YouTube: YouTube Data API V3 .

This interface is very simple and stable to use, and can be basically operated according to the official tutorial. However, due to two special reasons (though not a fatal defect), I decided to use the unstable and worry-free Selenium module for simulation Upload.

YouTube API can upload up to 6 videos per day. To upload more videos, you need to fill in an extra long application form and may not pass the review.

YouTube API requires certification two months ago before it can be used by "third parties", unless you activate a G Suit package of $6 per month

I don't want to get 6 dollars for the time being, but more importantly, I can only upload 6 quotas every day, which I can't stand. After all, our automatically generated videos cannot be compared with other people's exquisite videos that attract millions of broadcasts. We can only win by quantity.

6 per day, drink the northwest wind.

I have no choice but to Selenium the simulated upload.

I don't want to say more about this. If necessary, you can refer to an open source library on Github. My own Upload module is customized based on this little brother's code.

Github: youtube_uploader_selenium

The biggest contribution is that this open-source library makes me realize that it is feasible to use Selenium to simulate uploading YouTube videos (I used to think that it is impossible to use standard input on YouTube Upload page).

With confidence and open-source libraries, I believe you can get it done quickly. At least, it should be much better than me, a man who studies Python halfway.

Automatic server deployment module

After all the previous modules are developed, you will face a very important step: deploy the program to the server.

Although I can purchase a VPS on a platform like VPC and deploy the program to run continuously, I continue to choose the Google Cloud Engine of GCP for the following reasons.

1. Google Cloud Engine can be seamlessly connected with other GCP functions, such as Firestore.

2. Select a preemptible instance. An instance with 2 vCPUs and 1GB memory costs only $2 per month. The actual operating cost is only about $1 (it does not run 24 hours a day)

3. No traffic fee is charged for uploading videos to Google Cloud Engine within the YouTube.

image

In view of this, I choose to host the program in GCE and choose preemptible instances.

Note that the price of this type of preemptible instance is only about half of that of a standard instance, but the maximum running time cannot exceed 24 hours. However, this is not a problem for our tasks.

It is a pleasant thing to configure a server template on GCP, enable automatic instance startup and destroy instances. The following is the general procedure:

1. Open a common instance (preemptible type does not matter, this is only used as the basic configuration)

2. Deploy your program on this server, install all necessary modules, debug and run successfully

3. Use crontab to run your main program every minute (configure the flock lock to ensure that it does not start again)

4. Shut down the server and create a new machine image based on the configured server.

5. Create an instance template based on the created Machine Image. Select a preemptible instance from the instance template.

6. Configure a Cloud function Google Cloud Functions to automatically start or destroy instance groups based on instance templates.

7. Configure a Cloud Scheduler from 10:00 a.m. to 22:00 p.m. to automatically start a preemptible instance every hour.

After the above configuration, the current program running mechanism is as follows:

1. Cloud Scheduler access your Cloud functions every hour between ten o'clock A.M. and 22 p.m. every day.

2. This cloud function automatically starts a preemptible instance that you have configured before.

3. Once the server is started, your main program will be run every minute. However, because the flock program lock is set, there is no need to worry that the program will start again. The new task starts again in the next minute only after the current program is run.

4. If the program makes and uploads a certain number of videos within one hour and reaches the limit (I set 8 videos per hour), the program will automatically send instructions to destroy the current server, set the task status to off and wait for the next hour to wake up.

5. After one hour, Cloud Scheduler access your task Cloud function again, start the instance, run the program, and destroy the instance. This cycle ends until ten o'clock in the evening. Wait for the arrival of ten o'clock A.M. the next day and start the task of the new day.

Congratulations, you have a complete full-automatic YouTube video publishing system that can help you earn dollars.

Automatic Program Update module

For a system that has deployed server templates, how to automatically update the program version becomes another minor problem to be solved.

At first, I needed to manually connect to VPS through SSH and upload a new version of the program, but this was obviously unsustainable.

Later, I updated the program version through cloud function transfer.

Now, I host the program in Github's private repository and synchronize it in Google Cloud Source Repositories. Then, add the automatic code update link to the command that automatically runs the program to achieve this effect:

After the code is updated, it is uploaded directly to the Github repository. Google Cloud Source Repositories, the latest code is automatically synchronized. The system automatically pulls the latest code before running the main program.

For example, I configured an automatic running command (the automatic confusion function has been enabled for key content)

#!/bin/sh
echo $'n'
time=$(date "+%Y-%m-%d %H:%M:%S")
echo "${time}"
cd /home/whoami/iYTB
git pull https://source.developers.google.com/p/ytb/r/github_whoami_iytb
/usr/bin/python3 iYTB.py >> iYTB.log 2>&1

Program running result notification module

Since the program runs automatically on a server that may destroy itself at any time, it is necessary to open up a message channel for sending task status.

Fortunately, it is very easy to implement such a message channel. For example, I am currently using this method: Telegram group notification

You only need three steps.

1. Apply for a Telegram Bot

2. Create a Telegram Group, pull the robot into the Group, and set it as an administrator.

3. Deploy a Cloud Functions that can send messages to the group

After the deployment is complete, you can send a GET request to the cloud function regardless of the error message, unexpected bug, and success notification of the program, you can receive the latest message notification in the group, like this:

image

Screenshot is the running log of the program (after simple modification, it is not easy for people to guess the video content I actually uploaded), including the start time of the program, the status of cookies, the title of the uploaded video, the actual upload time of the program, the ID of the successfully published video, and the full running time of the program.

In addition, you can receive task status notifications in real time:

image

In addition, I have several separate channels for sending other types of notification messages, which will not be described here.

The above is a brief introduction of the whole YouTube automation operation system and each module. I hope these contents can be helpful to you.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>