Hi,
I wrote this simple module that works with API for upload to Keep2Share.
I wrote in few minutes and makes only basic work.
I've tested with single file and folder and it works.
I think that plowshare is an amazing upload tool for linux with a lot of hosting modules ready to use.
I wrote this simple module that works with API for upload to Keep2Share.
I wrote in few minutes and makes only basic work.
Code:
#!/bin/bash#
# keep2share.cc module
# Copyright (c) 2011-2012 Plowshare team
#
# This file is part of Plowshare.
#
# Plowshare is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Plowshare is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Plowshare. If not, see <http://www.gnu.org/licenses/>.
MODULE_KEEP2SHARE_REGEXP_URL="http://\(keep2share\|k2s\)\.cc/"
MODULE_KEEP2SHARE_DOWNLOAD_OPTIONS=""
MODULE_KEEP2SHARE_DOWNLOAD_RESUME=no
MODULE_KEEP2SHARE_DOWNLOAD_FINAL_LINK_NEEDS_COOKIE=no
MODULE_KEEP2SHARE_DOWNLOAD_SUCCESSIVE_INTERVAL=
MODULE_KEEP2SHARE_UPLOAD_OPTIONS="AUTH,a,auth,a=EMAIL:PASSWORD,User account"
MODULE_KEEP2SHARE_UPLOAD_REMOTE_SUPPORT=no
MODULE_KEEP2SHARE_LIST_OPTIONS=""
keep2share_upload() {
# local -r COOKIE_FILE=$1
local -r FILE=$2
local -r DEST_FILE=$3
local -r BASE_URL='http://keep2share.cc/api/v1/'
local -r MAX_SIZE=1073741823
local PAGE SERVER FILE_ID AUTH_DATA ACCOUNT FOLDER_ID
test "$AUTH" || return $ERR_LINK_NEED_PERMISSIONS
split_auth "$AUTH" USER PASSWORD || return
# Sanity checks
[ -n "$AUTH" ] || return $ERR_LINK_NEED_PERMISSIONS
if [ -n "$LINK_PASSWORD" ]; then
local -r PW_MAX=12
if [ -n "$PRIVATE_FILE" ]; then
log_error 'Private files cannot be password protected'
return $ERR_BAD_COMMAND_LINE
fi
# Check length limitation
if [ ${#LINK_PASSWORD} -gt $PW_MAX ]; then
log_error "Password must not be longer than $PW_MAX characters"
return $ERR_BAD_COMMAND_LINE
fi
fi
if [ -n "$ADMIN_CODE" ]; then
local -r AC_MAX=30
local -r AC_FORBIDDEN="/ '\"%#;&"
# Check length limitation
if [ ${#ADMIN_CODE} -gt $AC_MAX ]; then
log_error "Admin code must not be longer than $AC_MAX characters"
return $ERR_BAD_COMMAND_LINE
fi
# Check for forbidden characters
if match "[$AC_FORBIDDEN]" "$ADMIN_CODE"; then
log_error "Admin code must not contain any of these: $AC_FORBIDDEN"
return $ERR_BAD_COMMAND_LINE
fi
else
ADMIN_CODE=$(random a 8)
fi
PAGE=$(curl -d '{"username":"'$USER'","password":"'$PASSWORD'"}' "$BASE_URL"login ) || return
URL=$(parse_json 'auth_token' <<< "$PAGE") || return
log_debug "LOGIN: $PAGE"
FORMUPLOAD=$(curl -d '{"auth_token":"'$URL'"}' "$BASE_URL"GetUploadFormData ) || return
#Resp= rep:{"status":"success","code":200,"form_action":"http:\/\/und-06.keep2share.cc:8081\/upload\/index","file_field":"Filedata","form_data":{"nodeName":"prx-06","userId":"81432","expires":1390950710,"projectName":"k2s","hmac":"176b17c5debbcbbc08d5d716e8cf1ed47f5a9140","api_request":true}}
log_debug "FORM UPLOAD: $FORMUPLOAD"
# Check status
STATE=$(echo "$FORMUPLOAD" | parse_json 'status') || return
if [ "$STATE" != 'success' ]; then
log_error "Unexpected state: '$STATE'"
return $ERR_FATAL
fi
form_action=$(parse_json 'form_action' <<< "$FORMUPLOAD" ) || return
log_debug "FORM ACTION RESPONSE: $form_action"
file_field=$(parse_json 'file_field' <<< "$FORMUPLOAD" ) || return
log_debug "FILE FIELD RESPONSE: $file_field"
form_data=$(parse_json 'form_data' <<< "$FORMUPLOAD" ) || return
log_debug "FORM DATA RESPONSE: $form_data"
nodeName=$(parse_json 'nodeName' <<< "$form_data" ) || return
log_debug "NODE NAME RESPONSE: $nodeName"
userId=$(parse_json 'userId' <<< "$form_data" ) || return
log_debug "USERID RESPONSE: $userId"
hmac=$(parse_json 'hmac' <<< "$FORMUPLOAD" ) || return
log_debug "HMAC RESPONSE: $hmac"
expires=$(parse_json 'expires' <<< "$form_data" ) || return
log_debug "EXPIRES RESPONSE: $expires"
UPLOAD=$(curl_with_log -F "$file_field"="@$FILE" -F "hmac"="$hmac" -F "expires"="$expires" -F "userId"="$userId" -F "nodeName"="$nodeName" -F "api_request"="$URL" "$form_action") || return
log_debug "UPLOAD RESPONSE: $UPLOAD"
#Response: {"user_file_id":"52e7b3e29034c","status":"success","status_code":200}
status=$(parse_json 'status' <<< "$UPLOAD" ) || return
user_file_id=$(parse_json 'user_file_id' <<< "$UPLOAD" ) || return
# Check status
if [ "$status" != 'success' ]; then
log_error "Unexpected state: '$status'"
return $ERR_FATAL
fi
echo "http://k2s.cc/file/$user_file_id/$DEST_FILE"
}
I've tested with single file and folder and it works.
I think that plowshare is an amazing upload tool for linux with a lot of hosting modules ready to use.