Last active
September 25, 2021 00:45
-
-
Save tallguyjenks/d8c5b5678a4d9994c7b8e77aef0bd9d3 to your computer and use it in GitHub Desktop.
YouTube Sponsorship Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.9 | |
# | |
# Created by Bryan Jenks https://github.com/tallguyjenks on 2021-08-08 | |
# | |
# You will need these libraries and can acquire them through the following commands | |
# | |
# pip install --upgrade google-api-python-client google-auth-oauthlib google-auth-httplib2 requests scrapetube | |
# | |
# YouTube API Python Quickstart guide: | |
# https://developers.google.com/youtube/v3/quickstart/python | |
import requests | |
import pandas as pd | |
import scrapetube | |
API_KEY = "" # Add your Creds here | |
OAUTH_ID = "" # Add your Creds here | |
OAUTH_SECRET = "" # Add your Creds here | |
CHANNEL_ID = "" # Add your Channel ID here like: 'UCfhSB16X9MXhzSFe_H7XbHg' | |
ID = "" # This stays blank | |
PART = "statistics" | |
VIDEO_IDS = scrapetube.get_channel(f"{CHANNEL_ID}") | |
LATEST_VIDEO_IDS = pd.DataFrame(VIDEO_IDS)["videoId"].tolist()[:10] | |
sum_views = 0 | |
for ID in LATEST_VIDEO_IDS: | |
r = requests.get(f'https://www.googleapis.com/youtube/v3/videos?part={PART}&id={ID}&key={API_KEY}') | |
payload = r.json() | |
df = pd.DataFrame(payload['items']) | |
views = int(df['statistics'][0]['viewCount']) | |
sum_views += views | |
avg_views = sum_views / 10 | |
CPM = 100 | |
SHOUT_OUT = round((avg_views / 1000) * CPM, 0) | |
print(f""" | |
Your total views for the latest 10 videos: \033[0;31m{sum_views:,}\033[0m | |
Your Average views for the latest 10 videos: \033[0;31m{avg_views:,}\033[0m | |
Your desired CPM (Cost Per Mille) is: \033[0;35m${CPM:,}\033[0m | |
Price for 30-60 sec shout-out: \033[0;32m${SHOUT_OUT:,}\033[0m | |
3x Price for dedicated video: \033[0;32m${SHOUT_OUT * 3:,}\033[0m | |
""") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment