pcdoido2 commited on
Commit
31621d9
·
verified ·
1 Parent(s): 986de79

Update arquivos.py

Browse files
Files changed (1) hide show
  1. arquivos.py +11 -149
arquivos.py CHANGED
@@ -1,157 +1,19 @@
1
- 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"]
8
- EXPIRATION_FILE = "expirations.json"
9
 
10
- # --- Estilos CSS ---
11
- st.markdown("""
12
- <style>
13
- .file-box {
14
- border: 1px solid #ccc;
15
- padding: 10px;
16
- margin-bottom: 10px;
17
- border-radius: 5px;
18
- background-color: #f9f9f9;
19
- }
20
- .file-name {
21
- font-size: 18px;
22
- font-weight: bold;
23
- }
24
- .expire-text {
25
- font-size: 14px;
26
- color: #555;
27
- }
28
- </style>
29
- """, unsafe_allow_html=True)
30
-
31
- # Cria as pastas se não existirem
32
  for cat in CATEGORIES:
33
  os.makedirs(os.path.join(BASE_FOLDER, cat), exist_ok=True)
34
 
35
- # Carrega dados de expiração
36
- if os.path.exists(EXPIRATION_FILE):
37
- with open(EXPIRATION_FILE, "r") as f:
38
- expirations = json.load(f)
39
- else:
40
- expirations = {}
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 = []
49
-
50
- for file_full, expire_time in list(expirations.items()):
51
- cat, file = file_full.split("|||")
52
- file_path = os.path.join(BASE_FOLDER, cat, file)
53
- if now > expire_time:
54
- if os.path.exists(file_path):
55
- os.remove(file_path)
56
- expired_files.append(file_full)
57
- changed = True
58
-
59
- for file_full in expired_files:
60
- expirations.pop(file_full)
61
-
62
- if changed:
63
- with open(EXPIRATION_FILE, "w") as f:
64
- json.dump(expirations, f)
65
-
66
- # --- Apagar arquivos vencidos ao iniciar ---
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)
76
-
77
- if categoria:
78
- uploaded_files = st.file_uploader(
79
- f"Selecione arquivos para '{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}"
95
- expirations[key] = time.time() + 24 * 60 * 60
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 ---
103
- st.header("📄 Arquivos Disponíveis")
104
-
105
- for categoria in CATEGORIES:
106
- folder = os.path.join(BASE_FOLDER, categoria)
107
- files = os.listdir(folder)
108
-
109
- st.subheader(f"📁 {categoria}")
110
-
111
- if not files:
112
- st.info("Nenhum arquivo na categoria.")
113
- else:
114
- for file in files:
115
- st.markdown(f"<div class='file-box'>", unsafe_allow_html=True)
116
- st.markdown(f"<div class='file-name'>{file}</div>", unsafe_allow_html=True)
117
-
118
- key = f"{categoria}|||{file}"
119
-
120
- expira = expirations.get(key)
121
- if expira:
122
- restante = int(expira - time.time())
123
- if restante > 0:
124
- restante_horas = restante // 3600
125
- restante_min = (restante % 3600) // 60
126
- st.markdown(
127
- f"<div class='expire-text'>⏳ Expira em {restante_horas}h {restante_min}min</div>",
128
- unsafe_allow_html=True)
129
- else:
130
- st.markdown("<div class='expire-text'>⚠ Expiração iminente</div>", unsafe_allow_html=True)
131
-
132
- col1, col2, col3 = st.columns(3)
133
-
134
- with col1:
135
- with open(os.path.join(folder, file), "rb") as f_obj:
136
- st.download_button("⬇ Download", f_obj, file_name=file, key=f"down_{categoria}_{file}")
137
-
138
- with col2:
139
- if st.button("🗑 Excluir", key=f"delete_{categoria}_{file}"):
140
- os.remove(os.path.join(folder, file))
141
- expirations.pop(key, None)
142
- with open(EXPIRATION_FILE, "w") as f:
143
- json.dump(expirations, f)
144
- st.success(f"Arquivo '{file}' excluído.")
145
- st.rerun()
146
-
147
- with col3:
148
- with open(os.path.join(folder, file), "rb") as f_obj:
149
- if st.download_button("⬇ Baixar & Apagar", f_obj, file_name=file, key=f"download_delete_{categoria}_{file}"):
150
- os.remove(os.path.join(folder, file))
151
- expirations.pop(key, None)
152
- with open(EXPIRATION_FILE, "w") as f:
153
- json.dump(expirations, f)
154
- st.success(f"Arquivo '{file}' baixado e removido.")
155
- st.rerun()
156
-
157
- st.markdown("</div>", unsafe_allow_html=True)
 
 
1
  import os
2
+ import shutil
 
3
 
4
  BASE_FOLDER = "uploaded_files"
5
  CATEGORIES = ["AVATAR WORLD", "BLOX FRUITS", "TOCA LIFE"]
 
6
 
7
+ # Criar pastas se não existirem
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  for cat in CATEGORIES:
9
  os.makedirs(os.path.join(BASE_FOLDER, cat), exist_ok=True)
10
 
11
+ def salvar_no_gerenciador(video_path, categoria):
12
+ """
13
+ Copia o vídeo finalizado para a categoria no gerenciador de arquivos.
14
+ """
15
+ if categoria not in CATEGORIES:
16
+ raise ValueError("Categoria inválida.")
17
+ destino = os.path.join(BASE_FOLDER, categoria, os.path.basename(video_path))
18
+ shutil.copy(video_path, destino)
19
+ print(f"Arquivo {video_path} salvo em {destino}")