]> git.plutz.net Git - rawnet/blob - db_channel.sh
upload function to external file, ui change: put video upload before meta edit
[rawnet] / db_channel.sh
1 #!/bin/sh
2
3 [ "$include_dbchannel" ] && return 0
4 include_dbchannel="$0"
5
6 # == FILE FORMAT ==
7 # ID    NAME    DESCRIPTION     LOGO    THEME   AUTHORS DESCR_CACHE FUTUREUSE
8
9 # == GLOBALS ==
10 unset CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO CHANNEL_THEME \
11       CHANNEL_AUTHORS CHANNEL_DESCR_CACHE CHANNEL_FUTUREUSE
12
13 chan_db="$_DATA/channels.db"
14
15 read_channel() {
16   local channel="$1"
17
18   # Global exports
19   CHANNEL_ID='' CHANNEL_NAME='' CHANNEL_DESCRIPTION='' CHANNEL_LOGO=''
20   CHANNEL_THEME='' CHANNEL_AUTHORS='' CHANNEL_DESCR_CACHE=''
21   CHANNEL_FUTUREUSE=''
22
23   if [ $# -eq 0 ]; then
24     read -r CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \
25             CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE \
26             CHANNEL_FUTUREUSE
27   elif [ "$channel" -a -f "$chan_db" -a -r "$chan_db" ]; then
28     read -r CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \
29             CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE \
30             CHANNEL_FUTUREUSE <<-EOF
31         $(grep "^${channel}     " "${chan_db}")
32         EOF
33   fi
34   if [ "$CHANNEL_ID" ]; then
35            CHANNEL_NAME="$(UNSTRING "${CHANNEL_NAME}")"
36     CHANNEL_DESCRIPTION="$(UNSTRING "$CHANNEL_DESCRIPTION")"
37         CHANNEL_AUTHORS="$(UNSTRING "$CHANNEL_AUTHORS")"
38     CHANNEL_DESCR_CACHE="$(UNSTRING "$CHANNEL_DESCR_CACHE")"
39   else
40     unset CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \
41           CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE \
42           CHANNEL_FUTUREUSE
43     return 1
44   fi
45 }
46
47 update_channel(){
48   local id="${1}" name description logo theme authors descr_cache futureuse
49   local ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE
50   local arg
51
52   for arg in "$@"; do case $arg in
53     name=*) name="${arg#*=}";;
54     description=*) description="${arg#*=}";;
55     logo=*) logo="${arg#*=}";;
56     theme=*) theme="${arg#*=}";;
57     authors=*) authors="${arg#*=}";;
58   esac; done
59
60   if LOCK "$chan_db"; then
61     while read -r ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE; do
62       if [ "$id" = "$ID" ]; then
63         printf '%s      %s      %s      %s      %s      %s      %s      %s\n' \
64                "$id" "$(STRING "${name-$(UNSTRING "$NAME")}")" \
65                "$(STRING "${description-$(UNSTRING "$DESCRIPTION")}")" \
66                "${logo:-${logo-${LOGO}}${logo+\\}}" \
67                "${theme:-${theme-${THEME}}${theme+\\}}" \
68                "$(STRING "${authors-$(UNSTRING "${AUTHORS}")}")" \
69                "$(printf %s "${description-$(UNSTRING "$DESCRIPTION")}" |markdown |STRING)" \
70                "${FUTUREUSE:-\\}"
71       else
72         printf '%s      %s      %s      %s      %s      %s      %s      %s\n' \
73                "$ID" "$NAME" "$DESCRIPTION" "$LOGO" "$THEME" "$AUTHORS" \
74                "$DESCR_CACHE" "$FUTUREUSE"
75       fi
76     done <"$chan_db" >"${chan_db}.$$"
77     mv -- "${chan_db}.$$" "${chan_db}"
78     RELEASE "$chan_db"
79   else
80     return 1
81   fi
82 }
83
84 new_channel(){
85   local channel="${1:-$(randomid)}"
86
87   if LOCK "$chan_db"; then
88     if grep -q "^${channel}     " "$chan_db"; then
89       RELEASE "$chan_db"
90       return 1
91     fi
92     printf '%s  \\      \\      \\      \\      %s      \\      \\\n' \
93            "$channel" "$(STRING "$USER_ID")" >>"$chan_db"
94     RELEASE "$chan_db"
95   else
96     return 1
97   fi
98 }