June 17th, 2017, 05:34 AM | #1 |
Senior Member
Join Date: Aug 2011
Posts: 333
Thanks: 1,098
Thanked 8,548 Times in 339 Posts
|
pixhost.org BASH upload script
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. 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') # WARNING: CHANGE below { to [ and } to ]...bbcode makes this a URL so it won't post right on forum. 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 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 |
|
June 17th, 2017, 08:55 AM | #2 | ||
in memoriam Max
Join Date: Jun 2009
Location: Germany
Posts: 3,586
Thanks: 122,072
Thanked 47,469 Times in 3,337 Posts
|
Quote:
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:
|
||
June 17th, 2017, 05:03 PM | #4 |
Vintage Member
Join Date: Apr 2011
Location: Tulsa
Posts: 23,168
Thanks: 611
Thanked 275,326 Times in 23,048 Posts
|
It appears that you're not making galleries..?
Just wondering. I was going to work on redoing my upload scripts after I had downloaded and sorted my images from imagebam. I had used PHP to do my previous upload script. I would just point it to a folder and it would upload each image in that folder ascending alphabetically. Script would take 2 arguements: name of gallery, folder path I was planning to retrofit some pieces into a new script to upload for pixhost that way you could note your gallery links and use them. Code:
<?php $ID=$argv[1]; $gal_ID=NULL; function gallery($gallery) { global $gal_ID; // required parameters for the OAuth-authentication // replace all parameters! $API_key = "ABCD1234"; $API_secret = "ABCD1234"; $on1=rand(10000000,99999999); $oauth_nonce = "$on1"; $oauth_token = "ABCD1234"; $oauth_token_secret = "ABCD1234"; $oauth_timestamp = time(); $oauth_signature_method = "MD5"; #$oauth_consumer_key = "1RSF4O2X"; // build the signature string $oauth_signature_string = ""; $oauth_signature_string .= $API_key; $oauth_signature_string .= $API_secret; $oauth_signature_string .= $oauth_timestamp; $oauth_signature_string .= $oauth_nonce; $oauth_signature_string .= $oauth_token; $oauth_signature_string .= $oauth_token_secret; // calculate the MD5-checksum of the signature string $oauth_signature = md5($oauth_signature_string); // populate an array with parameters $gal_vars = array( // parameters required by OAuth "oauth_consumer_key" => $API_key, "oauth_signature_method" => $oauth_signature_method, "oauth_signature" => $oauth_signature, "oauth_timestamp" => $oauth_timestamp, "oauth_nonce" => $oauth_nonce, "oauth_token" => $oauth_token, // optional parameters "response_format" => "JSON", "title" => "$gallery", ); // initialize curl and set parameters $gal_curl = curl_init(); curl_setopt($gal_curl, CURLOPT_URL, 'http://www.imagebam.com/sys/API/resource/create_gallery'); curl_setopt($gal_curl, CURLOPT_TIMEOUT, 30); curl_setopt($gal_curl, CURLOPT_POST, 1); curl_setopt($gal_curl, CURLOPT_POSTFIELDS, $gal_vars); curl_setopt($gal_curl, CURLOPT_RETURNTRANSFER, true); // execute, get information and close connection $gal_response = curl_exec($gal_curl); $info = curl_getinfo($gal_curl); curl_close ($gal_curl); // check if the http-code is 200 if($info['http_code'] != 200) { exit("OAuth error: ".$gal_response); } // decode the json-encoded response $gal_response_array = json_decode($gal_response, true); // print nicely print_r($gal_response_array); //grab new gallery ID $gal_ID=$gal_response_array["rsp"]["gallery"]["GID"]; } function upload($img) { global $ID; //global $gal_ID; // required parameters for the OAuth-authentication // replace all parameters! $API_key = "ABCD1234"; $API_secret = "ABCD1234"; $on1=rand(10000000,99999999); $oauth_nonce = "$on1"; $oauth_token = "ABCD1234"; $oauth_token_secret = "ABCD1234"; $oauth_timestamp = time(); $oauth_signature_method = "MD5"; // build the signature string $oauth_signature_string = ""; $oauth_signature_string .= $API_key; $oauth_signature_string .= $API_secret; $oauth_signature_string .= $oauth_timestamp; $oauth_signature_string .= $oauth_nonce; $oauth_signature_string .= $oauth_token; $oauth_signature_string .= $oauth_token_secret; // calculate the MD5-checksum of the signature string $oauth_signature = md5($oauth_signature_string); // populate an array with parameters $pvars = array( // parameters required by OAuth "oauth_consumer_key" => $API_key, "oauth_signature_method" => $oauth_signature_method, "oauth_signature" => $oauth_signature, "oauth_timestamp" => $oauth_timestamp, "oauth_nonce" => $oauth_nonce, "oauth_token" => $oauth_token, // optional parameters "content_type" => "adult", "thumb_size" => "180x180", "image" => "@$img", // ATTENTION - note the @ infront of the filename! "gallery_id" => "$ID" ); //print_r($pvars); // initialize curl and set parameters $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'http://www.imagebam.com/sys/API/resource/upload_image'); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // execute, get information and close connection $response = curl_exec($curl); $info = curl_getinfo($curl); curl_close ($curl); // decode the json-encoded response $response_array = json_decode($response); // print nicely print_r($response_array); print_r($info); } //gallery($argv[1]); $dir=$argv[2]; foreach(scandir("$dir") as $entry) { if ($entry != "." && $entry != ".." && $entry != "upload_folder.php") { upload("$dir$entry"); } } ?> Code:
{ "gallery_name": "Test gallery", "gallery_hash": "8NtKF", "gallery_url": "http:\/\/pixhost.to\/galleries\/8NtKF", "gallery_upload_hash": "yKtOl8NbHMYJ8yWj8Mh90sIlfXC7PXT6RHW8Xua7" } You get the response back from the API in json format, and using json_decode function in PHP you could get rid of all of the sed calls you make to pull out the image link. With php it would come back from the curl call as a reponse ($curl_response) Then just json decode and you would have an object you could call Code:
$resp=json_decode($response); $imglink=$resp->show_url;
__________________
My posts are scripted, sorry if the preview images aren't great, but the whole gallery is in the link
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. If I post any duplicates, please PM me and I will remove them Last edited by herkalurk; June 17th, 2017 at 05:11 PM.. |
June 17th, 2017, 10:01 PM | #5 |
Senior Member
Join Date: Aug 2011
Posts: 333
Thanks: 1,098
Thanked 8,548 Times in 339 Posts
|
Yeah, I didn't do galleries. Still not very good at PHP (or bash scripting for that matter). Thanks for sharing your method!
|
The Following 5 Users Say Thank You to sagjob For This Useful Post: |
June 17th, 2017, 10:43 PM | #6 | |
Vintage Member
Join Date: Apr 2011
Location: Tulsa
Posts: 23,168
Thanks: 611
Thanked 275,326 Times in 23,048 Posts
|
Quote:
Then I need to figure out my upload method, then figure out editing my posts with the new image links. One thing I will mention to others for the future is to use galleries, but to also use unique names if you can. The majority of my galleries are uniquely named, so my plan is to script a way to edit my posts and use the post title to find the gallery, then insert the new image links in place of the old. I have yet to do an index of the post ID and title of each of my posts as of yet, but I will. It will take a while since I have 13000 posts...
__________________
My posts are scripted, sorry if the preview images aren't great, but the whole gallery is in the link
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. If I post any duplicates, please PM me and I will remove them |
|
June 17th, 2017, 10:47 PM | #7 |
Vintage Member
Join Date: Apr 2011
Location: Tulsa
Posts: 23,168
Thanks: 611
Thanked 275,326 Times in 23,048 Posts
|
As for scripting experience you just have to do it. If it's a task that you would have to do at least 20 times, script it. I learned bash because of my first IT job (linux systems administrator), php cause I wanted to (helped that I worked for a web development shop too), and now I have to use javascript for my job with vmware products. The core is the same, it's how the functions are executed.
__________________
My posts are scripted, sorry if the preview images aren't great, but the whole gallery is in the link
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. If I post any duplicates, please PM me and I will remove them |
June 17th, 2017, 11:37 PM | #8 |
Senior Member
Join Date: Aug 2011
Posts: 333
Thanks: 1,098
Thanked 8,548 Times in 339 Posts
|
I learned bash scripting because I do a ton of file manipulation and lots of repetitive processes in OSX/Linux. Most of my stuff is quick and dirty—sort life stuff. Never been disciplined enough to get down and write beautiful code.
|
The Following 4 Users Say Thank You to sagjob For This Useful Post: |
June 22nd, 2017, 08:57 PM | #9 |
in memoriam Max
Join Date: Jun 2009
Location: Germany
Posts: 3,586
Thanks: 122,072
Thanked 47,469 Times in 3,337 Posts
|
pixhostuploader
I have just stumbled upon a pixhost uploader written in Python. Did not try it yet, but it might be a reasonable alternative to home-grown bash or php scripts.
EDIT: After a cursory look at the code I'm positive there is no gallery support whatsoever, which is bad. Last edited by retroanalyst; June 22nd, 2017 at 09:26 PM.. |
June 24th, 2017, 01:47 AM | #10 | |
Vintage Member
Join Date: Apr 2011
Location: Tulsa
Posts: 23,168
Thanks: 611
Thanked 275,326 Times in 23,048 Posts
|
Quote:
For me galleries are a huge part of my upload process. I have logic that determines if the number of total images is over 125 (post limit of thumbnails) then I should only select 4 image thumbnails and the gallery link instead. One thing that surprises me about pixhost is that the gallery ID is only 5 characters. It still provides 916132832 possible combinations with upper, lower, and number characters, so it's probably enough. Imagebam used 32 characters for their gallery hash.
__________________
My posts are scripted, sorry if the preview images aren't great, but the whole gallery is in the link
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. If I post any duplicates, please PM me and I will remove them |
|
The Following 4 Users Say Thank You to herkalurk For This Useful Post: |
|
|