Bash Uploader For LuckyShare v1.30923

Status
Not open for further replies.

Peter South

Active Member
607
2013
360
1,680
Little script I wrote using LuckyShare's API that will upload all files in a directory into a LuckyShare Account and formats each files' download links into [BBCode]. This script also performs nicely with either of my two scripts for generating Video Contact Sheets and uploading the images to an ImgChili account:
Bash Script: Video Contact Sheet Generator & ImgChili Uploader | 3:4 Aspect Ratio
Bash Script: Video Contact Sheet Generator & ImgChili Uploader | 16:9 Aspect Ratio

Code:
#!/bin/bash
# Bash Uploader For LuckyShare v1.30923
# /usr/local/bin/luckyShareUploader.sh
# Dependencies: cURL - http://curl.haxx.se | Ubuntu 12.04LTS : apt-get install libcurl3
# Uploads all files in a directory to LuckyShare.net
####################################################################################################
#                                      CONFIGURATION SETTINGS                                      #
####################################################################################################
# Configure the following with your credentials between the ' ' marks.
userName='';
passWord='';
# Configure file size limitation in value of MBs, for premium accounts use: fileSizeLimit=4096;
fileSizeLimit=4096;
####################################################################################################
#                                              SCRIPT                                              #
####################################################################################################
echo "############################################"
echo "# Bash File Upload For LuckyShare v1.30923 #"
echo "# Written by SpecialEd @ irc.fileguide.org #"
echo "############################################"
####################################################################################################
fileSizeCheck=`find -size +4096M` >> .fileSizeCheck.swp;
if grep -Fxq "." .fileSizeCheck.swp;
  then
    echo "One or more files exceeds the limit of "$fileSizeLimit" MBs, exiting...";
    exit 0;
  else echo "All files in directory less than maximum file size of 4096MB, continuing...";
fi;
####################################################################################################
for file in ./*; do
  uploadTicket=`curl -s http://luckyshare.net/api/getuploadurl/user/$userName/pass/$passWord`;
  ls -lh $file | grep -v .txt | awk {'print $9'} | xargs -n1 -i curl -s -F "file=@./{}" \
  $uploadTicket >> .lsLinks.tmp;


  # Stops the script if an upload fails
  if grep -Fxq "Application Error: Failed to contact core server." ./.lsLinks.tmp;
    then
       echo "Upload of "$file" failed, trying again...";
       uploadTicket=`curl -s http://luckyshare.net/api/getuploadurl/user/$userName/pass/$passWord`;
       ls -lh $file | grep -v .txt | awk {'print $9'} | xargs -n1 -i curl -s -F "file=@./{}" \
       $uploadTicket >> .lsLinks.tmp;
       if grep -Fxq "Application Error: Failed to contact core server." ./.lsLinks.tmp;
         then
           echo "Upload of "$file" failed, moving to ./failedUploads/";
           mkdir failedUploads 2> /dev/null;
           mv $file ./failedUploads/;
         else
           echo "Upload of "$file" successful on second attempt.";
           break;
        fi;
    else
      echo "Completed upload for: "$file;
  fi;


  # Parses the .luckyShareLinks file and outputs [BBCode] formatted links to the terminal shell.
  cat .lsLinks.tmp | \
  sed 's/./&\ /33;s/./]/34;s/^/\[B\]LuckyShare\:\ \[\/B\]\[URL\=/;s/$/\[\/URL\]/;s/$/\n/' \
  >> LuckyShareLinks.txt; rm .lsLinks.tmp .fileSizeCheck.swp 2> /dev/null;
done;
####################################################################################################
cat LuckyShareLinks.txt;
#Counts the number of links generated and display with number of files in current directory.
numFiles=`ls ./* | grep -v luckyShareLinks | wc -l`;
numLinks=`cat ./LuckyShareLinks.txt | wc -l`;
echo "Number of files in this directory: "$numFiles;
echo "Total # LuckyShare URLs generated: "$numLinks;



For more of my scripts see: Index of various Bash Script Threads contributed by Eddie Johnson.
 
Last edited:
1 comment
Status
Not open for further replies.
Back
Top