Thumbnails : now in config, create folder if needed, pre_run()

This commit is contained in:
Your Name 2023-01-06 14:43:17 +00:00
parent 13e45d50b9
commit afaaead835
1 changed files with 17 additions and 9 deletions

26
app.py
View File

@ -112,8 +112,8 @@ def led_init():
''' '''
Set ACT and PWR leds trigger and turn them off Set ACT and PWR leds trigger and turn them off
''' '''
os.system('echo none | sudo tee /sys/class/leds/led0/trigger') os.system('echo none | sudo tee /sys/class/leds/led0/trigger 1> /dev/null')
os.system('echo none | sudo tee /sys/class/leds/led1/trigger') os.system('echo none | sudo tee /sys/class/leds/led1/trigger 1> /dev/null')
led_set(0, 0) led_set(0, 0)
led_set(1, 0) led_set(1, 0)
@ -124,7 +124,7 @@ def led_set(led_id, state):
''' '''
# led_id : 0 = PWR, 1 = ACT # led_id : 0 = PWR, 1 = ACT
# state : 0 = off, 1 = on # state : 0 = off, 1 = on
os.system("echo {} | sudo tee /sys/class/leds/led{}/brightness".format(str(state), str(led_id))) os.system("echo {} | sudo tee /sys/class/leds/led{}/brightness 1> /dev/null".format(str(state), str(led_id)))
def blink_pi(n): def blink_pi(n):
@ -176,8 +176,10 @@ def generate_thumbnails():
os.mkdir(thumbnails_folder) os.mkdir(thumbnails_folder)
for media in media_files: for media in media_files:
if not os.path.exists(os.path.join(thumbnails_folder, media["filename"]) + ".jpg"): if not os.path.exists(os.path.join(thumbnails_folder, media["filename"]) + ".jpg"):
subprocess.call(['ffmpeg', '-i', os.path.join(upload_folder, media["filename"]), '-q:v', '30', '-s', '160x120', '-vf', 'boxblur=2', '-ss', '00:00:01.000', '-vframes', '1', os.path.join(thumbnails_folder, media["filename"]) + ".jpg", "-y"]) print("Generating thumbnail for {}...".format(media["filename"]))
subprocess.call(['ffmpeg', '-v', '-8','-i', os.path.join(upload_folder, media["filename"]), '-q:v', '20', '-s', '320x240', '-vf', 'boxblur=2', '-ss', '00:00:01.000', '-vframes', '1', os.path.join(thumbnails_folder, media["filename"]) + ".jpg", "-y"])
else:
print("Thumbnail exists for {}...".format(media["filename"]))
def value_in_dict_list(value, dict_list, key): def value_in_dict_list(value, dict_list, key):
for dictionary in dict_list: for dictionary in dict_list:
@ -185,6 +187,16 @@ def value_in_dict_list(value, dict_list, key):
return dictionary return dictionary
return False return False
def pre_run():
generate_thumbnails()
# Turn ACT and POW leds off on start
if running_on_rpi():
led_init()
with app.app_context():
pre_run()
@app.route("/") @app.route("/")
@auth.login_required @auth.login_required
def main(): def main():
@ -310,9 +322,5 @@ def get_thumbnail(media):
if __name__ == '__main__': if __name__ == '__main__':
generate_thumbnails()
# Turn ACT and POW leds off on start
if running_on_rpi():
led_init()
# ~ app.run() # ~ app.run()
serve(app, host='127.0.0.1', port=5000, url_scheme=HTTP_url_scheme) serve(app, host='127.0.0.1', port=5000, url_scheme=HTTP_url_scheme)