summaryrefslogtreecommitdiff
path: root/art
blob: 5559f0ee93c9de73c3712802bac6a2f5564ff04a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
#
# a simple art reference manager, using IPTC tags.
#
# requires libiptcdata and feh
#
# requirements:
#  - list/edit iptc keywords for one or more files
#  - query iptc keywords for dir, list machine files
#
# FFS IPTC ONLY RETURNS A SINGLE KEYWORD, NOT ALL KEYWORDS FOR A FILE

import argparse
import os
from os.path import isfile, join
import subprocess

def sh(*args):
    proc = subprocess.Popen (args, stdout=subprocess.PIPE)
    stdout, _ = proc.communicate()
    txt = stdout.decode()
    return txt

def get_tags(filename):
    tags = sh("iptc", "--print=Keywords", filename)
    return tags.splitlines()

def images_with_tags():
    return os.listdir(".")

if __name__ == '__main__':
    for image in images_with_tags():
        tags = get_tags(image)
        print(image)
        for tag in tags:
            print(f"- {tag}")
        print("")

"""
old impl:

(use-modules (ice-9 popen)
             (ice-9 ftw)
             (ice-9 rdelim))

(define (get-tags-for-image filename)
  (let* ((port (open-input-pipe (string-append "iptc --print=Keywords " filename)))
         (tags (string-split (read-string port) #\newline))
         (x    (close-input-port port)))
    tags))

(define (member? x coll)
  (cond
   ((null? coll) #f)

   ((not (list? coll)) (equal? x coll))

   (else (or (member? x (car coll))
             (member? x (cdr coll))))))

;; returns an assoc list of (filename . '(tags))
(define (images-with-tags)
  (map (lambda (filename) (list filename (get-tags-for-image filename)))
       (filter (lambda (n) (not (member? n '("." ".."))))
               (scandir "."))))

(define (main args)
  (let ((cmd (cadr args)))
    (cond
     ((equal? cmd "tags")
      (display "show all tags"))

     ((equal? cmd "view")
      (begin
        (display "view all images with some tag or tags: ")
        (let* ((tags (cddr args))
               (s (images-with-tags)))
          ;; (define imgs (get-images-for-tag tag))
          ;; (system)
          (display s)))
      )

     ((equal? cmd "edit")
      (display "change tags on an image"))

     ((null? cmd)
      (begin
        (display "?: ")
        (display (cdr args))
        (newline))))))
"""