bcns-gameDistributionSystem/api/modules/gamelist.py
odecif fcf71d6fea Gamelist performance improvements
* Separated /gamelist to 2 calls: /gamelist and /gamelist/thumbnails.
* Refactored nested for-loop with a next() when looping artwork

[fixes #20]
2023-09-20 15:13:42 +02:00

55 lines
1.5 KiB
Python

from __main__ import app
from flask import jsonify, make_response
import modules.db_connect
from modules.functions import get_gamelist, set_gamelist
import modules.game
from modules.gamelist_functions import get_thumbnails, update_thumbnails
import glob
contentpath = modules.db_connect.contentpath()
nfosuffix = modules.db_connect.nfosuffix()
# Collects all _index.nfo-files present and crunches them into a list of
# games.
@app.route('/gamelist', methods=['GET'])
def show_gamelist():
if get_gamelist():
return jsonify(get_gamelist())
update_gamelist()
return jsonify(get_gamelist())
# Updates the gamelist by searching for new nfo's
@app.route('/gamelist/update', methods=['GET'])
def update_gamelist():
nfolist = list(dict.fromkeys(glob.glob(
str(contentpath)+'/**/**/*'+nfosuffix, recursive=True)))
glist = []
for nfo in nfolist:
try:
game = modules.game.game(nfo, True, True, True)
glist.append(game)
except Exception as e:
print(nfo, e)
set_gamelist(glist)
return make_response("<h1>Success</h1>", 200)
# Fetch displayimage for all nfo-files
@app.route('/gamelist/displayimage')
def get_displayimages(update=False):
thumbnails = get_thumbnails()
if (len(thumbnails) == 0) or update:
thumbnails = update_thumbnails(True)
return jsonify(thumbnails)
# Update displayimages
@app.route('/gamelist/displayimage/update')
def update_displayimages():
update_thumbnails()
return make_response("<h1>Success</h1>", 200)