Vintage Erotica Forums

Vintage Erotica Forums (http://vintage-erotica-forum.com/index.php)
-   Image Hosts (http://vintage-erotica-forum.com/forumdisplay.php?f=88)
-   -   pixhost.org BASH upload script (http://vintage-erotica-forum.com/showthread.php?t=333467)

sagjob June 17th, 2017 05:34 AM

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

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

retroanalyst June 17th, 2017 08:55 AM

Quote:

Originally Posted by sagjob (Post 4070400)
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.

sagjob June 17th, 2017 01:25 PM

Thanks. That's what I needed.

herkalurk June 17th, 2017 05:03 PM

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");
 }
}

?>

From pixhosts api docs - https://pixhost.to/api/index.html#galleries

Code:

{  "gallery_name": "Test gallery",  "gallery_hash": "8NtKF",  "gallery_url": "http:\/\/pixhost.to\/galleries\/8NtKF",  "gallery_upload_hash": "yKtOl8NbHMYJ8yWj8Mh90sIlfXC7PXT6RHW8Xua7" }
Another note, I chose to use PHP for these operations because it can natively turn json into objects.

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;


sagjob June 17th, 2017 10:01 PM

Yeah, I didn't do galleries. Still not very good at PHP (or bash scripting for that matter). Thanks for sharing your method!

herkalurk June 17th, 2017 10:43 PM

Quote:

Originally Posted by sagjob (Post 4071071)
Yeah, I didn't do galleries. Still not very good at PHP (or bash scripting for that matter). Thanks for sharing your method!

To be fair, that was for imagebam, I have yet to write anything for pixhost, still downloading everything I can. My next step is to verify I got as much and probably retry all of the downloads.

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...

herkalurk June 17th, 2017 10:47 PM

Quote:

Originally Posted by sagjob (Post 4071071)
Yeah, I didn't do galleries. Still not very good at PHP (or bash scripting for that matter). Thanks for sharing your method!

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.

sagjob June 17th, 2017 11:37 PM

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.

retroanalyst June 22nd, 2017 08:57 PM

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. :(

herkalurk June 24th, 2017 01:47 AM

Quote:

Originally Posted by retroanalyst (Post 4074979)
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. :(

I was always going to home grow mine though. I need to document the galleries and images into a easily query-able database. Already built the database structure, just need to make the script and start uploading images.

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.


All times are GMT. The time now is 03:53 PM.



vBulletin Optimisation provided by vB Optimise v2.6.1 (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.