Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- image_dir="images"
- tags_dir="tags"
- output_dir="output"
- # pre-search for the first tag matches
- grep --include=*.txt -rFl "$1" "$tags_dir" > /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"
- while read -r tag_file ; do
- grep --include=*.txt -rFl "$tag" "$tag_file" >> /tmp/booru_search_tag_matches_tmp.txt
- done < /tmp/booru_search_tag_matches.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 tag_file ; do
- # form paths for image and tags
- img_filename="$(basename ${tag_file%_tags.txt})"
- img_src="$image_dir/$img_filename"
- img_dst="$output_dir/$img_filename"
- ln -v "$img_src" "$img_dst"
- done < /tmp/booru_search_tag_matches.txt
- rm /tmp/booru_search_tag_matches.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement