Compare commits
No commits in common. "5443e3b93ecc86241c5e19a111145779ab964399" and "7706b0aa0ba96525a258dcec67d8934cff721454" have entirely different histories.
5443e3b93e
...
7706b0aa0b
@ -3,9 +3,7 @@ from flask import jsonify, make_response
|
|||||||
import modules.db_connect
|
import modules.db_connect
|
||||||
from modules.functions import get_gamelist, set_gamelist
|
from modules.functions import get_gamelist, set_gamelist
|
||||||
import modules.game
|
import modules.game
|
||||||
from modules.gamelist_functions import (
|
from modules.gamelist_functions import get_thumbnails, update_thumbnails
|
||||||
get_threaded_thumbnails,
|
|
||||||
update_threaded_thumbnails)
|
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
contentpath = modules.db_connect.contentpath()
|
contentpath = modules.db_connect.contentpath()
|
||||||
@ -43,14 +41,14 @@ def update_gamelist():
|
|||||||
# Fetch displayimage for all nfo-files
|
# Fetch displayimage for all nfo-files
|
||||||
@app.route('/gamelist/displayimage')
|
@app.route('/gamelist/displayimage')
|
||||||
def get_displayimages(update=False):
|
def get_displayimages(update=False):
|
||||||
thumbnails = get_threaded_thumbnails()
|
thumbnails = get_thumbnails()
|
||||||
if (len(thumbnails) == 0) or update:
|
if (len(thumbnails) == 0) or update:
|
||||||
thumbnails = update_threaded_thumbnails(True)
|
thumbnails = update_thumbnails(True)
|
||||||
return jsonify(thumbnails)
|
return jsonify(thumbnails)
|
||||||
|
|
||||||
|
|
||||||
# Update displayimages
|
# Update displayimages
|
||||||
@app.route('/gamelist/displayimage/update')
|
@app.route('/gamelist/displayimage/update')
|
||||||
def update_displayimages():
|
def update_displayimages():
|
||||||
update_threaded_thumbnails()
|
update_thumbnails()
|
||||||
return make_response("<h1>Success</h1>", 200)
|
return make_response("<h1>Success</h1>", 200)
|
||||||
|
|||||||
@ -3,9 +3,6 @@ import glob
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from modules.functions import reduceartcv2
|
from modules.functions import reduceartcv2
|
||||||
import threading
|
|
||||||
from queue import Queue
|
|
||||||
import time
|
|
||||||
|
|
||||||
contentpath = modules.db_connect.contentpath()
|
contentpath = modules.db_connect.contentpath()
|
||||||
nfosuffix = modules.db_connect.nfosuffix()
|
nfosuffix = modules.db_connect.nfosuffix()
|
||||||
@ -13,12 +10,12 @@ nfosuffix = modules.db_connect.nfosuffix()
|
|||||||
global nfofiles
|
global nfofiles
|
||||||
nfofiles = []
|
nfofiles = []
|
||||||
|
|
||||||
|
global thumbnails
|
||||||
|
thumbnails = []
|
||||||
|
|
||||||
global thumbnails_update_status
|
global thumbnails_update_status
|
||||||
thumbnails_update_status = False
|
thumbnails_update_status = False
|
||||||
|
|
||||||
global threaded_thumbnails
|
|
||||||
threaded_thumbnails = []
|
|
||||||
|
|
||||||
|
|
||||||
# Set nfo-files list
|
# Set nfo-files list
|
||||||
def set_nfofiles(nfofiles_list):
|
def set_nfofiles(nfofiles_list):
|
||||||
@ -43,30 +40,27 @@ def update_nfofiles(return_list=False):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# Set threaded_thumbnails list
|
# Set thumbnails list
|
||||||
def set_threaded_thumbnails(thumbnails_list):
|
def set_thumbnails(thumbnails_list):
|
||||||
global threaded_thumbnails
|
global thumbnails
|
||||||
threaded_thumbnails = thumbnails_list
|
thumbnails = thumbnails_list
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# Get threaded_thumbnails list
|
# Get thumbnails list
|
||||||
def get_threaded_thumbnails():
|
def get_thumbnails():
|
||||||
global threaded_thumbnails
|
global thumbnails
|
||||||
return threaded_thumbnails
|
return thumbnails
|
||||||
|
|
||||||
|
|
||||||
# Threaded printer
|
# Update thumbnails list
|
||||||
def printer(queue):
|
def update_thumbnails(return_list=False):
|
||||||
while True:
|
global thumbnails_update_status
|
||||||
message = queue.get()
|
thumbnails_update_status = True
|
||||||
print(message)
|
|
||||||
|
|
||||||
|
|
||||||
# Create thumbnails
|
|
||||||
def create_thumbnails(nfolist, lock, queue):
|
|
||||||
global threaded_thumbnails
|
|
||||||
nfos = []
|
nfos = []
|
||||||
|
nfolist = get_nfofiles()
|
||||||
|
if len(nfolist) == 0:
|
||||||
|
nfolist = update_nfofiles(True)
|
||||||
j = 0
|
j = 0
|
||||||
for nfopath in nfolist:
|
for nfopath in nfolist:
|
||||||
nfo = json.load(open(nfopath, 'r'))
|
nfo = json.load(open(nfopath, 'r'))
|
||||||
@ -86,54 +80,12 @@ def create_thumbnails(nfolist, lock, queue):
|
|||||||
current_nfo['displayimage'] = reduceartcv2(
|
current_nfo['displayimage'] = reduceartcv2(
|
||||||
artpath+art['filename'], 'thumbnail')
|
artpath+art['filename'], 'thumbnail')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
queue.put((
|
print("Failing cover:", art['filename'], e)
|
||||||
"Failing cover:" +
|
|
||||||
str(art['filename']) +
|
|
||||||
str(e)))
|
|
||||||
nfos.append(current_nfo)
|
nfos.append(current_nfo)
|
||||||
with lock:
|
j += 1
|
||||||
j += 1
|
print("[", j, "/", len(nfofiles), "]", nfopath, "added")
|
||||||
queue.put((
|
set_thumbnails(nfos)
|
||||||
"[" +
|
thumbnails_update_status = False
|
||||||
str(j) +
|
if return_list is True:
|
||||||
"/" +
|
return nfos
|
||||||
str(len(nfolist)) +
|
|
||||||
"] " +
|
|
||||||
str(nfopath) +
|
|
||||||
" added"))
|
|
||||||
with lock:
|
|
||||||
set_threaded_thumbnails(get_threaded_thumbnails() + nfos)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
# Update thumbnails list, threaded
|
|
||||||
def update_threaded_thumbnails(return_list=False):
|
|
||||||
global thumbnails_update_status
|
|
||||||
nfolist = get_nfofiles()
|
|
||||||
if len(nfolist) == 0:
|
|
||||||
nfolist = update_nfofiles(True)
|
|
||||||
nl1 = nfolist[:len(nfolist)//2]
|
|
||||||
nl2 = nfolist[len(nfolist)//2:]
|
|
||||||
|
|
||||||
lock = threading.Lock()
|
|
||||||
queue = Queue()
|
|
||||||
printer_thread = threading.Thread(
|
|
||||||
target=printer,
|
|
||||||
args=(queue,),
|
|
||||||
daemon=True,
|
|
||||||
name="Printer")
|
|
||||||
printer_thread.start()
|
|
||||||
|
|
||||||
t1 = threading.Thread(target=create_thumbnails, args=(nl1, lock, queue))
|
|
||||||
t2 = threading.Thread(target=create_thumbnails, args=(nl2, lock, queue))
|
|
||||||
|
|
||||||
start_time = time.time()
|
|
||||||
t1.start()
|
|
||||||
t2.start()
|
|
||||||
|
|
||||||
t1.join()
|
|
||||||
t2.join()
|
|
||||||
print("Threading done! duration:", (time.time() - start_time))
|
|
||||||
if return_list:
|
|
||||||
return get_threaded_thumbnails()
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@ -60,6 +60,7 @@ def gamelist(lang_code):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("error type:", type(e))
|
print("error type:", type(e))
|
||||||
|
|
||||||
if glist is not None:
|
if glist is not None:
|
||||||
return render_template('gamelist.html', gamelist=glist,
|
return render_template('gamelist.html', gamelist=glist,
|
||||||
**languages[lang_code], lang_code=lang_code, thumbnails=thumbnailslist)
|
**languages[lang_code], lang_code=lang_code, thumbnails=thumbnailslist)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user