jebin2 commited on
Commit
09a9880
Β·
1 Parent(s): 9cee612

refactor: modularize publishers and video editor utils

Browse files
src/api_clients.py CHANGED
@@ -70,19 +70,6 @@ class APIClients:
70
  except Exception as e:
71
  logger.error(f"Failed to set up bucket permissions: {e}")
72
 
73
- # Initialize TTS client with same credentials
74
- creds = get_gcs_credentials("final_data")
75
- # Initialize helper classes
76
- # self.tts = GoogleTTS(credentials=creds) # REMOVED: Automation now handles this directly
77
- # self.stt = GoogleSTT(credentials=creds) # REMOVED: Automation now handles this directly
78
-
79
- # RunwayML API configuration
80
- self.runway_api_key = config.get("runwayml_api_key") or os.getenv("RUNWAYML_API_KEY") or os.getenv("RUNWAY_2ND_API_KEY") or os.getenv("SPARK_KEY")
81
- self.runway_base_url = "https://api.dev.runwayml.com/v1"
82
-
83
- self.file_names = None
84
- # self.init_temp_gcs()
85
-
86
  async def get_from_cache(self, method_type, duration=0):
87
  try:
88
  with open(await self.get_cache_url(f"{method_type}_{duration}", ".txt"), 'r', encoding="utf-8") as file:
 
70
  except Exception as e:
71
  logger.error(f"Failed to set up bucket permissions: {e}")
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  async def get_from_cache(self, method_type, duration=0):
74
  try:
75
  with open(await self.get_cache_url(f"{method_type}_{duration}", ".txt"), 'r', encoding="utf-8") as file:
src/automation.py CHANGED
@@ -20,11 +20,11 @@ from google_src.gcs_utils import upload_file_to_gcs
20
  from google_src.tts import GoogleTTS
21
  from google_src.stt import GoogleSTT
22
  from moviepy.editor import AudioFileClip
23
- import loudness_normalize
24
  from a2e_avatar import create_greenscreen_video_workflow
25
- import remove_green_bg
26
  import hashlib
27
- from onscreebcta import add_cta
28
  import numpy as np
29
  from moviepy.editor import VideoFileClip, concatenate_videoclips
30
  import math
 
20
  from google_src.tts import GoogleTTS
21
  from google_src.stt import GoogleSTT
22
  from moviepy.editor import AudioFileClip
23
+ from video_editor import loudness_normalize
24
  from a2e_avatar import create_greenscreen_video_workflow
25
+ from video_editor import remove_green_bg
26
  import hashlib
27
+ from video_editor.onscreen_cta import add_cta
28
  import numpy as np
29
  from moviepy.editor import VideoFileClip, concatenate_videoclips
30
  import math
src/social_media_publishers/__init__.py ADDED
File without changes
src/{instagram_publisher.py β†’ social_media_publishers/instagram_publisher.py} RENAMED
@@ -12,6 +12,10 @@ import sys
12
  import pandas as pd
13
  from datetime import datetime
14
  from dotenv import load_dotenv
 
 
 
 
15
  from pathlib import Path
16
  from load_config import load_configuration
17
  from main import (
 
12
  import pandas as pd
13
  from datetime import datetime
14
  from dotenv import load_dotenv
15
+
16
+ # Add parent directory to path to allow importing modules from src
17
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
18
+
19
  from pathlib import Path
20
  from load_config import load_configuration
21
  from main import (
src/{publisher.py β†’ social_media_publishers/publisher.py} RENAMED
@@ -7,6 +7,9 @@ Reads CSV rows, downloads videos via GCS, publishes sequentially, and commits pr
7
  import sys
8
  import asyncio
9
  import os
 
 
 
10
  import subprocess
11
  import random
12
  import time
@@ -18,9 +21,9 @@ from main import load_content_strategies
18
  from api_clients import APIClients
19
 
20
  # Import individual platform publishers
21
- from youtube_publisher import YouTubePublisher
22
- from instagram_publisher import InstagramPublisher
23
- from tiktok_publisher import TikTokPublisher
24
 
25
  DATA_DIR = Path("data")
26
 
 
7
  import sys
8
  import asyncio
9
  import os
10
+ # Add parent directory to path to allow importing modules from src
11
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
12
+
13
  import subprocess
14
  import random
15
  import time
 
21
  from api_clients import APIClients
22
 
23
  # Import individual platform publishers
24
+ from social_media_publishers.youtube_publisher import YouTubePublisher
25
+ from social_media_publishers.instagram_publisher import InstagramPublisher
26
+ from social_media_publishers.tiktok_publisher import TikTokPublisher
27
 
28
  DATA_DIR = Path("data")
29
 
src/{tiktok_publisher.py β†’ social_media_publishers/tiktok_publisher.py} RENAMED
@@ -12,6 +12,10 @@ import base64
12
  import time
13
  import pandas as pd
14
  from datetime import datetime
 
 
 
 
15
  from dotenv import load_dotenv
16
  from pathlib import Path
17
  from load_config import load_configuration
 
12
  import time
13
  import pandas as pd
14
  from datetime import datetime
15
+
16
+ # Add parent directory to path to allow importing modules from src
17
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
18
+
19
  from dotenv import load_dotenv
20
  from pathlib import Path
21
  from load_config import load_configuration
src/{youtube_publisher.py β†’ social_media_publishers/youtube_publisher.py} RENAMED
@@ -16,6 +16,10 @@ import os
16
  import sys
17
  import json
18
  from datetime import datetime, timedelta
 
 
 
 
19
  from load_config import load_configuration
20
  from main import (
21
  load_content_strategies
 
16
  import sys
17
  import json
18
  from datetime import datetime, timedelta
19
+
20
+ # Add parent directory to path to allow importing modules from src
21
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
22
+
23
  from load_config import load_configuration
24
  from main import (
25
  load_content_strategies
src/video_editor/__init__.py ADDED
File without changes
src/{crop.py β†’ video_editor/crop.py} RENAMED
File without changes
src/{loudness_normalize.py β†’ video_editor/loudness_normalize.py} RENAMED
File without changes
src/{onscreebcta.py β†’ video_editor/onscreen_cta.py} RENAMED
@@ -3,7 +3,7 @@ from moviepy.editor import *
3
  from PIL import Image, ImageDraw, ImageFilter, ImageFont
4
  import numpy as np
5
  import re
6
- from safe_zone import SafeZone
7
  import uuid
8
  from utils import logger
9
 
 
3
  from PIL import Image, ImageDraw, ImageFilter, ImageFont
4
  import numpy as np
5
  import re
6
+ from video_editor.safe_zone import SafeZone
7
  import uuid
8
  from utils import logger
9
 
src/{remove_green_bg.py β†’ video_editor/remove_green_bg.py} RENAMED
@@ -1,6 +1,6 @@
1
  import subprocess
2
  import uuid
3
- from crop import get_crop_boundaries, crop_video, resize_video
4
 
5
  def process_video_with_ffmpeg(fg_video, bg_video, max_height=720):
6
  """
 
1
  import subprocess
2
  import uuid
3
+ from video_editor.crop import get_crop_boundaries, crop_video, resize_video
4
 
5
  def process_video_with_ffmpeg(fg_video, bg_video, max_height=720):
6
  """
src/{safe_zone.py β†’ video_editor/safe_zone.py} RENAMED
File without changes
src/{text_clip.py β†’ video_editor/text_clip.py} RENAMED
@@ -1,7 +1,7 @@
1
  from moviepy.editor import ImageClip, CompositeVideoClip, VideoClip, ColorClip
2
  from PIL import Image, ImageDraw, ImageFont, ImageFilter
3
  import numpy as np
4
- from safe_zone import SafeZone
5
  import cv2
6
  from utils import logger
7
  import math
 
1
  from moviepy.editor import ImageClip, CompositeVideoClip, VideoClip, ColorClip
2
  from PIL import Image, ImageDraw, ImageFont, ImageFilter
3
  import numpy as np
4
+ from video_editor.safe_zone import SafeZone
5
  import cv2
6
  from utils import logger
7
  import math
src/video_renderer.py CHANGED
@@ -25,7 +25,7 @@ from moviepy.editor import (
25
  import textwrap
26
  from utils import logger
27
  import time
28
- from text_clip import create as create_text_clip, group_words_by_time_and_width, caption_style_1, caption_style_2, caption_style_3, caption_style_4, caption_style_on_screen_text
29
  import subprocess
30
  import asyncio
31
  import utils
 
25
  import textwrap
26
  from utils import logger
27
  import time
28
+ from video_editor.text_clip import create as create_text_clip, group_words_by_time_and_width, caption_style_1, caption_style_2, caption_style_3, caption_style_4, caption_style_on_screen_text
29
  import subprocess
30
  import asyncio
31
  import utils