I wrote a bash perl script to embed tags from e621 into image exif metadata. This enables you to search the images directly on your computer in windows explorer.
tag_e621.pl (v2 using Perl) (FAST)
A small perl script to embed tags from e621.net into image EXIF metadata.
Prerequisites:
1) Text::CSV_XS
2) Path::Class
3) File::Basename
4) Image::ExifTool
How to use:
1) Download images from e621.net to some directory, for example /home/uwubanana/e621_files/
2) Download a posts db dump from https://e621.net/db_export/
3) Update "posts_csv" and "file_path" variables to the db dump and your e621 images.
4) Make the script executable: chmod +x tag_e621.pl
5) Run the script: ./tag_e621.pl
Notes:
EXIF METADATA TAGS ONLY WORK ON .JPG FOR WINDOWS SEARCH!
PNG and GIF files will still be tagged but Windows search doesn't support metadata for these files.
1) This perl script is much faster than the old BASH version, on an NVMe drive I was tagging over 150 images per second.
2) Parsing the CSV file takes a couple minutes, don't worry if it hangs for a while.
3) You may already have all prerequisites installed, if you're missing one try installing via:
perl -MCPAN -e 'install Text::CSV_XS'
perl -MCPAN -e 'install Path::Class'
perl -MCPAN -e 'install File::Basename'
perl -MCPAN -e 'install Image::ExifTool'
tag_e621.pl
#!/usr/bin/perl # Add tags from e621.net to local image EXIF metadata. # # $post_csv = posts db dump from https://e621.net/db_export/ # $file_path = path containing images downloaded from e621.net # # Authors # [email protected] # kora [email protected] # # 2023-03-26 #### CHANGE THESE VARIABLES my $posts_csv = "posts-2023-03-24.csv"; my $file_path = "files/e621_popular/2007"; #### DO NOT CHANGE BELOW THIS LINE use Text::CSV_XS; use Path::Class; use File::Basename; use Image::ExifTool; print "Parsing " . $posts_csv . "...\n"; binmode STDOUT, ":utf8"; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 }); open my $fh, "<", "$posts_csv" or die "$posts_csv $!"; $junk = <$fh>; while (my $row = $csv->getline ($fh)) { $tags{@$row[3]} = @$row[8]; } close $fh or die "$posts_csv: $!"; print "Searching: " . $file_path . "...\n"; my @files; dir($file_path)->recurse(callback => sub { my $file = shift; if($file =~ /(\.jpg|\.png|\.gif)\z/) { push @files, $file->absolute->stringify; } }); print "Tagging files...\n"; for my $file (@files) { print "Tagging: " . $file . "\n"; my $base_file_name = basename($file); (my $file_md5 = $base_file_name) =~ s/\.[^.]+$//; (my $formatted_tags = $tags{$file_md5}) =~ s/\ /; /g; my $exifTool = Image::ExifTool->new; if($file =~ /\.(jpg|gif)\z/) { $exifTool->Options(IgnoreMinorErrors => '1', OverwriteOriginal => '1', FastScan => '5'); $exifTool->SetNewValue(Keywords => [$formatted_tags]); $exifTool->SetNewValue(Subject => [$formatted_tags]); } if($file =~ /\.png\z/) { $exifTool->Options(IgnoreMinorErrors => '1', OverwriteOriginal => '1', FastScan => '1'); $exifTool->SetNewValue(Keywords => [$formatted_tags]); $exifTool->SetNewValue(Subject => [$formatted_tags]); } $exifTool->WriteInfo($file); } print "Done!\n"
GitHub link: https://github.com/bananahand/tag_e621
Let me know what you think!
Updated