melhorado explorer com teclas de atalhos funcionando e configurações de perfis do ffmpeg
This commit is contained in:
@@ -2,7 +2,7 @@ from nicegui import ui, app
|
||||
import os
|
||||
import asyncio
|
||||
from database import Category, FFmpegProfile, AppConfig
|
||||
from core.state import state # <--- ACESSAMOS O BOT POR AQUI AGORA
|
||||
from core.state import state
|
||||
|
||||
# --- CONSTANTES ---
|
||||
TMDB_GENRES = {
|
||||
@@ -26,315 +26,261 @@ ISO_LANGS = {
|
||||
'zho': 'Chinês (zho)', 'und': 'Indefinido (und)'
|
||||
}
|
||||
|
||||
# --- SELETOR DE PASTAS FLEXÍVEL ---
|
||||
async def pick_folder_dialog(start_path='/', allowed_root='/'):
|
||||
"""
|
||||
allowed_root: '/' permite tudo, '/media' restringe.
|
||||
"""
|
||||
# Se start_path for vazio ou None, começa na raiz permitida
|
||||
if not start_path: start_path = allowed_root
|
||||
|
||||
# Se o caminho salvo não começar com a raiz permitida, reseta
|
||||
if allowed_root != '/' and not start_path.startswith(allowed_root):
|
||||
start_path = allowed_root
|
||||
# Codecs disponíveis por Hardware
|
||||
HARDWARE_OPTS = {
|
||||
'vaapi': 'Intel/AMD VAAPI (Linux)',
|
||||
'nvenc': 'Nvidia NVENC',
|
||||
'qsv': 'Intel QuickSync (Proprietário)',
|
||||
'cpu': 'CPU (Software)',
|
||||
'copy': 'Copy (Sem Conversão)'
|
||||
}
|
||||
|
||||
CODEC_OPTS = {
|
||||
'vaapi': {'h264_vaapi': 'H.264 (VAAPI)', 'hevc_vaapi': 'H.265 (VAAPI)', 'vp9_vaapi': 'VP9 (VAAPI)'},
|
||||
'nvenc': {'h264_nvenc': 'H.264 (NVENC)', 'hevc_nvenc': 'H.265 (NVENC)'},
|
||||
'qsv': {'h264_qsv': 'H.264 (QSV)', 'hevc_qsv': 'H.265 (QSV)'},
|
||||
'cpu': {'libx264': 'H.264 (x264)', 'libx265': 'H.265 (x265)'},
|
||||
'copy': {'copy': 'Copiar Stream'}
|
||||
}
|
||||
|
||||
# --- SELETOR DE PASTAS ---
|
||||
async def pick_folder_dialog(start_path='/', allowed_root='/'):
|
||||
if not start_path: start_path = allowed_root
|
||||
if allowed_root != '/' and not start_path.startswith(allowed_root): start_path = allowed_root
|
||||
result = {'path': None}
|
||||
|
||||
with ui.dialog() as dialog, ui.card().classes('w-96 h-[500px] flex flex-col'):
|
||||
ui.label(f'Selecionar Pasta ({allowed_root})').classes('font-bold text-lg mb-2')
|
||||
path_label = ui.label(start_path).classes('text-xs bg-gray-100 p-2 border rounded w-full break-all font-mono')
|
||||
|
||||
scroll = ui.scroll_area().classes('flex-grow border rounded p-1 mt-2 bg-white')
|
||||
|
||||
async def load_dir(path):
|
||||
# Segurança: Garante que não saiu da jaula (se houver jaula)
|
||||
if allowed_root != '/' and not path.startswith(allowed_root):
|
||||
path = allowed_root
|
||||
|
||||
path_label.text = path
|
||||
scroll.clear()
|
||||
|
||||
if allowed_root != '/' and not path.startswith(allowed_root): path = allowed_root
|
||||
path_label.text = path; scroll.clear()
|
||||
try:
|
||||
# Botão Voltar (..)
|
||||
# Só mostra se não estiver na raiz do sistema OU na raiz permitida
|
||||
show_back = True
|
||||
if path == '/': show_back = False
|
||||
if allowed_root != '/' and path == allowed_root: show_back = False
|
||||
|
||||
if show_back:
|
||||
if path != '/' and path != allowed_root:
|
||||
parent = os.path.dirname(path)
|
||||
with scroll:
|
||||
ui.button('.. (Voltar)', on_click=lambda: load_dir(parent)).props('flat dense icon=arrow_upward align=left w-full')
|
||||
|
||||
# Lista Pastas
|
||||
with scroll: ui.button('.. (Voltar)', on_click=lambda: load_dir(parent)).props('flat dense icon=arrow_upward align=left w-full')
|
||||
with scroll:
|
||||
if os.path.exists(path):
|
||||
entries = sorted([e for e in os.scandir(path) if e.is_dir()], key=lambda x: x.name.lower())
|
||||
for entry in entries:
|
||||
for entry in sorted([e for e in os.scandir(path) if e.is_dir()], key=lambda x: x.name.lower()):
|
||||
ui.button(entry.name, on_click=lambda p=entry.path: load_dir(p)).props('flat dense icon=folder align=left w-full color=amber-8')
|
||||
else:
|
||||
ui.label('Caminho não encontrado.').classes('text-gray-400 italic p-2')
|
||||
|
||||
except Exception as e:
|
||||
with scroll: ui.label(f'Acesso negado: {e}').classes('text-red text-xs')
|
||||
|
||||
def select_this():
|
||||
result['path'] = path_label.text
|
||||
dialog.close()
|
||||
|
||||
with scroll: ui.label(f'Erro: {e}').classes('text-red text-xs')
|
||||
def select_this(): result['path'] = path_label.text; dialog.close()
|
||||
with ui.row().classes('w-full justify-between mt-auto pt-2'):
|
||||
ui.button('Cancelar', on_click=dialog.close).props('flat color=grey')
|
||||
ui.button('Selecionar Esta', on_click=select_this).props('flat icon=check color=green')
|
||||
|
||||
await load_dir(start_path)
|
||||
await dialog
|
||||
ui.button('Selecionar', on_click=select_this).props('flat icon=check color=green')
|
||||
await load_dir(start_path); await dialog
|
||||
return result['path']
|
||||
|
||||
# --- TELA PRINCIPAL ---
|
||||
def show():
|
||||
# Helper para pegar o bot de forma segura via State
|
||||
def get_bot():
|
||||
if state.watcher and state.watcher.bot:
|
||||
return state.watcher.bot
|
||||
return None
|
||||
def get_bot(): return state.watcher.bot if state.watcher else None
|
||||
|
||||
with ui.column().classes('w-full p-6'):
|
||||
ui.label('Configurações').classes('text-3xl font-light text-gray-800 mb-4')
|
||||
|
||||
with ui.tabs().classes('w-full') as tabs:
|
||||
tab_ident = ui.tab('Identificação', icon='search')
|
||||
tab_cats = ui.tab('Categorias', icon='category')
|
||||
tab_deploy = ui.tab('Deploy & Caminhos', icon='move_to_inbox')
|
||||
tab_deploy = ui.tab('Deploy', icon='move_to_inbox')
|
||||
tab_ffmpeg = ui.tab('Motor (FFmpeg)', icon='movie')
|
||||
tab_telegram = ui.tab('Telegram', icon='send')
|
||||
|
||||
with ui.tab_panels(tabs).classes('w-full bg-gray-50 p-4 rounded border'):
|
||||
|
||||
# --- ABA 1: IDENTIFICAÇÃO ---
|
||||
# --- IDENTIFICAÇÃO ---
|
||||
with ui.tab_panel(tab_ident):
|
||||
with ui.card().classes('w-full max-w-2xl mx-auto p-6'):
|
||||
ui.label('🔍 Configuração do Identificador').classes('text-2xl font-bold mb-4 text-indigo-600')
|
||||
tmdb_key = AppConfig.get_val('tmdb_api_key', '')
|
||||
|
||||
ui.input('API Key do TMDb', value=tmdb_key, password=True, on_change=lambda e: AppConfig.set_val('tmdb_api_key', e.value)).classes('w-full mb-4')
|
||||
with ui.grid(columns=2).classes('w-full gap-4'):
|
||||
ui.input('Idioma', value=AppConfig.get_val('tmdb_language', 'pt-BR'), on_change=lambda e: AppConfig.set_val('tmdb_language', e.value))
|
||||
ui.number('Confiança Auto (%)', value=int(AppConfig.get_val('min_confidence', '90')), min=50, max=100, on_change=lambda e: AppConfig.set_val('min_confidence', str(int(e.value))))
|
||||
|
||||
# --- ABA 2: CATEGORIAS (COM EDIÇÃO) ---
|
||||
# --- CATEGORIAS ---
|
||||
with ui.tab_panel(tab_cats):
|
||||
ui.label('Regras de Organização').classes('text-xl text-gray-700 mb-2')
|
||||
|
||||
editing_id = {'val': None}
|
||||
cats_container = ui.column().classes('w-full gap-2')
|
||||
form_card = ui.card().classes('w-full mb-4 bg-gray-100 p-4')
|
||||
editing_id = {'val': None}
|
||||
|
||||
def load_cats():
|
||||
cats_container.clear()
|
||||
cats = list(Category.select())
|
||||
|
||||
for cat in cats:
|
||||
for cat in list(Category.select()):
|
||||
g_ids = cat.genre_filters.split(',') if cat.genre_filters else []
|
||||
c_codes = cat.country_filters.split(',') if cat.country_filters else []
|
||||
g_names = [TMDB_GENRES.get(gid, gid) for gid in g_ids if gid]
|
||||
c_names = [COMMON_COUNTRIES.get(cc, cc) for cc in c_codes if cc]
|
||||
|
||||
desc = f"{cat.content_type.upper()}"
|
||||
if g_names: desc += f" | {', '.join(g_names)}"
|
||||
if c_names: desc += f" | {', '.join(c_names)}"
|
||||
|
||||
color_cls = 'bg-white border-gray-200'
|
||||
if 'Animação' in str(g_names) and 'Japão' in str(c_names): color_cls = 'bg-purple-50 border-purple-200'
|
||||
|
||||
color_cls = 'bg-purple-50 border-purple-200' if 'Animação' in str(g_names) and 'Japão' in str(c_names) else 'bg-white border-gray-200'
|
||||
|
||||
with cats_container, ui.card().classes(f'w-full flex-row items-center justify-between p-3 border {color_cls}'):
|
||||
with ui.row().classes('items-center gap-4'):
|
||||
icon = 'movie' if cat.content_type == 'movie' else ('tv' if cat.content_type == 'series' else 'shuffle')
|
||||
ui.icon(icon).classes('text-gray-600')
|
||||
ui.icon('movie' if cat.content_type == 'movie' else 'tv').classes('text-gray-600')
|
||||
with ui.column().classes('gap-0'):
|
||||
ui.label(cat.name).classes('font-bold text-lg')
|
||||
ui.label(desc).classes('text-xs text-gray-500')
|
||||
|
||||
with ui.row():
|
||||
ui.button(icon='edit', on_click=lambda c=cat: start_edit(c)).props('flat dense color=blue')
|
||||
ui.button(icon='delete', on_click=lambda c=cat: delete_cat(c)).props('flat dense color=red')
|
||||
ui.button(icon='delete', on_click=lambda c=cat: (c.delete_instance(), load_cats())).props('flat dense color=red')
|
||||
|
||||
def start_edit(cat):
|
||||
editing_id['val'] = cat.id
|
||||
name_input.value = cat.name
|
||||
type_select.value = cat.content_type
|
||||
name_input.value = cat.name; type_select.value = cat.content_type
|
||||
genre_select.value = cat.genre_filters.split(',') if cat.genre_filters else []
|
||||
country_select.value = cat.country_filters.split(',') if cat.country_filters else []
|
||||
|
||||
form_label.text = f"Editando: {cat.name}"
|
||||
btn_save.text = "Atualizar Regra"
|
||||
btn_save.props('color=blue icon=save')
|
||||
btn_cancel.classes(remove='hidden')
|
||||
form_card.classes(replace='bg-blue-50')
|
||||
btn_save.text = "Atualizar"; btn_cancel.classes(remove='hidden')
|
||||
|
||||
def cancel_edit():
|
||||
editing_id['val'] = None
|
||||
name_input.value = ''
|
||||
genre_select.value = []
|
||||
country_select.value = []
|
||||
form_label.text = "Nova Biblioteca"
|
||||
btn_save.text = "Adicionar Regra"
|
||||
btn_save.props('color=green icon=add')
|
||||
btn_cancel.classes(add='hidden')
|
||||
form_card.classes(replace='bg-gray-100')
|
||||
editing_id['val'] = None; name_input.value = ''; genre_select.value = []; country_select.value = []
|
||||
btn_save.text = "Adicionar"; btn_cancel.classes(add='hidden')
|
||||
|
||||
def save_cat():
|
||||
if not name_input.value: return
|
||||
g_str = ",".join(genre_select.value) if genre_select.value else ""
|
||||
c_str = ",".join(country_select.value) if country_select.value else ""
|
||||
data = {'name': name_input.value, 'content_type': type_select.value, 'genre_filters': ",".join(genre_select.value), 'country_filters': ",".join(country_select.value)}
|
||||
if not editing_id['val']: data['target_path'] = f"/media/{name_input.value}"
|
||||
|
||||
try:
|
||||
if editing_id['val']:
|
||||
Category.update(
|
||||
name=name_input.value,
|
||||
content_type=type_select.value,
|
||||
genre_filters=g_str,
|
||||
country_filters=c_str
|
||||
).where(Category.id == editing_id['val']).execute()
|
||||
ui.notify('Categoria atualizada!', type='positive')
|
||||
else:
|
||||
Category.create(
|
||||
name=name_input.value,
|
||||
target_path=f"/media/{name_input.value}",
|
||||
content_type=type_select.value,
|
||||
genre_filters=g_str,
|
||||
country_filters=c_str
|
||||
)
|
||||
ui.notify('Categoria criada!', type='positive')
|
||||
cancel_edit()
|
||||
load_cats()
|
||||
except Exception as e: ui.notify(f'Erro: {e}', type='negative')
|
||||
|
||||
def delete_cat(cat):
|
||||
cat.delete_instance()
|
||||
if editing_id['val'] == cat.id: cancel_edit()
|
||||
load_cats()
|
||||
if editing_id['val']: Category.update(**data).where(Category.id == editing_id['val']).execute()
|
||||
else: Category.create(**data)
|
||||
|
||||
# Correção: Notifica ANTES de recarregar a lista (para não perder o contexto do botão)
|
||||
ui.notify('Salvo!', type='positive')
|
||||
cancel_edit(); load_cats();
|
||||
|
||||
with form_card:
|
||||
with ui.row().classes('w-full justify-between items-center'):
|
||||
form_label = ui.label('Nova Biblioteca').classes('font-bold text-gray-700')
|
||||
btn_cancel = ui.button('Cancelar', on_click=cancel_edit).props('flat dense color=red').classes('hidden')
|
||||
|
||||
with ui.row().classes('w-full justify-between'):
|
||||
ui.label('Editor').classes('font-bold'); btn_cancel = ui.button('Cancelar', on_click=cancel_edit).props('flat dense color=red').classes('hidden')
|
||||
with ui.grid(columns=4).classes('w-full gap-2'):
|
||||
name_input = ui.input('Nome')
|
||||
type_select = ui.select({'mixed': 'Misto', 'movie': 'Só Filmes', 'series': 'Só Séries'}, value='mixed', label='Tipo')
|
||||
genre_select = ui.select(TMDB_GENRES, multiple=True, label='Gêneros').props('use-chips')
|
||||
country_select = ui.select(COMMON_COUNTRIES, multiple=True, label='Países').props('use-chips')
|
||||
|
||||
btn_save = ui.button('Adicionar Regra', on_click=save_cat).props('icon=add color=green').classes('mt-2 w-full')
|
||||
|
||||
btn_save = ui.button('Adicionar', on_click=save_cat).props('icon=add color=green').classes('mt-2 w-full')
|
||||
load_cats()
|
||||
|
||||
# --- ABA 3: DEPLOY (DESTINOS VS ORIGEM) ---
|
||||
# --- DEPLOY ---
|
||||
with ui.tab_panel(tab_deploy):
|
||||
|
||||
# ORIGEM (Permite Raiz /)
|
||||
with ui.card().classes('w-full mb-6 border-l-4 border-amber-500 bg-amber-50'):
|
||||
ui.label('📡 Origem dos Arquivos').classes('text-lg font-bold mb-2 text-amber-900')
|
||||
ui.label('📡 Origem').classes('text-lg font-bold mb-2 text-amber-900')
|
||||
monitor_path = AppConfig.get_val('monitor_path', '/downloads')
|
||||
|
||||
async def pick_source():
|
||||
# AQUI: allowed_root='/' permite navegar em tudo (incluindo /downloads)
|
||||
p = await pick_folder_dialog(mon_input.value, allowed_root='/')
|
||||
if p: mon_input.value = p
|
||||
|
||||
with ui.row().classes('w-full items-center gap-2'):
|
||||
mon_input = ui.input('Pasta Monitorada', value=monitor_path).classes('flex-grow font-mono bg-white rounded px-2')
|
||||
ui.button(icon='folder', on_click=pick_source).props('flat dense color=amber-9')
|
||||
|
||||
ui.button('Salvar Origem', on_click=lambda: (AppConfig.set_val('monitor_path', mon_input.value), ui.notify('Salvo!'))).classes('mt-2 bg-amber-600 text-white')
|
||||
|
||||
# DESTINOS (Restrito a /media para organização)
|
||||
ui.label('📂 Mapeamento de Destinos (/media)').classes('text-xl text-gray-700 mt-4')
|
||||
ui.label('📂 Destinos (/media)').classes('text-xl text-gray-700 mt-4')
|
||||
paths_container = ui.column().classes('w-full gap-2')
|
||||
|
||||
def load_deploy_paths():
|
||||
paths_container.clear()
|
||||
for cat in list(Category.select()):
|
||||
with paths_container, ui.card().classes('w-full p-4 flex-row items-center gap-4'):
|
||||
ui.label(cat.name).classes('font-bold w-32')
|
||||
path_input = ui.input(value=cat.target_path).classes('flex-grow font-mono')
|
||||
|
||||
async def pick_dest(i=path_input):
|
||||
# AQUI: allowed_root='/media' trava a navegação
|
||||
p = await pick_folder_dialog(i.value, allowed_root='/media')
|
||||
if p: i.value = p
|
||||
|
||||
ui.button(icon='folder', on_click=pick_dest).props('flat dense color=amber-8')
|
||||
ui.button(icon='save', on_click=lambda c=cat, p=path_input: (setattr(c, 'target_path', p.value), c.save(), ui.notify('Salvo!'))).props('flat round color=green')
|
||||
|
||||
load_deploy_paths()
|
||||
|
||||
# --- ABA 4: FFMPEG ---
|
||||
# --- MOTOR (FFMPEG MODULAR) ---
|
||||
with ui.tab_panel(tab_ffmpeg):
|
||||
ui.label('Perfis de Conversão').classes('text-xl text-gray-700')
|
||||
profiles_query = list(FFmpegProfile.select())
|
||||
profiles_dict = {p.id: p.name for p in profiles_query}
|
||||
active_profile = next((p for p in profiles_query if p.is_active), None)
|
||||
|
||||
def set_active_profile(e):
|
||||
if not e.value: return
|
||||
FFmpegProfile.update(is_active=False).execute()
|
||||
FFmpegProfile.update(is_active=True).where(FFmpegProfile.id == int(e.value)).execute()
|
||||
ui.notify(f'Perfil Ativado!', type='positive')
|
||||
ui.label('Gerenciador de Perfis').classes('text-xl text-gray-700')
|
||||
profiles_container = ui.column().classes('w-full gap-4')
|
||||
|
||||
select_profile = ui.select(profiles_dict, value=active_profile.id if active_profile else None, label='Perfil Ativo', on_change=set_active_profile).classes('w-64 mb-6')
|
||||
|
||||
for p in profiles_query:
|
||||
with ui.expansion(f"{p.name}", icon='tune').classes('w-full bg-white mb-2 border rounded'):
|
||||
with ui.column().classes('p-4 w-full'):
|
||||
with ui.grid(columns=2).classes('w-full gap-4'):
|
||||
c_name = ui.input('Nome', value=p.name)
|
||||
c_codec = ui.select({'h264_vaapi':'VAAPI','libx264':'CPU','copy':'Copy'}, value=p.video_codec, label='Codec')
|
||||
c_preset = ui.select(['fast', 'medium', 'slow'], value=p.preset, label='Preset')
|
||||
c_crf = ui.number('CRF', value=p.crf)
|
||||
c_audio = ui.select(ISO_LANGS, value=p.audio_langs.split(','), multiple=True, label='Áudios').props('use-chips')
|
||||
c_sub = ui.select(ISO_LANGS, value=p.subtitle_langs.split(','), multiple=True, label='Legendas').props('use-chips')
|
||||
def load_ffmpeg_profiles():
|
||||
profiles_container.clear()
|
||||
profiles = list(FFmpegProfile.select())
|
||||
active_p = next((p for p in profiles if p.is_active), None)
|
||||
|
||||
def set_active(e):
|
||||
if not e.value: return
|
||||
FFmpegProfile.update(is_active=False).execute()
|
||||
FFmpegProfile.update(is_active=True).where(FFmpegProfile.id == int(e.value)).execute()
|
||||
ui.notify(f'Perfil Ativado!', type='positive')
|
||||
|
||||
with profiles_container:
|
||||
ui.select({p.id: p.name for p in profiles}, value=active_p.id if active_p else None, label='Perfil Ativo (Global)', on_change=set_active).classes('w-full max-w-md mb-4 bg-green-50 p-2 rounded')
|
||||
|
||||
for p in profiles:
|
||||
with ui.expansion(f"{p.name} ({p.hardware_type.upper()})", icon='tune').classes('w-full bg-white mb-2 border rounded'):
|
||||
with ui.column().classes('p-4 w-full'):
|
||||
with ui.grid(columns=2).classes('w-full gap-4'):
|
||||
c_name = ui.input('Nome do Perfil', value=p.name)
|
||||
c_hw = ui.select(HARDWARE_OPTS, value=p.hardware_type, label='Tipo de Hardware')
|
||||
|
||||
with ui.grid(columns=3).classes('w-full gap-4'):
|
||||
hw_val = c_hw.value if c_hw.value in CODEC_OPTS else 'cpu'
|
||||
c_codec = ui.select(CODEC_OPTS[hw_val], value=p.video_codec, label='Codec de Vídeo')
|
||||
def update_codecs(e, el=c_codec):
|
||||
el.options = CODEC_OPTS.get(e.value, CODEC_OPTS['cpu'])
|
||||
el.value = list(el.options.keys())[0]
|
||||
el.update()
|
||||
c_hw.on('update:model-value', update_codecs)
|
||||
c_preset = ui.select(['fast', 'medium', 'slow', 'veryfast'], value=p.preset, label='Preset')
|
||||
c_crf = ui.number('CRF/Qualidade', value=p.crf)
|
||||
|
||||
def save_profile(prof=p, n=c_name, c=c_codec, pr=c_preset, cr=c_crf, a=c_audio, s=c_sub):
|
||||
prof.name = n.value; prof.video_codec = c.value; prof.preset = pr.value
|
||||
prof.crf = int(cr.value); prof.audio_langs = ",".join(a.value); prof.subtitle_langs = ",".join(s.value)
|
||||
prof.save()
|
||||
profiles_dict[prof.id] = prof.name
|
||||
select_profile.options = profiles_dict
|
||||
select_profile.update()
|
||||
ui.notify('Salvo!')
|
||||
ui.button('Salvar', on_click=save_profile).classes('mt-2')
|
||||
if p.hardware_type == 'vaapi':
|
||||
with ui.row().classes('bg-amber-50 p-2 rounded w-full items-center border border-amber-200'):
|
||||
ui.icon('warning', color='amber').classes('mr-2')
|
||||
c_hybrid = ui.checkbox('Modo Híbrido (Intel 4ª Gen / Haswell)', value=p.hybrid_decode).props('color=amber')
|
||||
ui.label('Ative se o vídeo x265 travar ou falhar. (Lê na CPU, Grava na GPU)').classes('text-xs text-gray-500')
|
||||
else:
|
||||
c_hybrid = None
|
||||
|
||||
# --- ABA 5: TELEGRAM ---
|
||||
with ui.grid(columns=2).classes('w-full gap-4'):
|
||||
c_audio = ui.select(ISO_LANGS, value=p.audio_langs.split(','), multiple=True, label='Áudios').props('use-chips')
|
||||
c_sub = ui.select(ISO_LANGS, value=p.subtitle_langs.split(','), multiple=True, label='Legendas').props('use-chips')
|
||||
|
||||
with ui.row().classes('w-full justify-end mt-4 gap-2'):
|
||||
def save_p(prof=p, n=c_name, hw=c_hw, c=c_codec, pr=c_preset, cr=c_crf, a=c_audio, s=c_sub, hy=c_hybrid):
|
||||
prof.name = n.value; prof.hardware_type = hw.value; prof.video_codec = c.value
|
||||
prof.preset = pr.value; prof.crf = int(cr.value)
|
||||
prof.audio_langs = ",".join(a.value); prof.subtitle_langs = ",".join(s.value)
|
||||
if hy: prof.hybrid_decode = hy.value
|
||||
prof.save()
|
||||
# CORREÇÃO: Inversão da ordem (Notifica -> Recarrega)
|
||||
ui.notify('Perfil Salvo!', type='positive')
|
||||
load_ffmpeg_profiles()
|
||||
|
||||
def delete_p(prof=p):
|
||||
if FFmpegProfile.select().count() <= 1:
|
||||
ui.notify('Não pode excluir o último perfil!', type='negative'); return
|
||||
prof.delete_instance()
|
||||
# CORREÇÃO: Inversão da ordem
|
||||
ui.notify('Perfil Excluído.')
|
||||
load_ffmpeg_profiles()
|
||||
|
||||
ui.button('Excluir', on_click=delete_p, icon='delete', color='red').props('flat')
|
||||
ui.button('Salvar Alterações', on_click=save_p, icon='save', color='green')
|
||||
|
||||
def create_new():
|
||||
FFmpegProfile.create(name="Novo Perfil", hardware_type='cpu', video_codec='libx264')
|
||||
load_ffmpeg_profiles()
|
||||
|
||||
ui.button('Criar Novo Perfil', on_click=create_new, icon='add').classes('w-full mt-4 bg-gray-200 text-gray-700')
|
||||
|
||||
load_ffmpeg_profiles()
|
||||
|
||||
# --- TELEGRAM ---
|
||||
with ui.tab_panel(tab_telegram):
|
||||
with ui.card().classes('w-full max-w-lg mx-auto p-6'):
|
||||
ui.label('🤖 Integração Telegram').classes('text-2xl font-bold mb-4 text-blue-600')
|
||||
|
||||
token_input = ui.input('Bot Token', value=AppConfig.get_val('telegram_token', '')).props('password').classes('w-full mb-2')
|
||||
chat_input = ui.input('Chat ID', value=AppConfig.get_val('telegram_chat_id', '')).classes('w-full mb-6')
|
||||
|
||||
async def save_and_restart():
|
||||
AppConfig.set_val('telegram_token', token_input.value)
|
||||
AppConfig.set_val('telegram_chat_id', chat_input.value)
|
||||
ui.notify('Salvando...', type='warning')
|
||||
|
||||
t_tok = ui.input('Bot Token', value=AppConfig.get_val('telegram_token', '')).props('password').classes('w-full mb-2')
|
||||
t_chat = ui.input('Chat ID', value=AppConfig.get_val('telegram_chat_id', '')).classes('w-full mb-6')
|
||||
async def save_tg():
|
||||
AppConfig.set_val('telegram_token', t_tok.value); AppConfig.set_val('telegram_chat_id', t_chat.value)
|
||||
bot = get_bot()
|
||||
if bot:
|
||||
await bot.restart()
|
||||
ui.notify('Bot Reiniciado!', type='positive')
|
||||
else:
|
||||
ui.notify('Salvo, mas Bot não está rodando.', type='warning')
|
||||
|
||||
async def test_connection():
|
||||
if bot: await bot.restart()
|
||||
ui.notify('Salvo!', type='positive')
|
||||
async def test_tg():
|
||||
bot = get_bot()
|
||||
if bot:
|
||||
ui.notify('Enviando mensagem...')
|
||||
success = await bot.send_test_msg()
|
||||
if success: ui.notify('Mensagem enviada!', type='positive')
|
||||
else: ui.notify('Falha no envio.', type='negative')
|
||||
else:
|
||||
ui.notify('Bot offline.', type='negative')
|
||||
|
||||
if bot and await bot.send_test_msg(): ui.notify('Sucesso!', type='positive')
|
||||
else: ui.notify('Falha.', type='negative')
|
||||
with ui.row().classes('w-full gap-2'):
|
||||
ui.button('Salvar e Reiniciar', on_click=save_and_restart).props('icon=save color=blue').classes('flex-grow')
|
||||
ui.button('Testar', on_click=test_connection).props('icon=send color=green')
|
||||
ui.button('Salvar', on_click=save_tg).classes('flex-grow'); ui.button('Testar', on_click=test_tg).props('color=green')
|
||||
Reference in New Issue
Block a user