pcdoido2 commited on
Commit
2ff2199
·
verified ·
1 Parent(s): b770ad2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -125,7 +125,6 @@ def randomize_video_metadata_ffmpeg(input_path, output_path):
125
  # --- Upload ---
126
 
127
  st.header("📤 Upload de Arquivos")
128
-
129
  st.subheader("Selecione uma categoria:")
130
 
131
  categoria = st.radio("Categoria:", CATEGORIES, index=None)
@@ -144,27 +143,33 @@ if categoria:
144
  if uploaded_files:
145
  for uploaded_file in uploaded_files:
146
  folder = os.path.join(BASE_FOLDER, categoria)
147
- file_path = os.path.join(folder, uploaded_file.name)
148
-
149
- # Salva temporário
150
- temp_path = file_path + ".tmp"
151
- with open(temp_path, "wb") as f:
 
 
 
 
 
 
 
152
  f.write(uploaded_file.read())
153
 
154
- # Se for vídeo e checkbox marcado, randomiza
155
  if apply_metadata and uploaded_file.name.lower().endswith((".mp4", ".mov", ".mkv")):
156
  try:
157
- randomize_video_metadata_ffmpeg(temp_path, file_path)
158
- os.remove(temp_path)
 
 
159
  except Exception as e:
160
- st.error(f"Erro ao processar metadados: {e}")
161
- os.rename(temp_path, file_path)
162
- else:
163
- os.rename(temp_path, file_path)
164
 
165
  # Salvar expiração se marcada
166
  if auto_delete:
167
- key = f"{categoria}|||{uploaded_file.name}"
168
  expirations[key] = time.time() + 24 * 60 * 60
169
  with open(EXPIRATION_FILE, "w") as f:
170
  json.dump(expirations, f)
 
125
  # --- Upload ---
126
 
127
  st.header("📤 Upload de Arquivos")
 
128
  st.subheader("Selecione uma categoria:")
129
 
130
  categoria = st.radio("Categoria:", CATEGORIES, index=None)
 
143
  if uploaded_files:
144
  for uploaded_file in uploaded_files:
145
  folder = os.path.join(BASE_FOLDER, categoria)
146
+ os.makedirs(folder, exist_ok=True)
147
+
148
+ # Nome final (renomeado aleatoriamente se for vídeo)
149
+ random_name = (
150
+ f"{int(time.time())}_{random.randint(1000,9999)}.mp4"
151
+ if uploaded_file.name.lower().endswith((".mp4", ".mov", ".mkv"))
152
+ else uploaded_file.name
153
+ )
154
+ file_path = os.path.join(folder, random_name)
155
+
156
+ # Salva original no destino
157
+ with open(file_path, "wb") as f:
158
  f.write(uploaded_file.read())
159
 
160
+ # Se for vídeo e checkbox marcado → processa com ffmpeg
161
  if apply_metadata and uploaded_file.name.lower().endswith((".mp4", ".mov", ".mkv")):
162
  try:
163
+ temp_out = file_path + ".processed.mp4"
164
+ randomize_video_metadata_ffmpeg(file_path, temp_out)
165
+ os.remove(file_path)
166
+ os.rename(temp_out, file_path)
167
  except Exception as e:
168
+ st.error(f"Erro ao randomizar metadados: {e}")
 
 
 
169
 
170
  # Salvar expiração se marcada
171
  if auto_delete:
172
+ key = f"{categoria}|||{random_name}"
173
  expirations[key] = time.time() + 24 * 60 * 60
174
  with open(EXPIRATION_FILE, "w") as f:
175
  json.dump(expirations, f)