Advertisement
Guest User

Untitled

a guest
Nov 5th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.96 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. image_dir="images"
  4. tags_index="tags_index.txt"
  5. output_dir="output"
  6.  
  7. # pre-search for the first tag matches
  8. echo -e "Reading tags index"
  9. pv "$tags_index" | grep "$1" > /tmp/booru_search_tag_matches.txt
  10.  
  11. # loop through the tags and discard non-matching ones
  12. for tag in "$@"
  13. do
  14.     echo -e "looking for images matching $tag"
  15.     grep -F "$tag" /tmp/booru_search_tag_matches.txt > /tmp/booru_search_tag_matches_tmp.txt
  16.     mv /tmp/booru_search_tag_matches_tmp.txt /tmp/booru_search_tag_matches.txt
  17. done
  18.  
  19. # clean up previous search results
  20. [ -d "$output_dir" ] && rm -r "$output_dir"
  21.  
  22. mkdir -p "$output_dir"
  23.  
  24. # link matching images to the output directory
  25. while read -r matching_entry ; do
  26.     # form path for image
  27.     dir=$image_dir${matching_entry:0:3}
  28.     src_path=$dir$(echo $matching_entry | awk '{print $1}' )
  29.  
  30.     ln -v "$src_path" "$output_dir/"
  31. done < /tmp/booru_search_tag_matches.txt
  32.  
  33. rm /tmp/booru_search_tag_matches.txt
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement