Serverless Google Cloud Functions with Python- A tutorial to download a youtube video and upload to google cloud storage

Ramsri Goutham
1 min readNov 22, 2018

In this tutorial we will see how to write a Google Cloud function to download a youtube video locally, provided a youtube url and then upload the video to a Google Cloud Storage Bucket.

The code of the Google cloud function can be found here. The root folder with requirements.txt and test function can be found here.

The key things to look for in the code below are -

  1. How to pass Youtube url link and access the link within the Google Cloud Function code.
  2. How to use Pytube to download Youtube video locally to ‘/tmp/’ folder of the Google Cloud Function machine.
  3. How to check if a file already exists in the google cloud storage bucket.
  4. Convert the locally downloaded Youtube video to audio file and upload to a storage bucket.

Google Cloud Function Code:

requirements.txt file to use in Google Cloud Functions

# Function dependencies, for example:
# package>=version
pytube
google-cloud-storage
moviepy

Calling the Code from Python:

Thanks for reading !!!

--

--

No responses yet