Skip to content

Commit

Permalink
new integrated video player
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaaoBlues committed Jun 26, 2022
1 parent 7ed83a0 commit 9315a04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 9 additions & 3 deletions copypasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ def process(process_id):
copy(get_history_file_by_id(int(request.args.get("scan_id")))['content'])


if process_id == "[OPEN VIDEO]":

ret = f"<head><title>CopyPasta/Video</title><head><body>"+f"<link rel=\"icon\" href=\"/static/favicon.ico\" type=\"image/x-icon\"/>"+f"<video controls> <source src=\"/{request.args.get('file_path')}\"></video></body>"

return ret
else:
return abort(403)

Expand Down Expand Up @@ -526,6 +531,7 @@ def upload():

store_to_history({ "file_type" : f"{file_type}", "date" : f"{time}","text" : f"{file_content}"})


open_browser_if_settings_okay("http://127.0.0.1:21987/scan_preview")


Expand Down Expand Up @@ -631,9 +637,9 @@ def upload():
file.save(full_path)
store_to_history({"file_name" : f"{file.filename}","file_type" : f"{file_type}","date" : f"{time}","path" : f"{full_path}"})


open_browser_if_settings_okay(f"{COPYPASTA_URL}/image_preview?image_id={get_history_file_last_id()}")

if is_image(file_type):
open_browser_if_settings_okay(f"{COPYPASTA_URL}/image_preview?image_id={get_history_file_last_id()}")
return jsonify({"upload_status" : "true"})

else:
Expand Down
9 changes: 5 additions & 4 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ <h1>Last files/data sent :</h1>
//videos
}else if(videos_ext.includes(obj.file_type)){

var open_file_icon = "<button type=\"button\" class=\"btn btn-primary\" onclick=\"request_and_notify('Opening video...','/process/[OPEN FILE]?file_path="+obj.path+"')\"><i class=\"bi bi-file-earmark-arrow-up\"></i></button>";

tab_element = "<tr><td><div class=\"fs-1 mb-1\"><i class=\"bi bi-film\"></i></div></td><td><div style=\"margin-top:15px;\">title:"+obj.file_name+"</td></div><td><div style=\"margin-top:15px;\">"+open_folder_icon+"<br>"+open_file_icon+delete_file_icon+"</div></td></tr>";
var open_file_icon = "<button type=\"button\" class=\"btn btn-primary mx-1 my-1\" onclick=\"request_and_notify('Opening video...','/process/[OPEN FILE]?file_path="+obj.path+"')\"><i class=\"bi bi-file-earmark-arrow-up\"></i></button>";

var play_video_icon = "<button type=\"button\" class=\"btn btn-primary mx-1 my-1\" onclick=\"window.open('/process/[OPEN VIDEO]?file_path="+obj.path+"')\"><i class=\"bi bi-play\"></i></button>";
tab_element = "<tr><td><div class=\"fs-1 mb-1\"><i class=\"bi bi-film\"></i></div></td><td><div style=\"margin-top:15px;\">title:"+obj.file_name+"</td></div><td><div style=\"margin-top:15px;\">"+play_video_icon+open_file_icon+"<br>"+open_folder_icon+delete_file_icon+"</div></td></tr>";

//audio
}else if(audios_ext.includes(obj.file_type)){
Expand Down Expand Up @@ -265,7 +266,7 @@ <h1>Last files/data sent :</h1>

//random file
}else{
var open_file_icon = "<button type=\"button\" class=\"btn btn-primary\" onclick=\"request_and_notify('Opening file...','/process/[OPEN FILE]?file_path="+obj.path+"')\"><i class=\"bi bi-file-earmark-arrow-up\"></i></button> ";
var open_file_icon = "<button type=\"button\" class=\"btn btn-primary mx-1 my-1\" onclick=\"request_and_notify('Opening file...','/process/[OPEN FILE]?file_path="+obj.path+"')\"><i class=\"bi bi-file-earmark-arrow-up\"></i></button> ";

tab_element = "<tr><td>"+obj.date+"</td><td>"+obj.file_name+"</td><td>"+open_folder_icon+"<br>"+open_file_icon+delete_file_icon+"</td></tr>";
}
Expand Down
7 changes: 6 additions & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,9 @@ def remove_copypasta_port_redirect():
run("netsh interface portproxy add v4tov4 listenport=80 listenaddress=127.0.0.1 connectport=80 connectaddress=127.0.0.1")
except:
# feature that may crash sometimes, not essential
pass
pass


def is_image(file_type:str):

return file_type in ["jpeg","jpg","png","ico","gif","apng","avif","gif","jfif","pjpeg","pjp","svg","webp"]

0 comments on commit 9315a04

Please sign in to comment.