]> git.plutz.net Git - rawnet/commitdiff
automatic meta data
authorPaul Hänsch <paul@plutz.net>
Thu, 30 Sep 2021 17:40:24 +0000 (19:40 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 30 Sep 2021 17:40:24 +0000 (19:40 +0200)
page_video.sh

index 1da7f0b743be198b8e58575dfe57ff1307741c9e..e1a2ae326116da12192dd7425af4abbb5ff180f3 100644 (file)
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+# ID   NAME    DESCRIPTION     RESX    RESY    LENGTH  COVER   STATUS (void|private|hidden|public)     UPLOADER        HITS    DESCR_CACHE     FUTUREUSE
+
 if [ "$video" -a -f "$vid_db" -a -r "$vid_db" ]; then
   read -r VIDEO_ID VIDEO_NAME VIDEO_DESCRIPTION VIDEO_RESX VIDEO_RESY \
           VIDEO_LENGTH VIDEO_COVER VIDEO_STATUS VIDEO_UPLOADER VIDEO_HITS \
@@ -16,33 +18,35 @@ if [ "$video" -a -f "$vid_db" -a -r "$vid_db" ]; then
   fi
 fi
 
-# Video
-# ID   NAME    DESCRIPTION     RESX    RESY    LENGTH  COVER   STATUS (void|private|hidden|public)     UPLOADER        HITS    DESCR_CACHE     FUTUREUSE
-
 update_video(){
   local id="${1}" name description resx resy length cover status uploader \
         hits descr_cache futureuse
   local ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS \
         DESCR_CACHE FUTUREUSE
-  local arg
+  local arg video
+  video="$_DATA/$CHANNEL_ID/$VIDEO_ID.mp4"
 
   for arg in "$@"; do case $arg in
     name=*) name="${arg#*=}";;
     description=*) description="${arg#*=}";;
-    resx=*) resx="${arg#*=}";;
-    resy=*) resy="${arg#*=}";;
-    length=*) length="${arg#*=}";;
     cover=*) cover="${arg#*=}";;
     status=*) status="${arg#*=}";;
     uploader=*) uploader="${arg#*=}";;
     hits=*) hits="${arg#*=}";;
   esac; done
 
+  if [ -f "$video" -a -r "$video" ]; then
+    arg="$(echo; ffprobe -show_entries stream=width,height,duration "$video" 2>&-)"
+    resx="${arg#*width=}"; resx="${resx%%${BR}*}"
+    resy="${arg#*height=}"; resy="${resy%%${BR}*}"
+    length="${arg#*duration=}"; length="${length%%${BR}*}"
+  fi
+
   if LOCK "$vid_db"; then
     while read -r ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS \
                   DESCR_CACHE FUTUREUSE; do
       if [ "$id" = "$ID" ]; then
-        printf '%s     %s      %s      %i      %i      %i      %s      %s      %s      %i      %s      %s\n' \
+        printf '%s     %s      %s      %i      %i      %f      %s      %s      %s      %i      %s      %s\n' \
                "$id" "$(STRING "${name-$(UNSTRING "$NAME")}")" \
                "$(STRING "${description-$(UNSTRING "$DESCRIPTION")}")" \
                "${resx:-${resx-${RESX}}${resx+0}}" \