Skip to content

Instantly share code, notes, and snippets.

@Sardonyx001
Created July 13, 2024 20:49
Show Gist options
  • Save Sardonyx001/b630720a2e8a98fe7d813b29b48226f7 to your computer and use it in GitHub Desktop.
Save Sardonyx001/b630720a2e8a98fe7d813b29b48226f7 to your computer and use it in GitHub Desktop.
Fish shell function to download all pictures in a 4chan thread
function 4get -a THREADURL -a OUTPUTDIR --description 'Get all the pictures in a 4chan thread'
if string-empty $THREADURL
echo "Must provide a thread URL"
return
end
if string-empty $OUTPUTDIR
set OUTPUTDIR "."
end
mkdir -p $OUTPUTDIR
set threadId $(echo $THREADURL | sed 's/.*\///g')
set boardId $(echo $THREADURL | sed 's/.*org\///g' | sed 's/\/.*//g' )
gum log -t kitchen -sl info "Downloading from" thread $threadId
gum log -t kitchen -sl info "On " board $boardId
gum log -t kitchen -sl info "To " output_dir $OUTPUTDIR
curl -s "https://a.4cdn.org/$boardId/thread/$threadId.json" \
| jq "
.posts[]
| if .tim != null then
[.tim, .ext]
else empty
end
| map(tostring)
| \"https://i.4cdn.org/$boardId/\"+.[0]+.[1]" \
| xargs -n 1 wget -P $OUTPUTDIR --no-verbose
end
@Sardonyx001
Copy link
Author

Use responsibly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment