mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-28 19:16:16 +00:00
remove unnecessary sass
clean up metadata parser (kinda)
This commit is contained in:
parent
3c09fb494b
commit
4c7bf9706f
9 changed files with 209 additions and 286 deletions
|
@ -22,7 +22,7 @@ from colorthief import ColorThief
|
|||
|
||||
from onlylegs.extensions import db
|
||||
from onlylegs.models import Post, GroupJunction
|
||||
from onlylegs.utils import metadata as mt
|
||||
from onlylegs.utils.metadata import yoink
|
||||
from onlylegs.utils.generate_image import generate_thumbnail
|
||||
|
||||
|
||||
|
@ -88,7 +88,7 @@ def upload():
|
|||
logging.info("Error saving file %s because of %s", img_path, err)
|
||||
return jsonify({"message": "Error saving file"}), 500
|
||||
|
||||
img_exif = mt.Metadata(img_path).yoink() # Get EXIF data
|
||||
img_exif = yoink(img_path) # Get EXIF data
|
||||
img_colors = ColorThief(img_path).get_palette(color_count=3) # Get color palette
|
||||
|
||||
# Save to database
|
||||
|
|
|
@ -106,6 +106,7 @@
|
|||
|
||||
background-color: RGB($primary)
|
||||
border-radius: $rad
|
||||
overflow: hidden
|
||||
|
||||
.banner-small
|
||||
height: 3.5rem
|
||||
|
|
|
@ -237,12 +237,11 @@ details
|
|||
|
||||
img
|
||||
position: absolute
|
||||
top: 0
|
||||
left: 0
|
||||
inset: 0
|
||||
width: 100%
|
||||
height: 100vh
|
||||
height: 100%
|
||||
background-color: RGB($fg-white)
|
||||
filter: blur(1rem) saturate(1.2)
|
||||
filter: blur(3rem) saturate(1.2) brightness(0.7)
|
||||
transform: scale(1.1)
|
||||
object-fit: cover
|
||||
object-position: center center
|
||||
|
|
|
@ -57,59 +57,23 @@ nav
|
|||
object-fit: cover
|
||||
border-radius: $rad-inner
|
||||
|
||||
.tool-tip
|
||||
padding: 0.4rem 0.7rem
|
||||
|
||||
display: block
|
||||
|
||||
position: absolute
|
||||
top: 50%
|
||||
left: 3rem
|
||||
transform: translateY(-50%)
|
||||
|
||||
font-size: 0.9rem
|
||||
font-weight: 500
|
||||
|
||||
background-color: RGB($bg-100)
|
||||
color: RGB($fg-white)
|
||||
opacity: 0
|
||||
border-radius: $rad-inner
|
||||
|
||||
transition: opacity 0.2s cubic-bezier(.76,0,.17,1), left 0.2s cubic-bezier(.76,0,.17,1)
|
||||
|
||||
pointer-events: none
|
||||
|
||||
> i
|
||||
display: block
|
||||
|
||||
position: absolute
|
||||
top: 50%
|
||||
left: -0.45rem
|
||||
transform: translateY(-50%)
|
||||
|
||||
font-size: 0.75rem
|
||||
|
||||
color: RGB($bg-100)
|
||||
|
||||
&:hover
|
||||
> i, .nav-pfp
|
||||
background: RGBA($fg-white, 0.1)
|
||||
|
||||
span
|
||||
opacity: 1
|
||||
left: 3.9rem
|
||||
|
||||
&.selected
|
||||
color: RGB($primary)
|
||||
|
||||
&::before
|
||||
content: ''
|
||||
display: block
|
||||
|
||||
position: absolute
|
||||
top: 3px
|
||||
left: 3px
|
||||
top: 0.5rem
|
||||
left: 0.2rem
|
||||
|
||||
width: 3px
|
||||
height: calc(100% - 6px)
|
||||
height: calc(100% - 1rem)
|
||||
|
||||
background-color: currentColor
|
||||
border-radius: $rad-inner
|
||||
|
|
|
@ -182,6 +182,9 @@
|
|||
background: rgba(var(--white), 0.6) !important;
|
||||
}
|
||||
|
||||
|
||||
.navigation-item.selected { color: {{ text_colour }} !important; }
|
||||
|
||||
.banner-header,
|
||||
.banner-info,
|
||||
.banner-subtitle {
|
||||
|
@ -196,11 +199,8 @@
|
|||
color: {{ text_colour }} !important;
|
||||
}
|
||||
|
||||
|
||||
@media (min-width: 800px) {
|
||||
.banner-filter {
|
||||
background: linear-gradient(90deg, rgb{{ images.0.colours.0 }}, rgba({{ images.0.colours.1.0 }}, {{ images.0.colours.1.1 }}, {{ images.0.colours.1.2 }}, 0.3)) !important;
|
||||
}
|
||||
.banner-filter {
|
||||
background: linear-gradient(90deg, rgb{{ images.0.colours.0 }}, rgba({{ images.0.colours.1.0 }}, {{ images.0.colours.1.1 }}, {{ images.0.colours.1.2 }}, 0.3)) !important;
|
||||
}
|
||||
@media (max-width: 800px) {
|
||||
.banner-filter {
|
||||
|
|
|
@ -170,18 +170,18 @@
|
|||
<details open>
|
||||
<summary>
|
||||
{% if tag == 'Photographer' %}
|
||||
<i class="ph ph-person"></i><h2>Photographer</h2>
|
||||
{% elif tag == 'Camera' %}
|
||||
<i class="ph ph-camera"></i><h2>Camera</h2>
|
||||
{% elif tag == 'Software' %}
|
||||
<i class="ph ph-desktop-tower"></i><h2>Software</h2>
|
||||
{% elif tag == 'File' %}
|
||||
<i class="ph ph-file-image"></i><h2>File</h2>
|
||||
{% else %}
|
||||
<i class="ph ph-file-image"></i><h2>{{ tag }}</h2>
|
||||
{% endif %}
|
||||
<span style="width: 100%"></span>
|
||||
<i class="ph ph-caret-down collapse-indicator"></i>
|
||||
<i class="ph ph-person"></i><h2>Photographer</h2>
|
||||
{% elif tag == 'Camera' %}
|
||||
<i class="ph ph-camera"></i><h2>Camera</h2>
|
||||
{% elif tag == 'Software' %}
|
||||
<i class="ph ph-desktop-tower"></i><h2>Software</h2>
|
||||
{% elif tag == 'File' %}
|
||||
<i class="ph ph-file-image"></i><h2>File</h2>
|
||||
{% else %}
|
||||
<i class="ph ph-file-image"></i><h2>{{ tag }}</h2>
|
||||
{% endif %}
|
||||
<span style="width: 100%"></span>
|
||||
<i class="ph ph-caret-down collapse-indicator"></i>
|
||||
</summary>
|
||||
<table>
|
||||
{% for subtag in image.exif[tag] %}
|
||||
|
@ -205,30 +205,3 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript">
|
||||
function getCookie(cname) {
|
||||
let name = cname + "=";
|
||||
let ca = document.cookie.split(';');
|
||||
for(let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) == ' ') {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(name) == 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/*
|
||||
if (getCookie("image-info")) {
|
||||
document.querySelector('.info-container').classList.add('collapsed');
|
||||
document.querySelector('.image-container').classList.add('collapsed');
|
||||
}
|
||||
*/
|
||||
*/
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -0,0 +1 @@
|
|||
# :3
|
|
@ -12,90 +12,74 @@ from .helpers import *
|
|||
from .mapping import *
|
||||
|
||||
|
||||
class Metadata:
|
||||
def yoink(file_path):
|
||||
"""
|
||||
Metadata parser
|
||||
Initialize the metadata parser
|
||||
"""
|
||||
if not os.path.isfile(file_path):
|
||||
return None
|
||||
|
||||
img_exif = {}
|
||||
file = Image.open(file_path)
|
||||
|
||||
img_exif["FileName"] = os.path.basename(file_path)
|
||||
img_exif["FileSize"] = os.path.getsize(file_path)
|
||||
img_exif["FileFormat"] = img_exif["FileName"].split(".")[-1]
|
||||
img_exif["FileWidth"], img_exif["FileHeight"] = file.size
|
||||
|
||||
def __init__(self, file_path):
|
||||
"""
|
||||
Initialize the metadata parser
|
||||
"""
|
||||
self.file_path = file_path
|
||||
img_exif = {}
|
||||
try:
|
||||
tags = file._getexif()
|
||||
for tag, value in TAGS.items():
|
||||
if tag in tags:
|
||||
img_exif[value] = tags[tag]
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
file.close()
|
||||
|
||||
return _format_data(img_exif)
|
||||
|
||||
try:
|
||||
file = Image.open(file_path)
|
||||
tags = file._getexif()
|
||||
img_exif = {}
|
||||
|
||||
for tag, value in TAGS.items():
|
||||
if tag in tags:
|
||||
img_exif[value] = tags[tag]
|
||||
def _format_data(encoded):
|
||||
"""
|
||||
Formats the data into a dictionary
|
||||
"""
|
||||
exif = {
|
||||
"Photographer": {},
|
||||
"Camera": {},
|
||||
"Software": {},
|
||||
"File": {},
|
||||
}
|
||||
|
||||
img_exif["FileName"] = os.path.basename(file_path)
|
||||
img_exif["FileSize"] = os.path.getsize(file_path)
|
||||
img_exif["FileFormat"] = img_exif["FileName"].split(".")[-1]
|
||||
img_exif["FileWidth"], img_exif["FileHeight"] = file.size
|
||||
# Thanks chatGPT xP
|
||||
# the helper function works, so not sure why it triggers pylint
|
||||
for key, value in encoded.items():
|
||||
for mapping_name, mapping_val in EXIF_MAPPING:
|
||||
if key in mapping_val:
|
||||
if len(mapping_val[key]) == 2:
|
||||
exif[mapping_name][mapping_val[key][0]] = {
|
||||
"raw": value,
|
||||
"formatted": (
|
||||
getattr(
|
||||
helpers, # pylint: disable=E0602
|
||||
mapping_val[key][1],
|
||||
)(value)
|
||||
),
|
||||
}
|
||||
else:
|
||||
exif[mapping_name][mapping_val[key][0]] = {
|
||||
"raw": value,
|
||||
}
|
||||
continue
|
||||
|
||||
file.close()
|
||||
except TypeError:
|
||||
img_exif["FileName"] = os.path.basename(file_path)
|
||||
img_exif["FileSize"] = os.path.getsize(file_path)
|
||||
img_exif["FileFormat"] = img_exif["FileName"].split(".")[-1]
|
||||
img_exif["FileWidth"], img_exif["FileHeight"] = file.size
|
||||
# Remove empty keys
|
||||
if not exif["Photographer"]:
|
||||
del exif["Photographer"]
|
||||
if not exif["Camera"]:
|
||||
del exif["Camera"]
|
||||
if not exif["Software"]:
|
||||
del exif["Software"]
|
||||
if not exif["File"]:
|
||||
del exif["File"]
|
||||
|
||||
self.encoded = img_exif
|
||||
|
||||
def yoink(self):
|
||||
"""
|
||||
Yoinks the metadata from the image
|
||||
"""
|
||||
if not os.path.isfile(self.file_path):
|
||||
return None
|
||||
return self.format_data(self.encoded)
|
||||
|
||||
@staticmethod
|
||||
def format_data(encoded_exif):
|
||||
"""
|
||||
Formats the data into a dictionary
|
||||
"""
|
||||
exif = {
|
||||
"Photographer": {},
|
||||
"Camera": {},
|
||||
"Software": {},
|
||||
"File": {},
|
||||
}
|
||||
|
||||
# Thanks chatGPT xP
|
||||
# the helper function works, so not sure why it triggers pylint
|
||||
for key, value in encoded_exif.items():
|
||||
for mapping_name, mapping_val in EXIF_MAPPING:
|
||||
if key in mapping_val:
|
||||
if len(mapping_val[key]) == 2:
|
||||
exif[mapping_name][mapping_val[key][0]] = {
|
||||
"raw": value,
|
||||
"formatted": (
|
||||
getattr(
|
||||
helpers, # pylint: disable=E0602
|
||||
mapping_val[key][1],
|
||||
)(value)
|
||||
),
|
||||
}
|
||||
else:
|
||||
exif[mapping_name][mapping_val[key][0]] = {
|
||||
"raw": value,
|
||||
}
|
||||
continue
|
||||
|
||||
# Remove empty keys
|
||||
if not exif["Photographer"]:
|
||||
del exif["Photographer"]
|
||||
if not exif["Camera"]:
|
||||
del exif["Camera"]
|
||||
if not exif["Software"]:
|
||||
del exif["Software"]
|
||||
if not exif["File"]:
|
||||
del exif["File"]
|
||||
|
||||
return exif
|
||||
return exif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue