summaryrefslogtreecommitdiff
path: root/pictures.py
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2022-08-24 02:12:49 +0200
committerpdp8 <pdp8@pdp8.info>2022-08-24 02:12:49 +0200
commitbfb3d38aba8649e4ad4e3ec3d23aa8152621d088 (patch)
tree29015bb2082902d4927df0eb7b000f0bc6cee45b /pictures.py
parente028591e8142827a878c4f94f561e73d2b888faf (diff)
image import, single music, video pages
Diffstat (limited to 'pictures.py')
-rwxr-xr-xpictures.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/pictures.py b/pictures.py
new file mode 100755
index 0000000..b9f3095
--- /dev/null
+++ b/pictures.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+
+import os
+import numpy as np
+import subprocess
+import json
+
+
+def descriptors(file):
+ npy = os.path.join(
+ os.path.dirname(file),
+ ".meta",
+ "descriptors",
+ os.path.basename(os.path.splitext(file)[0]) + ".npy", # TODO
+ )
+ return np.load(npy, allow_pickle=False)
+
+
+mail = "pdp8@pdp8.info"
+cmd = "grep '3$' /home/ch/img/art/.meta/ratings|cut -f1"
+favs = subprocess.check_output(cmd, shell=True, text=True).splitlines()
+distances = {}
+for fav in favs:
+ basename = os.path.basename(fav)
+ """
+ out = os.path.join("/home/ch/pub/pictures/", basename)
+ cmd = "convert '" + fav + "' -strip -resize 1024x '" + out + "'"
+ os.system(cmd)
+ cmd = (
+ "exiv2 -M'set Xmp.dc.creator "
+ + mail
+ + "' -M'set Xmp.dc.rights © "
+ + mail
+ + "' -M'set Xmp.dc.license http://creativecommons.org/licenses/by-sa/4.0/' -M'set Xmp.xmpRights.UsageTerms Creative Commons Attribution-ShareAlike 4.0 International License' -M'set Xmp.xmpRights.Marked True' -M'set Xmp.dc.description Original artwork available from "
+ + mail
+ + "' "
+ + out
+ )
+ os.system(cmd)
+ """
+ fav_d = descriptors(fav)
+ distances[basename] = {}
+ for img in favs:
+ if fav != img:
+ img_d = descriptors(img)
+ sim = np.dot(fav_d, img_d) / (np.linalg.norm(fav_d) * np.linalg.norm(img_d))
+ img_basename = os.path.basename(img)
+ distances[basename][img_basename] = np.float64(1.0 - sim)
+with open("/home/ch/pub/distances.js", "w") as f:
+ s = "distances = " + json.dumps(distances)
+ print(s, file=f)