Last active
November 6, 2022 09:39
-
-
Save bxb100/4cdfa1b52999ac491b21fd9e1803f58a to your computer and use it in GitHub Desktop.
DropOver 脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' | |
for var in "$@" | |
do | |
files="encoded_image=@$var" | |
# if this is a gif, get the first frame | |
if [[ $var =~ \.(gif|mp4)$ ]]; then | |
tempfile="$TMPDIR$(uuidgen).jpg"; | |
./opt/homebrew/bin/ffmpeg -i "$var" -vf "select=eq(n\,0)" -q:v 3 "$tempfile"; | |
files="encoded_image=@$tempfile"; | |
fi | |
echo "$files" | |
tt=$( curl -X POST "https://www.google.com/searchbyimage/upload" \ | |
--form "$files" | grep -oE 'https?:\/\/.*\"' | tr -d '"' ) | |
if [[ $tt =~ $regex ]]; then | |
open "$tt" | |
break | |
else | |
echo "URL not found, tt: $tt" 1>&2 | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
attention: using homebrew install the ffmpeg, so the execute full path is
./opt/homebrew/bin/ffmpeg