mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
Add Facebook video compatibility for automatic post scheduling
Transform video URLs to ensure they are compatible with Facebook's requirements (H.264, AAC, MP4) by applying Cloudinary transformations. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: 33011479-5eb2-4750-8cfe-77cac0f51d8e Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/L05E01m
This commit is contained in:
1 parent
008b1a80c5
commit
20c0866fe8
1 file changed
+36
-2
@@ -127,9 +127,43 @@ export class FacebookService {
|
||||
return data.post_id || data.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Facebook-compatible video URL with Cloudinary transformations
|
||||
* Facebook requires: H.264 video codec, AAC audio codec, MP4 container
|
||||
*/
|
||||
private getFacebookCompatibleVideoUrl(originalUrl: string): string {
|
||||
// Check if this is a Cloudinary URL
|
||||
const cloudinaryPattern = /https:\/\/res\.cloudinary\.com\/([^\/]+)\/video\/upload\//;
|
||||
const match = originalUrl.match(cloudinaryPattern);
|
||||
|
||||
if (!match) {
|
||||
// Not a Cloudinary URL, return as-is (may fail on Facebook)
|
||||
console.warn('Video URL is not from Cloudinary, cannot apply transformations:', originalUrl);
|
||||
return originalUrl;
|
||||
}
|
||||
|
||||
const [fullMatch, cloudName] = match;
|
||||
const videoPath = originalUrl.replace(fullMatch, '');
|
||||
|
||||
// Apply transformations for Facebook compatibility:
|
||||
// - vc_h264: Video codec H.264
|
||||
// - ac_aac: Audio codec AAC
|
||||
// - f_mp4: Force MP4 format
|
||||
// - q_auto: Automatic quality optimization
|
||||
const transformations = 'vc_h264,ac_aac,f_mp4,q_auto';
|
||||
|
||||
const transformedUrl = `https://res.cloudinary.com/${cloudName}/video/upload/${transformations}/${videoPath}`;
|
||||
|
||||
console.log('🎬 Transforming video for Facebook compatibility:');
|
||||
console.log(' Original:', originalUrl);
|
||||
console.log(' Transformed:', transformedUrl);
|
||||
|
||||
return transformedUrl;
|
||||
}
|
||||
|
||||
private async publishVideoPost(post: Post, page: SocialPage, media: Media): Promise<string> {
|
||||
// Use original URL for video
|
||||
const videoUrl = media.originalUrl;
|
||||
// Transform video URL to ensure Facebook compatibility (H.264/AAC/MP4)
|
||||
const videoUrl = this.getFacebookCompatibleVideoUrl(media.originalUrl);
|
||||
|
||||
const params = new URLSearchParams({
|
||||
access_token: page.accessToken!,
|
||||
|
||||
Reference in new issue
Block a user