FootageDownloader
To download footage, we will use the Pexels API.
Developing this class will teach you how to work directly with service APIs.
Working with the Pexels API (or any other API) typically involves the following steps: obtaining an API key, reviewing the documentation, sending HTTP requests, and handling the responses.
Let's go through these steps using the Pexels API to download videos.
1. Obtaining an API Key
Register on the Pexels website and obtain an API key from your account.
https://www.pexels.com/api/
2. Reviewing API Documentation
The documentation provides all available endpoints, request parameters, example responses, and header requirements.
https://www.pexels.com/api/documentation/
To download footage, we will use the Pexels API.
Developing this class will teach you how to work directly with service APIs.
Working with the Pexels API (or any other API) typically involves the following steps: obtaining an API key, reviewing the documentation, sending HTTP requests, and handling the responses.
Let's go through these steps using the Pexels API to download videos.
1. Obtaining an API Key
Register on the Pexels website and obtain an API key from your account.
https://www.pexels.com/api/
2. Reviewing API Documentation
The documentation provides all available endpoints, request parameters, example responses, and header requirements.
https://www.pexels.com/api/documentation/
π₯7
3. Sending Requests
Requests to the Pexels API are sent via HTTP, most often using the GET method to retrieve data. For each request, you need to include a header with your API key and additional parameters.
Example request:
β’ URL (endpoint): https://api.pexels.com/videos/search
β’ Header: Authorization: <your_key>
β’ Request parameters:
- query β search term (e.g., "nature").
- per_page β the number of results returned per page.
- page β page number for pagination.
4. Handling the Response
The API response contains JSON data, which must be processed to extract the video file links.
Requests to the Pexels API are sent via HTTP, most often using the GET method to retrieve data. For each request, you need to include a header with your API key and additional parameters.
Example request:
β’ URL (endpoint): https://api.pexels.com/videos/search
β’ Header: Authorization: <your_key>
β’ Request parameters:
- query β search term (e.g., "nature").
- per_page β the number of results returned per page.
- page β page number for pagination.
4. Handling the Response
The API response contains JSON data, which must be processed to extract the video file links.
π₯7β€1
Let's start developing the
We will insert the video footage in the middle of our Shorts.
A 40-second Shorts usually consists of 6-7 scenes. Therefore, we will save the footage file in the folder for the 3rd or 4th scene.
Class constructor:
1. In the class constructor, accept the API key.
2. Create an attribute
FootageDownloader class.We will insert the video footage in the middle of our Shorts.
A 40-second Shorts usually consists of 6-7 scenes. Therefore, we will save the footage file in the folder for the 3rd or 4th scene.
Class constructor:
1. In the class constructor, accept the API key.
2. Create an attribute
self.api_key and assign it the value of the passed argument.π₯6π1
Next, create a method for sending a request (
1. The method takes an endpoint and request parameters.
2. Then, the headers for the request are formed. This is a dictionary containing the key '
3. A get request is made to the endpoint, with the parameters and headers set.
4. The method returns the JSON response.
An example of such a method is shown in the image
make_request):1. The method takes an endpoint and request parameters.
2. Then, the headers for the request are formed. This is a dictionary containing the key '
Authorization' and the value of the API key.headers = {'Authorization': self.api_key}3. A get request is made to the endpoint, with the parameters and headers set.
4. The method returns the JSON response.
An example of such a method is shown in the image
π₯7
Method execute:
1. Accept an argument containing the search keyword for the video (
2. Form the endpoint path:
Alternatively, set it as an object attribute:
3. Create a dictionary with parameters:
4. Send a request to the target endpoint by calling the
5. Obtain the JSON response from the request.
6. Extract video links from the JSON response.
7. Save several videos in the folder for the 3rd or 4th scene of the script.
1. Accept an argument containing the search keyword for the video (
query), and also set the parameters page, per_page, orientation with default values:def execute(self, query, page=1, per_page=10, orientation='portrait'):2. Form the endpoint path:
endpoint = 'https://api.pexels.com/videos/search'Alternatively, set it as an object attribute:
self.endpoint.3. Create a dictionary with parameters:
params = {'query': query, 'page': page, 'per_page': per_page, 'orientation': orientation}4. Send a request to the target endpoint by calling the
make_request method and passing the endpoint and parameters.5. Obtain the JSON response from the request.
6. Extract video links from the JSON response.
7. Save several videos in the folder for the 3rd or 4th scene of the script.
π₯9
Way to obtain key phrases for a scene:
1. Read the file(s) containing the divided scenes of the script (
2. Take the text of the 3rd or 4th scene for each script.
3. Create a writer object and send a request to the AI assistant, asking it to return a list of key phrases from the text. Request the format to be a Python dictionary or list.
4. Extract the elements of the dictionary or list.
5. Loop through the elements, for each element call the
1. Read the file(s) containing the divided scenes of the script (
script_scenes.csv).2. Take the text of the 3rd or 4th scene for each script.
3. Create a writer object and send a request to the AI assistant, asking it to return a list of key phrases from the text. Request the format to be a Python dictionary or list.
4. Extract the elements of the dictionary or list.
5. Loop through the elements, for each element call the
execute method and pass the key phrase into it.π₯7π1
VideoGenerator
To implement this class, we will need the following tools:
β’
β’
β’
Command for installation:
To implement this class, we will need the following tools:
β’
Pillow β for image processing (scaling and cropping)β’
Moviepy β for merging video clips and audio filesβ’
numpy β for creating animations and converting images into arraysCommand for installation:
pip install pillow moviepy numpyπ₯7π2
Data preparation example:
1. Loop through the folders containing materials for each script (script_1, script_2, script_3), located in the
2. For each folder, loop through the subfolders with scenes (scene_1, scene_2, scene_3).
3. In each subfolder, pack the paths to all files into a dictionary. Example of a dictionary:
4. Return a list of lists of dictionaries. Each list of dictionaries represents a script, and each dictionary contains file paths for a specific scene.
5. Loop through each list (script).
6. Pass the LIST OF DICTIONARIES to the
1. Loop through the folders containing materials for each script (script_1, script_2, script_3), located in the
generated_images folder.2. For each folder, loop through the subfolders with scenes (scene_1, scene_2, scene_3).
3. In each subfolder, pack the paths to all files into a dictionary. Example of a dictionary:
files = {'image_1': 'path', 'image_2': 'path', 'image_3': 'path', 'voiceover': 'path', 'footage_1': 'path', 'footage_2': 'path'}4. Return a list of lists of dictionaries. Each list of dictionaries represents a script, and each dictionary contains file paths for a specific scene.
5. Loop through each list (script).
6. Pass the LIST OF DICTIONARIES to the
execute method.π₯7
Method execute:
1. Iterate through each element of the list (dictionary).
2. Extract the paths to all media files from the dictionary and save them in variables.
3. Calculate the duration of the audio file:
4. Based on the duration of the audio file, calculate and perform the animation of the image.
You can add a logic to relate the duration of the audio file to the number of images. For example, if the duration of the audio file is less than 3 seconds, use one image; if it's longer, use two images.
5. To implement the joining of video footage, check for the presence of a video file in the folder. If a video file exists, the image animation is not performed, and the video file is joined instead.
6. After performing the animation, merge the video file with the audio file.
7. After completing the loop, combine the finished video segments from each scene into one final file.
8. Save the final video file in the
1. Iterate through each element of the list (dictionary).
2. Extract the paths to all media files from the dictionary and save them in variables.
3. Calculate the duration of the audio file:
audio_clip = AudioFileClip(audio_path)
duration = audio_clip.duration4. Based on the duration of the audio file, calculate and perform the animation of the image.
You can add a logic to relate the duration of the audio file to the number of images. For example, if the duration of the audio file is less than 3 seconds, use one image; if it's longer, use two images.
5. To implement the joining of video footage, check for the presence of a video file in the folder. If a video file exists, the image animation is not performed, and the video file is joined instead.
6. After performing the animation, merge the video file with the audio file.
7. After completing the loop, combine the finished video segments from each scene into one final file.
8. Save the final video file in the
generated_videos folder.π₯7β€1
Image animation methods:
1. For image animations, you need to write separate methods. Some possible animations include:
2. Before performing the animation, the image must be scaled and cropped (using Pillow). This requires writing a separate method. The scaling should account for shifts happening during the animation to prevent black unfilled areas from appearing.
3. The numpy library is used for performing animations. Numpy helps transform the image into a pixel array, making it faster and easier to manipulate.
* An example implementation of the zoom_out method is shown in the image.
1. For image animations, you need to write separate methods. Some possible animations include:
zoom_in, zoom_out, slide_left_to_right, slide_right_to_left, slide_top, slide_bottom, circular_motion.2. Before performing the animation, the image must be scaled and cropped (using Pillow). This requires writing a separate method. The scaling should account for shifts happening during the animation to prevent black unfilled areas from appearing.
3. The numpy library is used for performing animations. Numpy helps transform the image into a pixel array, making it faster and easier to manipulate.
* An example implementation of the zoom_out method is shown in the image.
π₯8π1
The output of this class should be video files where:
1. For each scene, image animations are performed based on the duration of the audio file.
2. Images are scaled and cropped to the required video size, considering animation shifts.
3. Video footage is merged if available in the folder. The footage is scaled to the video size.
4. Each generated video file has its respective voiceover audio file merged.
5. The generated video fragments of each scene are combined into one final video file.
1. For each scene, image animations are performed based on the duration of the audio file.
2. Images are scaled and cropped to the required video size, considering animation shifts.
3. Video footage is merged if available in the folder. The footage is scaled to the video size.
4. Each generated video file has its respective voiceover audio file merged.
5. The generated video fragments of each scene are combined into one final video file.
π₯7
This media is not supported in your browser
VIEW IN TELEGRAM
You should end up with video files like this.
* For now, adding transitions and subtitles can be something for you to think about.
* For now, adding transitions and subtitles can be something for you to think about.
β€βπ₯15π₯5π1π1
Let's summarize our Shorts Monster course.
What have we learned?
1. Decomposing tasks, identifying actors and bot classes, creating a class hierarchy
2. Feeling the class, working with inheritance and composition
3. Building the bot's basis, designing the project folder structure
4. Setting up launch logic via console and argparse
5. Storing project settings, securely managing confidential data from environment variables in a .env file
6. Working with text generation (OpenAI API, g4f)
7. Working with AI image generation
8. Automating the browser (Playwright + Bing Image Creator)
9. Generating voiceovers (Elevenlabs API)
10. Working directly with APIs through HTTP requests (Pexels API)
11. Processing images, animating, and generating videos (Pillow, Moviepy, Numpy)
After solving this task, you will have:
1. Strong Python programming skills with a focus on practice
2. A powerful bot that includes modules for text, AI images, voiceovers, and video generation
3. A foundation for building powerful OOP bots for other projects
What have we learned?
1. Decomposing tasks, identifying actors and bot classes, creating a class hierarchy
2. Feeling the class, working with inheritance and composition
3. Building the bot's basis, designing the project folder structure
4. Setting up launch logic via console and argparse
5. Storing project settings, securely managing confidential data from environment variables in a .env file
6. Working with text generation (OpenAI API, g4f)
7. Working with AI image generation
8. Automating the browser (Playwright + Bing Image Creator)
9. Generating voiceovers (Elevenlabs API)
10. Working directly with APIs through HTTP requests (Pexels API)
11. Processing images, animating, and generating videos (Pillow, Moviepy, Numpy)
After solving this task, you will have:
1. Strong Python programming skills with a focus on practice
2. A powerful bot that includes modules for text, AI images, voiceovers, and video generation
3. A foundation for building powerful OOP bots for other projects
π₯10π2β€1
This is everything I wanted to say and all I wanted to teach you.
You can support my project by subscribing to Patreon or sending some crypto (addresses are on YouTube).
βοΈ As part of the Patreon subscription, I've added this course in an easy-to-read PDF version along with some bonuses:
1. The course in PDF format (67 pages)
2. A way for adding captions and transitions
3. A bonus section: abstract classes, interfaces, and contracts using this project as an example
4. I've also separately added a Prompt Builder with hidden columns and ready-made prompts
I also want to express my gratitude to everyone who has already supported the project. I appreciate the support of each one of you. π€
You can support my project by subscribing to Patreon or sending some crypto (addresses are on YouTube).
βοΈ As part of the Patreon subscription, I've added this course in an easy-to-read PDF version along with some bonuses:
1. The course in PDF format (67 pages)
2. A way for adding captions and transitions
3. A bonus section: abstract classes, interfaces, and contracts using this project as an example
4. I've also separately added a Prompt Builder with hidden columns and ready-made prompts
I also want to express my gratitude to everyone who has already supported the project. I appreciate the support of each one of you. π€
β€47π₯10π4π€1
I often hear questions like these:
β’ How to build a traffic/account farm?
β’ How to build a system that runs 24/7?
β’ What can such a system look like in production?
β’ What stack and components might it use?
I want to answer these questions here. For some, this will help to see possible directions for developing their own systems further.
β’ How to build a traffic/account farm?
β’ How to build a system that runs 24/7?
β’ What can such a system look like in production?
β’ What stack and components might it use?
I want to answer these questions here. For some, this will help to see possible directions for developing their own systems further.
β€37π3π2π€1
What requirements might such a system have? It should run autonomously on a server and provide convenient centralized management.
The tech stack and architecture could look as follows:
1. API layer (FastAPI) β REST endpoints for managing accounts, tasks, schedules, and statuses.
2. Task queue (Celery + Redis) β background workers running 24/7 for generators, uploaders, and registrars.
3. Scheduler β Celery Beat + synchronization of schedules from the database (dynamic periodic tasks).
4. Database β SQLite for local development, PostgreSQL in production (via SQLAlchemy + Alembic).
5. Admin panel (React Admin) β dashboard to manage all entities, runs, statuses, and logs; manual starts and timers.
6. Notifications β simple Telegram wrapper to notify about errors or successes.
7. Logging β JSON logging for API and workers.
The tech stack and architecture could look as follows:
1. API layer (FastAPI) β REST endpoints for managing accounts, tasks, schedules, and statuses.
2. Task queue (Celery + Redis) β background workers running 24/7 for generators, uploaders, and registrars.
3. Scheduler β Celery Beat + synchronization of schedules from the database (dynamic periodic tasks).
4. Database β SQLite for local development, PostgreSQL in production (via SQLAlchemy + Alembic).
5. Admin panel (React Admin) β dashboard to manage all entities, runs, statuses, and logs; manual starts and timers.
6. Notifications β simple Telegram wrapper to notify about errors or successes.
7. Logging β JSON logging for API and workers.
β€15π2π€2
Pay attention to the project structure:
Backend β a FastAPI application that handles all the logic: it stores data in the database (accounts, tasks, schedules, media), accepts requests via API routes, validates and processes them (schemas + services), and delegates heavy tasks (image/text generation, post uploads) to background tasks via Celery.
Frontend (admin panel) β a React Admin application that provides a user-friendly interface: you can add accounts, configure modules, create tasks, and view statistics. Itβs a convenient dashboard that communicates with the API, while all data and operations come from the backend.
Backend β a FastAPI application that handles all the logic: it stores data in the database (accounts, tasks, schedules, media), accepts requests via API routes, validates and processes them (schemas + services), and delegates heavy tasks (image/text generation, post uploads) to background tasks via Celery.
Frontend (admin panel) β a React Admin application that provides a user-friendly interface: you can add accounts, configure modules, create tasks, and view statistics. Itβs a convenient dashboard that communicates with the API, while all data and operations come from the backend.
β€11