This project automates the workflow of downloading videos of Highest Available Resolution, storing metadata, and optionally uploading them to Google Drive. It performs the following steps:
Downloads a video and returns its local file path.
Validates and updates spreadsheet headers as needed.
Appends metadata (title, source, date, etc.) to a Google Sheet.
If UPLOAD_TO_DRIVE is enabled, uploads the video to Google Drive and records the file ID in the sheet.
If not, stores the local file path in the sheet instead.
Includes robust error handling for each step.
Ideal for organizing and managing large batches of videos efficiently.
Before you begin, ensure you have met the following requirements:
- Python 3.x installed on your system.
- Access to Google Cloud Platform.
-
Create a Google Cloud Project:
- Go to the Google Cloud Console.
- Create a new project.
-
Enable APIs:
- Navigate to the "API & Services" dashboard.
- Enable the following APIs:
- Google Drive API
- Google Sheets API
-
Create Service Account:
- Go to "IAM & Admin" > "Service Accounts".
- Click "Create Service Account".
- Fill in the details and click "Create".
- Assign the role
EditororOwnerto the service account. - Click "Done".
-
Generate Service Account Key:
- Click on the created service account.
- Go to the "Keys" tab.
- Click "Add Key" > "Create New Key".
- Choose JSON format and click "Create".
- Save the generated JSON file as
google_service_account_creds.json.
-
Place Credentials:
- Move the
google_service_account_creds.jsonfile to thecredentialsfolder in your project directory.
- Move the
-
Share Drive Folder with Service Account
-
Locate the Folder: Go to your Google Drive (drive.google.com) and find the folder you want to share.
-
Right-Click the Folder: Right-click on the folder.
-
Select "Share": In the context menu, click on "Share".
-
Add the Service Account Email:
-
In the "Add people and groups" field, enter the email address of your service account.
-
Set Permissions:
-
Use the dropdown menu next to the service account's email to set the permission level:
-
Editor: The service account can view, edit, delete, and add files within the folder.
-
Click "Send": Click the "Send" button to share the folder.
-
-
Share Spreadsheet with service account:
- Go to your Google Sheets (sheets.google.com) and find the spreadsheet you want to shar
- Right-Click the Spreadsheet: Right-click on the spreadsheet.
- Select "Share": In the context menu, click on "Share".
- Add the Service Account Email:
- In the "Add people and groups" field, enter the email address of your service account.
- Set Permissions:
- Use the dropdown menu next to the service account's email to set the permission level:
- Editor: The service account can view, edit, delete, and add files within the spreadsheet.
- Click "Send": Click the "Send" button to share the spreadsheet.
- For Windows, download the FFmpeg executable from FFmpeg's official website and follow the installation instructions.
- For macOS, you can install FFmpeg using Homebrew:
brew install ffmpeg
- For Linux, you can install FFmpeg using your package manager:
sudo apt-get install ffmpeg
- If you prefer not to install FFmpeg globally, you can download the FFmpeg executable and place it in the project directory as
ffmpeg.
Create a .env file in the root of your project directory with the following content:
DRIVE_ID=your_drive_id
SPREADSHEET_ID=your_spreadsheet_idReplace your_drive_id and your_spreadsheet_id with the actual IDs.
Modify the config.py file to set the following options:
UPLOAD_TO_DRIVE: Set toTrueorFalseto enable or disable uploading to Google Drive.FFMPEG_INSTALLED: Set toTrueif FFmpeg is installed on your system, otherwise set toFalse.
Make sure you have the latest version of yt-dlp installed. Run the following command:
pip install --upgrade yt-dlp- Make sure you have the necessary permissions to access the Google Drive and Google Sheets APIs.
- Ensure that the service account email is added to the Google Sheets and Google Drive permissions.
- If you encounter any issues with FFmpeg, ensure that it is installed correctly and the executable is -Read README.md Carefully.
- project-root/
├── credentials/google_service_account_creds.json # Google service account credentials
├── ffmpeg/ # (Optional) FFmpeg binaries for processing
├── storage/
│ ├──videos # Downloaded videos stored here.
│ └──logs/ # Logs
├── utils/
│ ├──__init__.py
│ ├──download_videos.py # Download Logic
│ ├──spreadsheet.py # Spreadsheet Logic
│ └──upload_to_drive.py # Upload to Google Drive Logic
├── config.py
├── .env
└── main.pypython main.py- Clone the Repository
git clone https://github.com/your-username/your-project.git
cd your-project- Install Required Packages
pip install -r requirements.txtpython main.pyThis project is licensed under the MIT License. @shyamDev18