# Global exports
META_LENGTH='' META_WIDTH='' META_HEIGHT='' META_TAGS=''
- META_COMMENT='' META_NAME='' META_GROUP=''
+ META_COMMENT='' META_NAME='' META_GROUP='' META_GROUPORDER=''
if [ $# -eq 0 ]; then
read -r META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT \
- META_NAME META_GROUP
+ META_NAME META_GROUP META_GROUPORDER
elif [ "$name" -a -f "$meta_db" -a -r "$meta_db" ]; then
read -r META_LENGTH META_WIDTH META_HEIGHT META_TAGS META_COMMENT \
- META_NAME META_GROUP <<-EOF
- $(grep -F " ${name}${CR}" "$meta_db")
+ META_NAME META_GROUP META_GROUPORDER <<-EOF
+ $(grep -F " ${name}${CR}" "$meta_db" |dbmeta_autogroup)
EOF
fi
if [ "$META_NAME" ]; then
pfx="$(STRING "${pfx#/}")"
[ "$pfx" = '\' ] && pfx='' || pfx="${pfx}/"
- while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP; do
+ dbmeta_autogroup "$meta" \
+ | while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME GROUP; do
printf '%i %i %i tags=%s comment=%s %s%s\r %s\n' \
$LENGTH $WIDTH $HEIGHT "${TAGS#tags=}" \
"${COMMENT#comment=}" "${pfx}" "${NAME%${CR}}" "${GROUP:-\\}"
- done <"$meta"
+ done
done
}
+
+dbmeta_autogroup(){
+ sed -E '
+ # perform auto grouping if group id is missing or empty
+ /\r$/bAUTOGROUP; s;\r \\$;\r;; tAUTOGROUP;
+
+ # skip auto grouping if manual group id is present
+ /\r .+$/b;
+
+ :AUTOGROUP
+ # save original dataset
+ h;
+
+ # strip all fields but the name
+ s;^[^\t]+ [^\t]+ [^\t]+ [^\t]+ [^\t]+ ;;
+ # strip common suffixes of web video sites
+ s;-([0-9a-zA-Z_-]{11}|ph[0-9a-f]{13}|[0-9]{6,})\r$;-\r;;
+
+ # replace all numeric parts and append numerals to an ordering field
+ # the group id will be made up of only the non-numeric character frame
+ # the ordering field will hold all numbers from the name
+ :X s;^([^\r0-9]*)([0-9]+)([^\r0-9]*)\r\t?([0-9]*)$;\1\r\3\r \4\2;; tX;
+
+ # append group id and ordering field to dataset
+ H; g; s;\n;\t;;
+ ' "$@"
+}