NarratoAI/webui/utils/cache.py

35 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import streamlit as st
import os
import glob
from app.utils import utils
def get_fonts_cache(font_dir):
if 'fonts_cache' not in st.session_state:
fonts = []
for root, dirs, files in os.walk(font_dir):
for file in files:
# 支持常见字体格式少字体时也能被UI识别
if file.lower().endswith((".ttf", ".ttc", ".otf")):
fonts.append(file)
fonts.sort()
st.session_state['fonts_cache'] = fonts
return st.session_state['fonts_cache']
def get_video_files_cache():
if 'video_files_cache' not in st.session_state:
video_files = []
for suffix in ["*.mp4", "*.mov", "*.avi", "*.mkv"]:
video_files.extend(glob.glob(os.path.join(utils.video_dir(), suffix)))
st.session_state['video_files_cache'] = video_files[::-1]
return st.session_state['video_files_cache']
def get_songs_cache(song_dir):
if 'songs_cache' not in st.session_state:
songs = []
for root, dirs, files in os.walk(song_dir):
for file in files:
if file.endswith(".mp3"):
songs.append(file)
st.session_state['songs_cache'] = songs
return st.session_state['songs_cache']