Compare commits
No commits in common. "7706b0aa0ba96525a258dcec67d8934cff721454" and "4e76be200aae9d468a21eab982cf45792f01301e" have entirely different histories.
7706b0aa0b
...
4e76be200a
@ -11,11 +11,7 @@ contentpath = modules.db_connect.contentpath()
|
||||
|
||||
# Fetch and present all information from one _index.nfo-file
|
||||
@app.route('/game', methods=['POST'])
|
||||
def game(
|
||||
predefinednfo=False,
|
||||
return_dict=False,
|
||||
skip_artwork=False,
|
||||
skip_displayimage=False):
|
||||
def game(predefinednfo=False, return_dict=False, skip_artwork=False):
|
||||
nfopath = ""
|
||||
if predefinednfo is not False:
|
||||
nfopath = predefinednfo
|
||||
@ -23,36 +19,31 @@ def game(
|
||||
nfopath = base64.b64decode(request.json).decode()
|
||||
nfo = json.load(open(nfopath, 'r'))
|
||||
nfo['path'] = base64.b64encode(nfopath.encode('utf-8')).decode()
|
||||
nfo['nfo'] = os.path.basename(nfopath)
|
||||
|
||||
# Add front cover artwork in medium size
|
||||
# TODO: Refactor to use next() instead of nested for()
|
||||
if skip_displayimage is True:
|
||||
nfo['game']['displayimage'] = ""
|
||||
else:
|
||||
artpath = os.path.dirname(nfopath)+'/art/'
|
||||
i = 0
|
||||
if 'artwork' in nfo['game']:
|
||||
if nfo['game']['artwork']:
|
||||
artpath = os.path.dirname(nfopath)+'/art/'
|
||||
i = 0
|
||||
if 'artwork' in nfo['game']:
|
||||
if nfo['game']['artwork']:
|
||||
for art in nfo['game']['artwork']:
|
||||
try:
|
||||
if skip_artwork is False:
|
||||
nfo['game']['artwork'][i]['data'] = reduceartcv2(
|
||||
artpath+art['filename'], 'thumbnail')
|
||||
if art['type'] == 'front':
|
||||
nfo['game']['displayimage'] = reduceartcv2(
|
||||
artpath+art['filename'], 'thumbnail')
|
||||
except Exception as e:
|
||||
print("Failing cover: " + art['filename'])
|
||||
print(e)
|
||||
i += 1
|
||||
if 'displayimage' not in nfo['game']:
|
||||
for art in nfo['game']['artwork']:
|
||||
try:
|
||||
if skip_artwork is False:
|
||||
nfo['game']['artwork'][i]['data'] = reduceartcv2(
|
||||
artpath+art['filename'], 'thumbnail')
|
||||
if art['type'] == 'front':
|
||||
nfo['game']['displayimage'] = reduceartcv2(
|
||||
artpath+art['filename'], 'thumbnail')
|
||||
except Exception as e:
|
||||
print("Failing cover: " + art['filename'])
|
||||
print(e)
|
||||
i += 1
|
||||
if 'displayimage' not in nfo['game']:
|
||||
for art in nfo['game']['artwork']:
|
||||
if art['type'] in ['cd', 'dvd']:
|
||||
nfo['game']['displayimage'] = reduceartcv2(
|
||||
artpath+art['filename'], 'thumbnail')
|
||||
else:
|
||||
nfo['game']['displayimage'] = ""
|
||||
if art['type'] in ['cd', 'dvd']:
|
||||
nfo['game']['displayimage'] = reduceartcv2(
|
||||
artpath+art['filename'], 'thumbnail')
|
||||
else:
|
||||
nfo['game']['displayimage'] = ""
|
||||
if return_dict is False:
|
||||
return jsonify(nfo)
|
||||
return nfo
|
||||
|
||||
@ -3,7 +3,6 @@ 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()
|
||||
@ -29,26 +28,10 @@ def update_gamelist():
|
||||
glist = []
|
||||
for nfo in nfolist:
|
||||
try:
|
||||
game = modules.game.game(nfo, True, True, True)
|
||||
game = modules.game.game(nfo, 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)
|
||||
|
||||
@ -1,91 +0,0 @@
|
||||
import modules.db_connect
|
||||
import glob
|
||||
import os
|
||||
import json
|
||||
from modules.functions import reduceartcv2
|
||||
|
||||
contentpath = modules.db_connect.contentpath()
|
||||
nfosuffix = modules.db_connect.nfosuffix()
|
||||
|
||||
global nfofiles
|
||||
nfofiles = []
|
||||
|
||||
global thumbnails
|
||||
thumbnails = []
|
||||
|
||||
global thumbnails_update_status
|
||||
thumbnails_update_status = False
|
||||
|
||||
|
||||
# Set nfo-files list
|
||||
def set_nfofiles(nfofiles_list):
|
||||
global nfofiles
|
||||
nfofiles = nfofiles_list
|
||||
return True
|
||||
|
||||
|
||||
# Get nfo-files list
|
||||
def get_nfofiles():
|
||||
global nfofiles
|
||||
return nfofiles
|
||||
|
||||
|
||||
# Get list of all .nfo-files
|
||||
def update_nfofiles(return_list=False):
|
||||
newlist = list(dict.fromkeys(glob.glob(
|
||||
str(contentpath)+'/**/**/*'+nfosuffix, recursive=True)))
|
||||
set_nfofiles(newlist)
|
||||
if return_list is True:
|
||||
return newlist
|
||||
return True
|
||||
|
||||
|
||||
# Set thumbnails list
|
||||
def set_thumbnails(thumbnails_list):
|
||||
global thumbnails
|
||||
thumbnails = thumbnails_list
|
||||
return True
|
||||
|
||||
|
||||
# Get thumbnails list
|
||||
def get_thumbnails():
|
||||
global thumbnails
|
||||
return thumbnails
|
||||
|
||||
|
||||
# Update thumbnails list
|
||||
def update_thumbnails(return_list=False):
|
||||
global thumbnails_update_status
|
||||
thumbnails_update_status = True
|
||||
nfos = []
|
||||
nfolist = get_nfofiles()
|
||||
if len(nfolist) == 0:
|
||||
nfolist = update_nfofiles(True)
|
||||
j = 0
|
||||
for nfopath in nfolist:
|
||||
nfo = json.load(open(nfopath, 'r'))
|
||||
current_nfo = {"nfo": os.path.basename(nfopath)}
|
||||
artpath = os.path.dirname(nfopath)+'/art/'
|
||||
if 'artwork' in nfo['game']:
|
||||
if nfo['game']['artwork']:
|
||||
art = next((
|
||||
artw for artw in nfo['game']['artwork'] if artw['type'] ==
|
||||
"front"), False)
|
||||
if art is False:
|
||||
art = next((
|
||||
artw for artw in nfo['game']['artwork'] if
|
||||
artw['type'] in ['cd', 'dvd']), False)
|
||||
if art is not False:
|
||||
try:
|
||||
current_nfo['displayimage'] = reduceartcv2(
|
||||
artpath+art['filename'], 'thumbnail')
|
||||
except Exception as e:
|
||||
print("Failing cover:", art['filename'], e)
|
||||
nfos.append(current_nfo)
|
||||
j += 1
|
||||
print("[", j, "/", len(nfofiles), "]", nfopath, "added")
|
||||
set_thumbnails(nfos)
|
||||
thumbnails_update_status = False
|
||||
if return_list is True:
|
||||
return nfos
|
||||
return True
|
||||
@ -8,7 +8,6 @@
|
||||
"lang_gamelist_title": "Gamelist",
|
||||
"lang_gamelist_body_header": "Gamelist",
|
||||
"lang_gamelist_body_ingress": "Here there be a bunch of games listed",
|
||||
"lang_gamelist_get_thumbnails_button": "Get thumbnails",
|
||||
"lang_game_title": "Game",
|
||||
"lang_game_body_header": "Game",
|
||||
"lang_game_body_ingress": "Here there be info about games n stuff",
|
||||
|
||||
@ -5,6 +5,5 @@
|
||||
"lang_home_change_language_button": "Byt",
|
||||
"lang_navigation_home": "Hem",
|
||||
"lang_navigation_gamelist": "Spellista",
|
||||
"lang_gamelist_get_thumbnails_button": "Hämta bilder",
|
||||
"lang_game_download_zip_button": "Ladda ned Zip"
|
||||
}
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
from __main__ import app
|
||||
import json
|
||||
import requests
|
||||
from flask import render_template, redirect, url_for, request
|
||||
from flask import render_template, redirect, url_for
|
||||
import modules.init
|
||||
import base64
|
||||
|
||||
host_endpoint = modules.init.host_endpoint()
|
||||
languages = modules.init.get_languages()
|
||||
@ -18,11 +17,10 @@ def lang(lang_code):
|
||||
|
||||
|
||||
# Show gamelist
|
||||
@app.route("/<lang_code>/gamelist", methods=["GET", "POST"])
|
||||
@app.route("/<lang_code>/gamelist")
|
||||
# @app.route("/gamelist")
|
||||
def gamelist(lang_code):
|
||||
lang_code = lang(lang_code)
|
||||
thumbnails = request.args.get("thumbnails")
|
||||
glist = None
|
||||
try:
|
||||
glist = json.loads((requests.get(
|
||||
@ -43,27 +41,9 @@ def gamelist(lang_code):
|
||||
except Exception as e:
|
||||
print("error type: ", type(e))
|
||||
|
||||
# If thumbnails are to be collected
|
||||
thumbnailslist = []
|
||||
if thumbnails == "get":
|
||||
try:
|
||||
thumbnailslist = json.loads((requests.get(
|
||||
host_endpoint + '/gamelist/displayimage').content).decode())
|
||||
|
||||
except request.exceptions.ConnectionError as e:
|
||||
print(e)
|
||||
em = "Cannot connect to the API, is the server up?"
|
||||
et = "ConnectionError"
|
||||
error_object = {"error_type": et, "error_message": em}
|
||||
return render_template('error.html', **languages[lang_code],
|
||||
lang_code=lang_code, error_object=error_object)
|
||||
|
||||
except Exception as e:
|
||||
print("error type:", type(e))
|
||||
|
||||
if glist is not None:
|
||||
return render_template('gamelist.html', gamelist=glist,
|
||||
**languages[lang_code], lang_code=lang_code, thumbnails=thumbnailslist)
|
||||
**languages[lang_code], lang_code=lang_code)
|
||||
|
||||
|
||||
# Update/Refresh the gamelist by re-scanning the game archive (slow)
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
{% block content %}
|
||||
<h1>{{lang_gamelist_body_header}}</h1>
|
||||
<p>{{lang_gamelist_body_ingress}}</p>
|
||||
<a href="{{ url_for('gamelist', thumbnails="get", lang_code=lang_code)}}"><button type="button">{{lang_gamelist_get_thumbnails_button}}</button></a>
|
||||
<table class="game">
|
||||
<tr>
|
||||
<th>{{lang_game_artwork}}</th>
|
||||
@ -21,22 +20,12 @@
|
||||
</tr>
|
||||
{% for item in gamelist %}
|
||||
<tr>
|
||||
{% for thumbnail in thumbnails %}
|
||||
{% if thumbnail.nfo == item.nfo %}
|
||||
<td><a href="{{ url_for('game', gamepath=item.path, lang_code=lang_code)}}"><img src="data:image/jpeg;base64,{{thumbnail.displayimage}}"></img></a></td>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<td></td>
|
||||
{% endfor %}
|
||||
<td><a href="{{ url_for('game', gamepath=item.path, lang_code=lang_code)}}"><img src="data:image/jpeg;base64,{{item.game.displayimage}}"></img></a></td>
|
||||
<td><a href="{{ url_for('game', gamepath=item.path, lang_code=lang_code)}}">{{item.game.title}}</a></td>
|
||||
<td>{{item.game.year}}</td>
|
||||
<td>{{item.game.genre}}</td>
|
||||
<td>{{item.game.developer}}</td>
|
||||
<td>
|
||||
{% for mode in item.game.playermodes %}
|
||||
<p>{{mode}} </p>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>{{item.game.playermodes}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user