Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- image_dir="images"
- tags_index="tags_index.txt"
- output_dir="output"
- # pre-search for the first tag matches
- echo -e "Reading tags index"
- pv "$tags_index" | grep "$1" > /tmp/booru_search_tag_matches.txt
- # loop through the tags and discard non-matching ones
- for tag in "$@"
- do
- echo -e "looking for images matching $tag"
- grep -F "$tag" /tmp/booru_search_tag_matches.txt > /tmp/booru_search_tag_matches_tmp.txt
- mv /tmp/booru_search_tag_matches_tmp.txt /tmp/booru_search_tag_matches.txt
- done
- # clean up previous search results
- [ -d "$output_dir" ] && rm -r "$output_dir"
- mkdir -p "$output_dir"
- # link matching images to the output directory
- while read -r matching_entry ; do
- # form path for image
- dir=$image_dir${matching_entry:0:3}
- src_path=$dir$(echo $matching_entry | awk '{print $1}' )
- ln -v "$src_path" "$output_dir/"
- done < /tmp/booru_search_tag_matches.txt
- rm /tmp/booru_search_tag_matches.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement