diff --git a/.gitignore b/.gitignore index 9942040..a58d60b 100644 --- a/.gitignore +++ b/.gitignore @@ -140,4 +140,6 @@ main (2).py search_data.json 2.json image_gen.py -config.json \ No newline at end of file +config.json +test_frame.py +test.png \ No newline at end of file diff --git a/data/vid.png b/data/vid.png new file mode 100644 index 0000000..ce38b36 Binary files /dev/null and b/data/vid.png differ diff --git a/server.py b/server.py index 8d2166b..448e5b8 100644 --- a/server.py +++ b/server.py @@ -6,7 +6,7 @@ import json import io import mimetypes import os -import webbrowser +import cv2 ip_run = "127.0.0.23" port_run = 80 @@ -16,6 +16,30 @@ global root_folder root_folder = os.getcwd() + "\\" print(root_folder) +def get_frame(file_path): + vid = cv2.VideoCapture(file_path) + fps = vid.get(cv2.CAP_PROP_FPS) + total_frames = vid.get(cv2.CAP_PROP_FRAME_COUNT) + duration_seconds = float(total_frames) / float(fps) + secs = duration_seconds // 2 + fps = vid.get(cv2.CAP_PROP_FPS) + vid.set(cv2.CAP_PROP_POS_FRAMES, fps*secs) + ret, frame_res = vid.read() + color_coverted = cv2.cvtColor(frame_res, cv2.COLOR_BGR2RGB) + im = Image.fromarray(color_coverted) + datavid = Image.open("data/vid.png") + im.paste(datavid, (5, 5)) + if im.width >= im.height: + widtha = 250 + percent = widtha / im.width + heighta = round(im.height * percent) + else: + heighta = 250 + percent = heighta / im.height + widtha = round(im.width * percent) + im = im.resize((widtha, heighta)) + return im + @app.route("/") def index(): value = Markup('The HTML String') @@ -74,9 +98,11 @@ def hentai_search(types, tags): if contun == 2: if ".webm" in ii["file"] or ".mp4" in ii["file"] or ".avi" in ii["file"] or ".flv" in ii["file"]: typef = "v" + url_thumb = "/file/thumb/"+ii["file"]+".png" else: typef = "i" - res_post = {"tags":" ".join(ii["tags"]), "id":ii["id"], "type":typef, "rating":ii["rating"], "url_full":"/file/full/"+ii["file"], "url_thumb":"/file/thumb/"+ii["file"]} + url_thumb = "/file/thumb/"+ii["file"] + res_post = {"tags":" ".join(ii["tags"]), "id":ii["id"], "type":typef, "rating":ii["rating"], "url_full":"/file/full/"+ii["file"], "url_thumb":url_thumb} list_res.append(res_post) count += 1 json_resp = {"count":count,"list":list_res} @@ -100,16 +126,19 @@ def hentai_img(filetype, filename): return response if filetype == "thumb": ext = filename.split(".")[-1] - images = Image.open(root_folder+"data_img/"+filename) - if images.width >= images.height: - widtha = 250 - percent = widtha / images.width - heighta = round(images.height * percent) + if ".webm.png" in filename: + images = get_frame(root_folder+"data_img/"+(filename.replace(".webm.png", ".webm"))) else: - heighta = 250 - percent = heighta / images.height - widtha = round(images.width * percent) - images = images.resize((widtha, heighta)) + images = Image.open(root_folder+"data_img/"+filename) + if images.width >= images.height: + widtha = 250 + percent = widtha / images.width + heighta = round(images.height * percent) + else: + heighta = 250 + percent = heighta / images.height + widtha = round(images.width * percent) + images = images.resize((widtha, heighta)) io_data = io.BytesIO() if ext == "jpg": extf = "jpeg" diff --git a/static/js/my.js b/static/js/my.js index c119af1..1c89f65 100644 --- a/static/js/my.js +++ b/static/js/my.js @@ -39,7 +39,11 @@ function search(e){ imgc.innerHTML = ''; resp_res.forEach(function(item, i, resp_res) { var add_elem_a = document.createElement("button"); - add_elem_a.setAttribute("onclick", "see_full('"+item["url_full"]+"', '"+item["id"]+"', '"+item["type"]+"')"); + if (item["type"] == "i") { + add_elem_a.setAttribute("onclick", "see_full_img('"+item["url_full"]+"', '"+item["id"]+"', '"+item["type"]+"')"); + } else { + add_elem_a.setAttribute("onclick", "see_full_vid('"+item["url_full"]+"', '"+item["id"]+"', '"+item["type"]+"')"); + } add_elem_a.setAttribute("id", item["id"]); add_elem_a.setAttribute("class", "buttimg"); var add_elem_img = document.createElement("img"); @@ -52,15 +56,47 @@ function search(e){ }); } } -function see_full(url, id_button, type){ - var fulldata = document.getElementById("fullimg"); + +function see_full_vid(url, id_button, type){ + var fulldata = document.getElementById("fulldata"); if (fulldata != null){ fulldata.remove(); } var add_elem_br = document.createElement("br"); var add_elem_p = document.createElement("p"); add_elem_p.setAttribute("class", "fullimagep"); - add_elem_p.setAttribute("id", "fullimg"); + add_elem_p.setAttribute("id", "fulldata"); + var add_elem_a = document.createElement("a"); + add_elem_a.setAttribute("href", "#"+id_button); + var add_elem_button = document.createElement("button"); + add_elem_button.textContent = 'CLOSE'; + add_elem_button.setAttribute("class", "buttonclose"); + add_elem_button.setAttribute("onclick", "close_full()"); + var add_elem_ai = document.createElement("a"); + add_elem_ai.setAttribute("href", url); + add_elem_ai.setAttribute("target", "_blank"); + var add_elem_img = document.createElement("video"); + add_elem_img.setAttribute("src", url); + add_elem_img.setAttribute("class", "fullimage"); + add_elem_img.controls = true; + add_elem_ai.append(add_elem_img) + add_elem_p.appendChild(add_elem_button); + add_elem_p.appendChild(add_elem_br); + add_elem_p.appendChild(add_elem_ai); + var targetimg = document.getElementById(id_button); + targetimg.after(add_elem_p) + add_elem_a.click(); +} + +function see_full_img(url, id_button, type){ + var fulldata = document.getElementById("fulldata"); + if (fulldata != null){ + fulldata.remove(); + } + var add_elem_br = document.createElement("br"); + var add_elem_p = document.createElement("p"); + add_elem_p.setAttribute("class", "fullimagep"); + add_elem_p.setAttribute("id", "fulldata"); var add_elem_a = document.createElement("a"); add_elem_a.setAttribute("href", "#"+id_button); var add_elem_button = document.createElement("button"); @@ -82,7 +118,7 @@ function see_full(url, id_button, type){ add_elem_a.click(); } function close_full(){ - var fulldata = document.getElementById("fullimg"); + var fulldata = document.getElementById("fulldata"); fulldata.remove(); }