]> git.plutz.net Git - serve0/blob - multitag.sh
Merge commit 'b931bbd0c30907b9cc956d3707b26b449bf41f76'
[serve0] / multitag.sh
1 #!/bin/sh
2
3 . "$_EXEC/db_meta.sh"
4 . "$_EXEC/cgilite/session.sh" nocookie
5 . "$_EXEC/widgets.sh"
6
7 # newtags=''  # tags selected in ui
8 # tags=''     # taglist from database
9 # detag=''    # temporary remove list
10 # extags=''   # exclusive tags, tags that preclude others within their categorie
11 # group=''    # id for grouping videos (videos in a group get a common group id)
12 # op=''       # operation: add | del | flip
13
14 newtags=''
15 for tn in $(seq 1 $(POST_COUNT tag)); do
16   newtags="$(POST tag $tn)${BR}${newtags}"
17 done
18 newtags="$(POST newtag |tr -d '\r' |tr , '\n')${BR}${newtags}"
19
20 if [ "$(POST makegroup)" = true ]; then
21   group="$(timeid)"
22 fi
23
24 # strip leading and trailing line breaks
25 while [ "${newtags#${BR}}" != "${newtags}" ]; do newtags="${newtags#${BR}}"; done
26 while [ "${newtags%${BR}}" != "${newtags}" ]; do newtags="${newtags%${BR}}"; done
27
28 op="$(POST op)"
29
30 for select in $(seq 1 $(POST_COUNT select)); do
31   file="$(POST select $select)"
32   read_meta "${file%.*}" || continue
33
34   tags="$(printf %s\\n "$META_TAGS" |tr , \\n)"
35
36   if [ "$op" = add ]; then
37     extags="$(printf '%s' "${newtags}" |grep -e "^-" |cut -d: -f1 )"
38     [ "$extags" ] && tags="$(printf %s\\n "$tags" |grep -vwFe "$extags")"
39     if printf %s "${newtags}" |grep -e "^-" |grep -qEe "^-[^:]+$"; then
40       tags="$(printf %s\\n "$tags" |grep -vEe '^-[^:]+$')"
41     fi
42     tags="${tags}${BR}${newtags}"
43
44   elif [ "$op" = del ]; then
45     detag="${newtags}${BR}"; while [ "$detag" ]; do
46       tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%${BR}*}")"
47       detag="${detag#*${BR}}"
48     done
49
50   elif [ "$op" = flip ]; then
51     fliptag="${newtags}${BR}"; while [ "$fliptag" ]; do
52       comp="$tags"
53       tags="$(printf '%s\n' "$tags" |grep -vxFe "${fliptag%%${BR}*}")"
54       [ "$comp" = "$tags" ] && tags="${tags}${BR}${fliptag%%${BR}*}"
55       fliptag="${fliptag#*${BR}}"
56     done
57
58   fi
59   tags="$(printf '%s\n' "$tags" |sort -u |tr '\n' ,)"
60   tags="${tags#,}"; tags="${tags%,}"
61
62   if [ "$group" ]; then
63     update_meta "$META_NAME" tags="${tags}" group="${group}"
64   else
65     update_meta "$META_NAME" tags="${tags}"
66   fi
67 done
68
69 ( if [ $(POST_COUNT select) -gt 0 ]; then
70     taglist >"$c_tags.$$"
71     mv -- "$c_tags.$$" "$c_tags"
72   fi &
73 ) &