Last active
March 20, 2025 12:46
-
-
Save cmj/5d0cd4335f5300ff6c2b1a04caf0dd20 to your computer and use it in GitHub Desktop.
Get timestamp from a 'twimg' (Twitter image) url
This file contains hidden or 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
#!/bin/bash | |
# Get timestamp from a 'twimg' (Twitter image) url and return search options to find originating tweet. | |
# Image is given a snowflake id before the actual tweet; add ~2 seconds to until_time search operator. | |
# ./twimg2date.sh https://pbs.twimg.com/media/GmeLAsLbYAAPGpk.jpg | |
# | |
# https://danbooru.donmai.us/forum_topics/29446#forum_post_320975 | |
input=$(sed -E 's|.*/||;s/.*%2F//' <<< "${1}" | head -c15) | |
twimg=$(base64 -d <<< "${input}" 2>/dev/null | od -An -tx1 | sed -E 's/ //g;s/.{6}$//') | |
id=$(bc <<< "ibase=16; ${twimg^^}") | |
d=$((($id>>22)+1288834974657)) | |
date -d @${d:: -3} '+%F %T %s' | | |
while read date time epoch; do | |
echo "Image post date: $date $time" | |
echo "Find original tweet using these search options:" | |
echo "since_time:$epoch until_time:$(($epoch+2)) filter:twimg" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment