Upload YouTube videos from Python and more.
Project description
PillarGG YouTube Uploader
Upload Youtube Videos and more via Python.
Getting Started
pip install pillar-youtube-upload
You can read more below and on the docs.
This project uses the Youtube Data API.
All implementations of youtube upload needs some form of authentication.
Client Side youtube upload
To upload youtube videos as a client, you need to follow this guide.
Server Side youtube upload
To upload youtube videos as a server, you need to follow this guide.
Getting a youtube api key
- First, you need to go to this website.
- If prompted, select a project, or create a new one.
- Use the Library page to find and enable the YouTube Data API v3.
- Go to the credentials page.
- Click
Create Credentials > OAuth client ID
. - Select the Web application app type.
- Fill in the form and click create. For testing redirect URIs that refer to the local machine with
http://localhost:8080
. - Download the client_secret.json file from the API Console and securely store the file in a location that only your application can access. By default, the application gets this file from the directory your script is being ran in. The path can also be changed when the class
YoutubeUploader
is being initialized. - Get your
client_id
andclient_secret
.
We recommend that you design your app's auth endpoints so that your application does not expose authorization codes to other resources on the page.
The key must have the scope 'https://www.googleapis.com/auth/youtube.upload'.
Usage Info
The variables client_id
and client_secret
are how Google identify your application. These are specified in the initialization parameters or in the client_secrets.json
file.
The variables access_token
and refresh_token
are how Google's APIs differentiate between different YouTube channels. These are specified in the authenticate method.
This module uploads a given video to a youtube channel, as such there are 2 things this module needs.
-
A video
-
Video Options
- Title
- Description
- Tags
- Category
- Status
- DeclaredMadeForKids
-
A channel to upload to(In the form of a authentication file)
-
The authentication file should contain the following:
- access_token: token_here
- refresh_token: token_here
- scope: scope_here
- token_type: Bearer
- expires_in: 3599
This file should be called client_secrets.json and exist in the directory this script is.
Usage
0. Importing the package
# youtube upload api
from youtube_upload.client import YoutubeUploader
1. Instantiating an uploader
uploader = YoutubeUploader(client_id,client_secret)
or
uploader = YoutubeUploader()
If a client_secrets.json is present in the current working directory (downloaded from the Credentials Control Panel in the Google Cloud Console when you create the application). or
uploader = YoutubeUploader(secrets_file_path=secrets_file_path_here)
You can specify the path to the file with the secrets_file_path
parameter.
2. Authentication
If you run authenticate
with no parameters and no oauth.json
, it opens a web page locally that you can use to sign into the YouTube Channel you want to upload the video to.
uploader.authenticate()
or
uploader.authenticate(access_token=access_token_here, refresh_token=refresh_token_here)
OR
uploader.authenticate(oauth_path='oauth.json')
3. Uploading the video
# Video options
options = {
"title" : "Example title", # The video title
"description" : "Example description", # The video description
"tags" : ["tag1", "tag2", "tag3"],
"categoryId" : "22",
"privacyStatus" : "private", # Video privacy. Can either be "public", "private", or "unlisted"
"kids" : False, # Specifies if the Video if for kids or not. Defaults to False.
"thumbnailLink" : "https://cdn.havecamerawilltravel.com/photographer/files/2020/01/youtube-logo-new-1068x510.jpg" # Optional. Specifies video thumbnail.
}
# upload video
uploader.upload(file_path, options)
Parameter tags
should be list of strings only. The parameter categoryId
refers to YouTube internal categories, more information can be found here.
4. Closing the uploader
uploader.close()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pillar-youtube-upload-0.3.0.tar.gz
.
File metadata
- Download URL: pillar-youtube-upload-0.3.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9273bd921ef87c512718888ea795c5762d5b238a39d241b499486ff9f710c7b8 |
|
MD5 | 5e11443c56455deacb92c5a521427330 |
|
BLAKE2b-256 | faf7d825507e3b84b3daf3b199e7e7521734015c49b4642388c4b1867cc47439 |
File details
Details for the file pillar_youtube_upload-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: pillar_youtube_upload-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd4cd0b153f478079ae707b5f936d406153802e3756053172fc5fbc8a8383072 |
|
MD5 | 841f6992e01769e7f74d2e3f87a107f7 |
|
BLAKE2b-256 | b33a73f5f477658a1d0a357de6cdb0f0d9367dce5f340d4880300c776cec1e2e |