Skip to content

Commit

Permalink
ci: update the input-props script
Browse files Browse the repository at this point in the history
  • Loading branch information
malkiii committed Sep 20, 2024
1 parent f87f3b1 commit 89bca20
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@main
- uses: actions/checkout@master
- uses: pnpm/action-setup@v4

- name: Install FFmpeg
run: sudo apt update && sudo apt install -y ffmpeg

- name: Use Node.js
uses: actions/setup-node@main
uses: actions/setup-node@master
with:
node-version: 20.x

Expand All @@ -28,6 +28,7 @@ jobs:
- name: Render video.mp4
env:
CLOUDINARY_URL: ${{ secrets.CLOUDINARY_URL }}
RUN_COUNT: ${{ github.run_number }}
run: |
node remotion/generate-props.js
pnpm remotion:render -- --props="./input-props.json"
Expand Down
22 changes: 11 additions & 11 deletions remotion/generate-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import 'dotenv/config';

await ensureBrowser();

const cloudinaryURL = new URL(process.env.CLOUDINARY_URL);
const runCount = parseInt(process.env.RUN_COUNT, 10) || 1;

/**
* @param {'croma' | 'background'} folder
*/
async function getVideoURL(folder) {
const { hostname } = new URL(process.env.CLOUDINARY_URL);
async function getNextVideoURL(folder) {
const { hostname } = cloudinaryURL;

const folderName = `quran-${folder}s`;
const count = await getTotalFilesCount(folderName);

const diff = new Date().getTime() - new Date('2020-01-01').getTime();
const dayNumber = Math.floor(diff / (1000 * 60 * 60 * 24));
const filesCount = await getTotalFilesCount(folderName);

const video = `${folder}_${(dayNumber % count) + 1}.mp4`;
const video = `${folder}_${(runCount % filesCount) + 1}.mp4`;

return `https://res.cloudinary.com/${hostname}/video/upload/${folderName}/${video}`;
}
Expand All @@ -28,7 +28,7 @@ async function getVideoURL(folder) {
* @returns {Promise<number>}
*/
async function getTotalFilesCount(folder) {
const { username, password, hostname } = new URL(process.env.CLOUDINARY_URL);
const { username, password, hostname } = cloudinaryURL;

const endpoint = new URL(
`/v1_1/${hostname}/resources/by_asset_folder`,
Expand All @@ -48,10 +48,10 @@ async function getTotalFilesCount(folder) {
* @type {import('./schema').CompositionProps}
*/
const inputProps = {
croma: await getVideoURL('croma'),
background: await getVideoURL('background'),
croma: await getNextVideoURL('croma'),
background: await getNextVideoURL('background'),
};

fs.writeFileSync('./input-props.json', JSON.stringify(inputProps));

console.log('Props generated successfully:', inputProps);
console.log('Props generated successfully ✨');
3 changes: 2 additions & 1 deletion scripts/upload-videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
file_path,
folder=f"quran-{folder_name}s",
public_id=public_id,
resource_type="video"
resource_type="video",
overwrite=True
)

# Get the URL of the uploaded video
Expand Down

0 comments on commit 89bca20

Please sign in to comment.