BUBOUTLW commited on
Commit
600897e
·
verified ·
1 Parent(s): 37334d1

Update pack_builder/zip_builder.py

Browse files
Files changed (1) hide show
  1. pack_builder/zip_builder.py +25 -11
pack_builder/zip_builder.py CHANGED
@@ -1,22 +1,33 @@
1
- import zipfile
2
- import uuid
3
  import os
 
 
 
 
4
  from beat_generator.riffusion_cpu import generate_audio_loop
5
  from content_generator.hooks import generate_hooks
6
  from content_generator.captions import generate_captions
7
  from content_generator.ideas import generate_content_ideas
8
  from content_generator.scripts import generate_short_scripts
9
 
 
10
  def build_creator_pack(niche, style, bpm, tone, goal):
11
- folder = f"assets/temp/{uuid.uuid4().hex}"
 
 
12
  os.makedirs(folder, exist_ok=True)
13
 
14
- # Beats
 
 
15
  for i in range(3):
16
  beat_path = generate_audio_loop(style, bpm)
17
- os.system(f"cp {beat_path} {folder}/beat_{i+1}.wav")
18
 
19
- # Text Packs
 
 
 
 
 
20
  with open(f"{folder}/hooks.txt", "w") as f:
21
  f.write("\n".join(generate_hooks(niche, tone)))
22
 
@@ -29,13 +40,16 @@ def build_creator_pack(niche, style, bpm, tone, goal):
29
  with open(f"{folder}/scripts.txt", "w") as f:
30
  f.write("\n".join(generate_short_scripts(niche, tone)))
31
 
32
- # ZIP
 
 
33
  zip_path = f"{folder}.zip"
34
- with zipfile.ZipFile(zip_path, "w") as zipf:
 
35
  for root, _, files in os.walk(folder):
36
  for file in files:
37
- p = os.path.join(root, file)
38
- arc = os.path.relpath(p, folder)
39
- zipf.write(p, arc)
40
 
41
  return zip_path
 
 
 
1
  import os
2
+ import uuid
3
+ import zipfile
4
+ import shutil
5
+
6
  from beat_generator.riffusion_cpu import generate_audio_loop
7
  from content_generator.hooks import generate_hooks
8
  from content_generator.captions import generate_captions
9
  from content_generator.ideas import generate_content_ideas
10
  from content_generator.scripts import generate_short_scripts
11
 
12
+
13
  def build_creator_pack(niche, style, bpm, tone, goal):
14
+ # Create temp folder
15
+ pack_id = uuid.uuid4().hex
16
+ folder = f"assets/temp/{pack_id}"
17
  os.makedirs(folder, exist_ok=True)
18
 
19
+ # -----------------------------------
20
+ # 1. Generate beats & copy correctly
21
+ # -----------------------------------
22
  for i in range(3):
23
  beat_path = generate_audio_loop(style, bpm)
 
24
 
25
+ # Copy safely using Python, NOT shell commands
26
+ shutil.copy(beat_path, f"{folder}/beat_{i+1}.wav")
27
+
28
+ # -----------------------------------
29
+ # 2. Generate text files
30
+ # -----------------------------------
31
  with open(f"{folder}/hooks.txt", "w") as f:
32
  f.write("\n".join(generate_hooks(niche, tone)))
33
 
 
40
  with open(f"{folder}/scripts.txt", "w") as f:
41
  f.write("\n".join(generate_short_scripts(niche, tone)))
42
 
43
+ # -----------------------------------
44
+ # 3. Build ZIP file safely
45
+ # -----------------------------------
46
  zip_path = f"{folder}.zip"
47
+
48
+ with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
49
  for root, _, files in os.walk(folder):
50
  for file in files:
51
+ file_path = os.path.join(root, file)
52
+ arc_path = os.path.relpath(file_path, folder)
53
+ zipf.write(file_path, arc_path)
54
 
55
  return zip_path