]> Frank Brehm's Git Trees - my-stuff/tools.git/commitdiff
Nearly completing bin/convert-stack.sh
authorFrank Brehm <frank@brehm-online.com>
Sat, 18 Nov 2017 16:24:29 +0000 (17:24 +0100)
committerFrank Brehm <frank@brehm-online.com>
Sat, 18 Nov 2017 16:24:29 +0000 (17:24 +0100)
bin/convert-stack.sh

index 53597ee490e274af6d975434643efdf1c3074c61..e979037c6e86cd939190d092af256ed925cab3b7 100755 (executable)
@@ -11,7 +11,7 @@ DEBUG="n"
 QUIET='n'
 SIMULATE="n"
 
-VERSION="0.3"
+VERSION="0.4"
 
 # console colors:
 RED=""
@@ -132,7 +132,7 @@ get_options() {
     local base_dir=
 
     set +e
-    tmp=$( getopt -o R:P:G:F:sdvhV \
+    tmp=$( getopt -o R:L:P:G:F:sdvhV \
                     --long resolution:,linkdir:,perms:,group:,field-separator:,simulate,debug,verbose,nocolor,help,version \
                     -n "${BASENAME}" -- "$@" )
     if [[ $? != 0 ]] ; then
@@ -298,7 +298,26 @@ MKDIR() {
     if [[ "${VERBOSE}" == "y" ]] ; then
         cmd+=" --verbose"
     fi
-    eval ${cmd} "$@"
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        info "Executing: ${cmd}" "$@"
+    else
+        debug "Executing: ${cmd}" "$@"
+        eval ${cmd} "$@"
+    fi
+}
+
+#------------------------------------------------------------------------------
+RM() {
+    local cmd="rm"
+    if [[ "${VERBOSE}" == "y" ]] ; then
+        cmd+=" --verbose"
+    fi
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        info "Executing: ${cmd}" "$@"
+    else
+        debug "Executing: ${cmd}" "$@"
+        eval ${cmd} "$@"
+    fi
 }
 
 #------------------------------------------------------------------------------
@@ -307,7 +326,54 @@ LN() {
     if [[ "${VERBOSE}" == "y" ]] ; then
         cmd+=" --verbose"
     fi
-    eval ${cmd} "$@"
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        info "Executing: ${cmd}" "$@"
+    else
+        debug "Executing: ${cmd}" "$@"
+        eval ${cmd} "$@"
+    fi
+}
+
+#------------------------------------------------------------------------------
+CHOWN() {
+    local cmd="chown"
+    if [[ "${VERBOSE}" == "y" ]] ; then
+        cmd+=" --verbose"
+    fi
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        info "Executing: ${cmd}" "$@"
+    else
+        debug "Executing: ${cmd}" "$@"
+        eval ${cmd} "$@"
+    fi
+}
+
+#------------------------------------------------------------------------------
+CHGRP() {
+    local cmd="sudo chgrp"
+    if [[ "${VERBOSE}" == "y" ]] ; then
+        cmd+=" --verbose"
+    fi
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        info "Executing: ${cmd}" "$@"
+    else
+        debug "Executing: ${cmd}" "$@"
+        eval ${cmd} "$@"
+    fi
+}
+
+#------------------------------------------------------------------------------
+CHMOD() {
+    local cmd="chmod"
+    if [[ "${VERBOSE}" == "y" ]] ; then
+        cmd+=" --verbose"
+    fi
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        info "Executing: ${cmd}" "$@"
+    else
+        debug "Executing: ${cmd}" "$@"
+        eval ${cmd} "$@"
+    fi
 }
 
 ################################################################################
@@ -316,6 +382,51 @@ LN() {
 ##
 ################################################################################
 
+#------------------------------------------------------------------------------
+perform_movie() {
+
+    src="$1"
+    tgt="$2"
+    title="$3"
+
+    if [[ -f "${tgt}" ]] ; then
+        info "Conversion of '${src}' => '${tgt}' already done."
+        sleep 2
+        return 0
+    fi
+
+    info "Start converting '${src}' => '${tgt}' ..."
+    sleep 2
+
+    local verbose_opt=""
+    if [[ "${VERBOSE}" == "y" ]] ; then
+        verbose_opt="--verbose "
+    fi
+
+    RM -f divx2pass.log frameno.avi
+    echo
+    local cmd="${CONVERT_SCRIPT} ${verbose_opt}-y -S ${RESOLUTION} -T \"${title}\" \"${src}\" \"${tgt}\""
+    echo
+    sleep 2
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        info "Executing: ${cmd}"
+    else
+        debug "Executing: ${cmd}"
+        eval ${cmd} "$@"
+    fi
+    echo
+
+    if [[ -n "${LINK_DIR}" ]] ; then
+        LN "${tgt}" "${LINK_DIR}"
+        echo
+    fi
+
+    CHMOD "${PERMS}" "${tgt}"
+    CHGRP "${OWNING_GROUP}" "${tgt}"
+    sleep 3
+
+}
+
 #------------------------------------------------------------------------------
 perform_csv() {
 
@@ -342,6 +453,63 @@ perform_csv() {
         fi
         debug "Evaluating line ${lnr}: ${line}"
 
+        cd $( dirname "${CSV_FILE}" )
+        debug "Current base directory is now: '$( pwd )'."
+
+        directory=$( echo "${line}" | \
+                awk -F"${FIELD_SEPARATOR}" '{print $1}' | \
+                sed -e 's/^[   ]*//' -e 's/[   ]*$//' )
+        src=$( echo "${line}" | \
+                awk -F"${FIELD_SEPARATOR}" '{print $2}' | \
+                sed -e 's/^[   ]*//' -e 's/[   ]*$//'  | \
+                xargs basename )
+        tgt=$( echo "${line}" | \
+                awk -F"${FIELD_SEPARATOR}" '{print $3}' | \
+                sed -e 's/^[   ]*//' -e 's/[   ]*$//' | \
+                xargs basename )
+        title=$( echo "${line}" | \
+                awk -F"${FIELD_SEPARATOR}" '{print $4}' | \
+                sed -e 's/^[   ]*//' -e 's/[   ]*$//' )
+
+        if [[ -z "${directory}" ]] ; then
+            directory='.'
+        fi
+        debug "Checking working directory '${directory}' ..."
+        if [[ ! -d "${directory}" ]] ; then
+            error "Directory '${RED}${directory}${NORMAL}' not found."
+            continue
+        fi
+
+        cd "${directory}"
+        debug "Current working directory is now: '$( pwd )'."
+
+        debug "Checking source file ..."
+        if [[ -z "${src}" ]] ; then
+            error "No source file name found in line ${lnr}."
+            continue
+        fi
+
+        debug "Checking source file '${src}' ..."
+        if [[ ! -f "${src}" ]] ; then
+            error "Source file '${RED}${src}${NORMAL}' (line ${lnr}) not found."
+            continue
+        fi
+
+        debug "Checking target file ..."
+        if [[ -z "${tgt}" ]] ; then
+            error "No target file name found in line ${lnr}."
+            continue
+        fi
+
+        debug "Checking target file '${tgt}' ..."
+        if [[ "${src}" == "${tgt}" ]] ; then
+            error "Source and target file name '${tgt}' are identic in line ${lnr}."
+            continue
+        fi
+
+        echo
+        perform_movie "${src}" "${tgt}" "${title}"
+
     done
 
 }