]> zdv2.bktei.com Git - BK-2020-03.git/blobdiff - user/bkfeh
update(user/htmlz_to_cbz.sh): Use jdupes to deduplicate images
[BK-2020-03.git] / user / bkfeh
index 911d51b9fbb974212420a7287531a283afd7bcd9..7620e259f1b9cf5c336dee8b7512da1f9e31d6a0 100755 (executable)
@@ -1,8 +1,8 @@
 #!/usr/bin/env bash
 # Desc: Wrapper for feh that accepts directory paths via posargs or stdin lines.
 #!/usr/bin/env bash
 # Desc: Wrapper for feh that accepts directory paths via posargs or stdin lines.
-# Version: 0.3.0
+# Version: 0.3.4
 # Ref/Attrib: [1] Tange, Ole. GNU Parallel with Bash Array. 2019-03-24. https://unix.stackexchange.com/a/508365/411854
 # Ref/Attrib: [1] Tange, Ole. GNU Parallel with Bash Array. 2019-03-24. https://unix.stackexchange.com/a/508365/411854
-# Depends: GNU Parallel, GNU Bash v5.1.16, feh 3.6.3, GNU Coreutils 8.32 (b2sum)
+# Depends: GNU Parallel, GNU Bash v5.1.16, feh 3.6.3, GNU Coreutils 9.4 (b2sum, cp)
 
 #===Declare local functions===
 yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
 
 #===Declare local functions===
 yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
@@ -157,7 +157,7 @@ check_depends() {
         displayMissing;
         die "FATAL:Missing apps.";
     fi;
         displayMissing;
         die "FATAL:Missing apps.";
     fi;
-    return 1;
+    return 0;
 }; # check dependencies
 checkInt() {
     # Desc: Checks if arg is integer
 }; # check dependencies
 checkInt() {
     # Desc: Checks if arg is integer
@@ -257,6 +257,7 @@ save_sample() {
     local list_paths
     sample_count="100"; # max number of images to put in sample dir
     sample_max_space="10000000"; # max bytes to put in sample dir
     local list_paths
     sample_count="100"; # max number of images to put in sample dir
     sample_max_space="10000000"; # max bytes to put in sample dir
+    n_fail_max="10"; # max failures to save sample file (e.g. due to space limits)
 
     # Load environment variables if set
     if [[ ! -v BKFEH_SAMPLE_DIR ]]; then return 0; fi; # return early if environment var not set.
 
     # Load environment variables if set
     if [[ ! -v BKFEH_SAMPLE_DIR ]]; then return 0; fi; # return early if environment var not set.
@@ -286,14 +287,16 @@ save_sample() {
         yell "STATUS:Saving random sample of size $sample_count to $BKFEH_SAMPLE_DIR...";
         list_paths_sample="$(echo "$list_paths" | bkshuf "$sample_count" | head -n"$sample_count")";
         n_samp=0; # init sample file counter
         yell "STATUS:Saving random sample of size $sample_count to $BKFEH_SAMPLE_DIR...";
         list_paths_sample="$(echo "$list_paths" | bkshuf "$sample_count" | head -n"$sample_count")";
         n_samp=0; # init sample file counter
+        n_fail=0; # init failure counter
         sample_log="$BKFEH_SAMPLE_DIR"/paths.txt;
         printf "%s,%s,%s\n" "n_samp" "file_hash" "file_path" >> "$sample_log";
         sample_log="$BKFEH_SAMPLE_DIR"/paths.txt;
         printf "%s,%s,%s\n" "n_samp" "file_hash" "file_path" >> "$sample_log";
-        while read -r line; do
+        while read -r line && [[ "$n_fail" -le "$n_fail_max" ]]; do
             if [[ -z "$line" ]]; then continue; fi;
             ### check size limit
             sample_act_space="$(du -bd1 "$BKFEH_SAMPLE_DIR" | cut -f1 )"; # actual used space
             cand_space="$(du -bd1 "$line" | cut -f1 )"; # size of candidate file to add
             sample_req_space="$((sample_act_space + cand_space))";
             if [[ -z "$line" ]]; then continue; fi;
             ### check size limit
             sample_act_space="$(du -bd1 "$BKFEH_SAMPLE_DIR" | cut -f1 )"; # actual used space
             cand_space="$(du -bd1 "$line" | cut -f1 )"; # size of candidate file to add
             sample_req_space="$((sample_act_space + cand_space))";
+            if [[ ! "$sample_req_space" -lt "$sample_max_space" ]]; then ((n_fail++)); continue; fi;
 
             ### Customize file names
             n_samp_w="$(printf "%s" "$sample_count" | wc -c)";
 
             ### Customize file names
             n_samp_w="$(printf "%s" "$sample_count" | wc -c)";
@@ -307,10 +310,10 @@ save_sample() {
             file_name="${file_name%.*}";
             file_shortname="${file_name:0:32}";
             file_name_new="$n_samp_dd"_"$file_hash".."$file_shortname"."$file_ext";
             file_name="${file_name%.*}";
             file_shortname="${file_name:0:32}";
             file_name_new="$n_samp_dd"_"$file_hash".."$file_shortname"."$file_ext";
-            file_path_new="$BKFEH_SAMPLE_DIR"/"$file_name_new"            
+            file_path_new="$BKFEH_SAMPLE_DIR"/"$file_name_new";
             if [[ "$sample_req_space" -lt "$sample_max_space" ]]; then
                 #### add file to sample dir
             if [[ "$sample_req_space" -lt "$sample_max_space" ]]; then
                 #### add file to sample dir
-                must cp -n "$file_path" "$file_path_new";
+                must cp --update=none "$file_path" "$file_path_new";
                 #### note path in sample dir log
                 printf "%s,%s,%s\n" "$n_samp_dd" "$file_hash" "$file_path" \
                        >> "$sample_log";
                 #### note path in sample dir log
                 printf "%s,%s,%s\n" "$n_samp_dd" "$file_hash" "$file_path" \
                        >> "$sample_log";
@@ -410,7 +413,7 @@ main() {
     yell "STATUS:Built file list in $SECONDS seconds.";
 
     # Run feh with filelist
     yell "STATUS:Built file list in $SECONDS seconds.";
 
     # Run feh with filelist
-    feh --full-screen --auto-zoom --draw-filename --filelist "$list_paths_images_tmp" && \
+    feh --full-screen --auto-zoom --draw-filename --filelist "$list_paths_images_tmp" -D 16 --stretch --scale-down && \
         must rm "$list_paths_images_tmp" &
 
     # Save sample to path in env. var. BKFEH_SAMPLE_DIR if set
         must rm "$list_paths_images_tmp" &
 
     # Save sample to path in env. var. BKFEH_SAMPLE_DIR if set