Giter Club home page Giter Club logo

youtube-uploader-bot's Introduction

Youtube Uploader Bot

How to Build a YouTube Uploader Bot Using Google Apps ScriptWhenever you hear the word 'Bot' you probably imagine a robot like they show in the movies. They are bots too, rather smart ones. But we are referring to a different kind of bot here.

We can define a bot as a script that can be used to automate certain tasks which are either tedious or difficult for humans. There are good bots and bad bots, and there is a very fine line between them.

Before we start, let me tell you one thing, This tutorial only discusses the part which involves uploading videos to YouTube. We will be using a sample video here.

If you create a bot which uploads video regularly (like Webdriver Torso, which we will talk more about at the end of the article) you need a source for the video.

Also, a warning: make sure you check the copyrights of all videos you upload. The version of the bot I first created uploaded others' videos to YouTube – and you won't believe what happened. I got series of copyright claims and strikes and my channel was ultimately deleted.

So in this tutorial I'll show you how it's done. But if you want to implement it, first find a good source of videos that you can upload without copyright issues.

Why Google Apps Script?

Google Apps Script is a scripting platform developed by google for running light-weight applications. Its syntax is based on JavaScript. If you already know Javascript you will find it really easy.

The reason we are using Google Apps Script is because it makes it really easy to build this bot. It has in-built support for most Google products like Gmail, Sheets, Forms, and Youtube. And it's free.

Overview of Google Apps Script

Google Apps Script has an online editor and filesystem. It doesn't need any deployment, you just have to save your code and it's running.

If you open the Apps Script editor, it will look something like this:

Just like any other text editor, it has a sidebar with list of files, a menu, and space for writing code. The code files have a .gs extension (probably for Google script). And most important, all the code must be inside some function – anonymous code won't be executed.

There are two special functions, doPost() and doGet(). As the name suggests, they are used for handling POST and GET requests, respectively. We won't be using them here, but if you want to create this bot like an API that can be called using HTTP requests, it would be useful.

Getting Started

Unlike other tutorials, I won't tell you to clone a GitHub repository. First, because I want you to learn and code along with me. Second, the code isn't that big, and you need to understand how it works.

This is the function that uploads a given video to a YouTube channel:

function upload(url, title, description, topics) { try { var video = UrlFetchApp.fetch(url); YouTube.Videos.insert({ snippet: { title: title, description: description, tags: topics }, status: { privacyStatus: "public", }, }, "snippet,status", video); return ContentService.createTextOutput("done") } catch (err) { return ContentService.createTextOutput(err.message) } }

Enabling YouTube API

Before you run this function, you have to enable YouTube Data API V3. You must be familiar with what an API is, so let me try to explain that with an example.

Google Maps is a great service. It has lots of amazing tools. Suppose you want to use those features in your app, let's say for building a smart digital invitation card with an embedded map.

Normally, to do this you need the source code of Maps. But that code is not open-source. And it would be foolish to give someone source code just because they want to use some feature. That's where an API comes handy.

APIs or Application Programming Interfaces, are a way for developers to allow others to use your app's features without disclosing the source code.

In this case, YouTube's API allows developers to use YouTube's features in their apps, or to control some YouTube channel after authentication. If you have an idea of what an API is, let's continue.

To enable the YouTube Data API, navigate to Resources > Advanced Google Services. You will see something like the below. It may ask you to accept Google Cloud's terms before proceeding if you don't have a project already set up. If asked, accept the terms.

Scroll to the bottom. You will see YouTube Data API V3. Usually, you need to create a Google Cloud Project to use it. But App Script creates a project for itself, so you don't need to create something separate. Enable it and close the popup. Now you are good to go.

Running the function

You have to paste the code given below (same as above) into the text editor and save it from the File > Save menu.

function upload(url, title, description, topics) { try { var video = UrlFetchApp.fetch(url); YouTube.Videos.insert({ snippet: { title: title, description: description, tags: topics }, status: { privacyStatus: "public", }, }, "snippet,status", video); return ContentService.createTextOutput("done") } catch (err) { return ContentService.createTextOutput(err.message) } }

After saving it, you have to navigate to the Run > Run function > Upload menu. It will look something like this:

On clicking the upload button, you will receive a popup like this:

Now this is where the usefulness of App Script becomes apparent. Here, you can give it permission to upload videos to your account. It will show you warnings that the app is not verified – but don't worry, that's a security step Google takes to prevent malicious apps.

But here, you are the developer, so you can ignore the warning and give permission from the Advanced button on the bottom left. It will ask you for two permissions, as shown:

Permission to manage your YouTube account is a serious permission. Though it's safe in this particular instance, never give this permission to any app you don't trust. It will give the app complete access to your YouTube account.

And this isn't just the case for YouTube. You should be extra careful before you allow sensitive scopes on any platform, like Twitter, Facebook, GitHub and other social sign-in methods.

After you give that permission, the function will be executed. But nothing will happen as we didn't specify what should be uploaded.

Here, you need to give values to the URL, title, description, and tags variables. Let us take a sample video for our use (remember those copyright issues?).

This is the modified upload() function:

function upload() { try { var video = UrlFetchApp.fetch("https://www.w3schools.com/html/mov_bbb.mp4"); YouTube.Videos.insert({ snippet: { title: "Big Buck Funny", description: "This Is The Description", tags: ["funny"] }, status: { privacyStatus: "public", }, }, "snippet,status", video); return ContentService.createTextOutput("done") } catch (err) { return ContentService.createTextOutput(err.message) } }

You can Save it and Run the function again. You can see that we changed the URL to a video URL, the title and description were set, and the tags are also set as an array. You can also set privacyStatus to private for testing.

Let's see the results:

As I told you at the start of the tutorial, copyright infringement is a big deal. The above video was removed by YouTube within minutes of uploading.

So, find a good video source first. If you want to generate videos programatically, there are libraries like ffmpeg, but let's not discuss that here. The aim of this article was to create a bot and we did.

Bot that regularly uploads videos

Suppose you find a source for videos and want your bot to regularly upload videos. Google Apps Script has an inbuilt Cron service which will execute your function at regular intervals, like daily, or once a week. You can create a trigger from the dashboard:

You will get an option to add a trigger on the bottom right. The options will look something like this:

You can set the function to be called, the frequency, and other options. Thus we have successfully created a YouTube Uploader Bot.

This was just one use of Google Apps script – you can use it for other tasks like:

  • Modifying Google Forms

  • Creating extensions for Google Sheets

  • Creating Blogger posts programatically

You may try other projects too, There is a lot you can do with it.

Webdriver Torso

You may not have heard about it, but this bot (or maybe a superhuman) has uploaded more than 70,000 videos on its youtube channel over a relatively short period of time. And although they are procedurally generated videos, it's still very cool.

These are the most viewed videos on this channel:

You can see that the Eiffel Tower at night video (which is illegal) has the most views. There are conspiracy theories that this channel is owned by YouTube for testing purposes.

Either way, don't get inspired – if you upload this many videos, YouTube will most probably suspend you.

youtube-uploader-bot's People

Contributors

theabbie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

youtube-uploader-bot's Issues

help

what can i use as the link? or where can i get a video?

Private (locked)

Hello! Thank you for the excellent tutorial - I was able to set this up easily and quickly. The problem I am running into is that Youtube privates the video as soon as I upload it. I saw somewhere that this is because the app/script is unverified? I'm not interested in taking the time to try to get it verified, so is there a way around this block or is there an already verified script that can be used for this purpose?

Hey! I am learning to code in school.

Hey! I am learning to code in school and i wanted one of my projects to be a bot which would upload videso for me. I was wondering if you wanted to go through how your code works and how to use it?!

Br, Dylan

Contact info
dyl#2854 on discord

Video Source????

The problem is that I think this bot is designed to only upload one video. After that the user has to manually change the bot so that it uploads a different video. That's not very efficent. This bot only works to google video vids

An Example of what it looks like. In case, you don't know what I'm reffering to.

Screenshot 2021-10-09 192439

Since, google video does not support a playlist/collection of videos. Finding a good video source is impossible. Since there are no source of video"s." Meaning that a playlist/collection of video's where the bot can upload stuff cannot be be done. So you litterally have to switch the googlevideo every time it uploads. Which is very slow and less efficent If I hadn't of used the bot.

Supposedly, you found a "good video source" for your channel (the one deleted by copyright) Can you please tell me what it is? Since you can't do that according to my observations.

Website for MP$

Hey!
Would you be able to drop me a free software I could use to convert the MP4 into like a raw link? Cant seem to find any. Thanks!

it works but it sometimes uploads

Hey! so the code works but sometimes it will upload and sometimes it won't upload and I already got the videos source and everything but everytime i press the run button it runs but i check my youtube studio and the video isn't there. Can you help me and if i am doing something wrong? Is there a limited times I can run the code or is it like a daily youtube upload limit?

Videos being locked as private!

hey, when i use the script to upload videos onto my channel about a minute after they are uploaded they get the visibility "Private (Locked)" because of a tos break. What is causing triggering this? is there a way to fix it?

Hi i need help :)

I wan't to make a download link for my video but what services dose work? google drive ain't working for me.
The test video works for me but i cant generate a link for the video i wan't to upload.

Thanks for the help :) best regards AJ from Denmark

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.