View Single Post
Old June 17th, 2017, 08:55 AM   #2
retroanalyst
in memoriam Max
 
retroanalyst's Avatar
 
Join Date: Jun 2009
Location: Germany
Posts: 3,586
Thanks: 121,983
Thanked 47,461 Times in 3,337 Posts
retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+
Default

Quote:
Originally Posted by sagjob View Post
If you are familiar with BASH scripts, thought I'd post this in case someone wanted to modify it for their needs.

READ THE WARNING IN THE SCRIPT COMMENTS OR YOU'LL SCREW THIS UP.
- BBCODE won't let me post it as-is.
Note that there is a noparse tag to disable the interpretation of BBcode. I have attempted this below.

Code:
#!/bin/bash

#Fix sequence for missing images (404 not found)
#Rename 0001, 0002, 0003...
#Delete this if you want to keep filenames
a=1
for i in *.[Jj][Pp][Gg]; do
  new=$(printf "%04d.jpg" "$a") #04 pad to length of 4
  mv -i -- "$i" "$new"
  let a=a+1
done

#Find all JPG files in current folder
files=($(find -E . -type f -regex "^.*jpg"))
#Clear the Forum URL txt file if it exists.
> post.txt
#Process each JPG Found
for item in ${files[*]}
do
  printf "   %s\n" $item | sed 's/\ \ \ .\///g'
  output=$(curl -X POST --include "https://api.pixhost.to/images"  -H 'Content-Type: multipart/form-data; charset=utf-8' -H 'Accept: application/json' -F "img=@$item" -F 'content_type=0' -F 'max_th_size=180')
  fullImage=$(echo $output | sed 's/^.*show_url//g' | sed 's/\":\"//g' | sed 's/\\//g' | sed 's/\".*//g')
  thumbImage=$(echo $output | sed 's/^.*show_url//g' | sed 's/\":\"//g' | sed 's/\\//g' | sed 's/^.*th_url//g' | sed 's/"}//g')
  echo -n "[url="$fullImage"][img]"$thumbImage"[/img][/url] " >> post.txt
done

#Put into OSX Clipboard
cat post.txt | sort | pbcopy

#Send OSX Notification
osascript -e 'display notification "Copied to Clipboard" with title "Upload Complete"'

#Delete all JPGs in folder to clear for next batch.
rm *.jpg
Quote:
I run this on OSX Sierra. It is messy, but functional for my needs. Some command may not be native to OSX. May require HomeBrew https://brew.sh/

Feel free to tweak and repost a better version that is more adaptable to all. Just sharing in case it helps someone get started on their own script.

If you don't know what you're doing—Don't. You've been warned.

Here it is in action.

https://www.youtube.com/watch?v=T4-anPkVvfg
Thanks. Except for the clipboard/notification commands, the script should also run on Linux and on other Unices.
retroanalyst is online now   Reply With Quote
The Following 8 Users Say Thank You to retroanalyst For This Useful Post: