How a simple Python script led to over 50 million views on Youtube
A catchy title fetched him over 50 million views. So I wondered how it works behind the scenes...
All you need to do is use Youtube's V3 API to update your video details with the help of some simple Python code. Set it up as a CRON job on a cloud virtual machine (GCP for instance) and let it run every 5 mins or so.
API_SERVICE_NAME = 'youtube'
API_VERSION = 'v3'
def get_authenticated_service():
flow = InstalledAppFlow.from_client_secrets_file(CLIENT, SCOPES)
credentials = flow.run_console()
return build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
request = youtube.videos().list(
part="statistics",
id="PASTE VIDEO ID HERE"
)
response = request.execute()
newDict={}
for item in response['items']:
newDict.update(item)
response['items']=newDict
Views=str(response['items']['statistics']['viewCount'])
def make_ordinal(n):
n = int(n)
suffix = ['th', 'st', 'nd', 'rd', 'th'][min(n % 10, 4)]
if 11 <= (n % 100) <= 13:
suffix = 'th'
return str(n) + suffix
ordinalViews=make_ordinal(Views)
request2 = youtube.videos().update(
part="snippet,status,localizations",
body={
"id": "PASTE VIDEO ID HERE",
"snippet": {
"categoryId": "Your category ID",
"description":"Your Description",
"tags": ['Your tags here'],
"title": "You are the "+ordinalViews+" person to click on this video!"
}
}
)
Et Voilà! You can update your video's title as well (until you run out of free GCP credits 😭)
Link to Github repo: Youtube-Title-Updater
Most of my posts are fueled by caffeine
Help me put out more content to please your eyeballs by showing your support through Buy Me a Coffee