pcdoido2 commited on
Commit
2a96281
·
verified ·
1 Parent(s): cb55387

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -6
app.py CHANGED
@@ -2,6 +2,10 @@ import streamlit as st
2
  import os
3
  import json
4
  import time
 
 
 
 
5
 
6
  BASE_FOLDER = "uploaded_files"
7
  CATEGORIES = ["AVATAR WORLD", "BLOX FRUITS", "TOCA LIFE"]
@@ -41,8 +45,41 @@ else:
41
 
42
  st.title("📂 File Manager por Categoria")
43
 
44
- # --- Função: apagar arquivos expirados ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  def remove_expired_files():
 
46
  changed = False
47
  now = time.time()
48
  expired_files = []
@@ -67,9 +104,7 @@ def remove_expired_files():
67
  remove_expired_files()
68
 
69
  # --- Upload ---
70
-
71
  st.header("📤 Upload de Arquivos")
72
-
73
  st.subheader("Selecione uma categoria:")
74
 
75
  categoria = st.radio("Categoria:", CATEGORIES, index=None)
@@ -80,15 +115,22 @@ if categoria:
80
  accept_multiple_files=True,
81
  key=f"uploader_{categoria}"
82
  )
83
- auto_delete = st.checkbox("Excluir automaticamente após 24 horas")
 
84
 
85
  if uploaded_files:
86
  for uploaded_file in uploaded_files:
87
  folder = os.path.join(BASE_FOLDER, categoria)
88
  file_path = os.path.join(folder, uploaded_file.name)
 
 
89
  with open(file_path, "wb") as f:
90
  f.write(uploaded_file.read())
91
 
 
 
 
 
92
  # Salvar expiração se marcada
93
  if auto_delete:
94
  key = f"{categoria}|||{uploaded_file.name}"
@@ -96,7 +138,7 @@ if categoria:
96
  with open(EXPIRATION_FILE, "w") as f:
97
  json.dump(expirations, f)
98
 
99
- st.success("Arquivos enviados com sucesso!")
100
  st.rerun()
101
 
102
  # --- Lista de Arquivos agrupada por pasta ---
@@ -154,4 +196,4 @@ for categoria in CATEGORIES:
154
  st.success(f"Arquivo '{file}' baixado e removido.")
155
  st.rerun()
156
 
157
- st.markdown("</div>", unsafe_allow_html=True)
 
2
  import os
3
  import json
4
  import time
5
+ import subprocess
6
+ import random
7
+ import string
8
+ import mimetypes
9
 
10
  BASE_FOLDER = "uploaded_files"
11
  CATEGORIES = ["AVATAR WORLD", "BLOX FRUITS", "TOCA LIFE"]
 
45
 
46
  st.title("📂 File Manager por Categoria")
47
 
48
+ # --- Funções auxiliares ---
49
+ def random_string(n=12):
50
+ return ''.join(random.choices(string.ascii_letters + string.digits, k=n))
51
+
52
+ def randomize_video_metadata(file_path):
53
+ """Randomiza metadados de vídeos sem alterar resolução"""
54
+ mime, _ = mimetypes.guess_type(file_path)
55
+ if not mime or not mime.startswith("video"):
56
+ return # não é vídeo
57
+
58
+ temp_path = file_path + ".tmp"
59
+
60
+ metadata = {
61
+ "title": random_string(),
62
+ "artist": random_string(),
63
+ "album": random_string(),
64
+ "comment": random_string(),
65
+ "encoder": random_string(),
66
+ "description": random_string()
67
+ }
68
+
69
+ cmd = ["ffmpeg", "-y", "-i", file_path, "-map", "0", "-c", "copy"]
70
+ for k, v in metadata.items():
71
+ cmd.extend(["-metadata", f"{k}={v}"])
72
+ cmd.append(temp_path)
73
+
74
+ try:
75
+ subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
76
+ os.replace(temp_path, file_path)
77
+ print(f"✅ Metadados randomizados em {file_path}")
78
+ except Exception as e:
79
+ print(f"⚠ Erro ao randomizar {file_path}: {e}")
80
+
81
  def remove_expired_files():
82
+ """Remove arquivos vencidos automaticamente"""
83
  changed = False
84
  now = time.time()
85
  expired_files = []
 
104
  remove_expired_files()
105
 
106
  # --- Upload ---
 
107
  st.header("📤 Upload de Arquivos")
 
108
  st.subheader("Selecione uma categoria:")
109
 
110
  categoria = st.radio("Categoria:", CATEGORIES, index=None)
 
115
  accept_multiple_files=True,
116
  key=f"uploader_{categoria}"
117
  )
118
+ auto_delete = st.checkbox("🕒 Excluir automaticamente após 24 horas")
119
+ randomize_meta = st.checkbox("🔀 Randomizar metadados de vídeos")
120
 
121
  if uploaded_files:
122
  for uploaded_file in uploaded_files:
123
  folder = os.path.join(BASE_FOLDER, categoria)
124
  file_path = os.path.join(folder, uploaded_file.name)
125
+
126
+ # Salva arquivo
127
  with open(file_path, "wb") as f:
128
  f.write(uploaded_file.read())
129
 
130
+ # Se marcado → randomizar metadados (apenas vídeos)
131
+ if randomize_meta:
132
+ randomize_video_metadata(file_path)
133
+
134
  # Salvar expiração se marcada
135
  if auto_delete:
136
  key = f"{categoria}|||{uploaded_file.name}"
 
138
  with open(EXPIRATION_FILE, "w") as f:
139
  json.dump(expirations, f)
140
 
141
+ st.success("Arquivos enviados com sucesso!")
142
  st.rerun()
143
 
144
  # --- Lista de Arquivos agrupada por pasta ---
 
196
  st.success(f"Arquivo '{file}' baixado e removido.")
197
  st.rerun()
198
 
199
+ st.markdown("</div>", unsafe_allow_html=True)