SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2009-08-06 13:40:04

sircrazy
#! Member
From: Florida
Registered: 2009-07-17
Posts: 85

Thunar + Uploader

The following is a custom action script for thunar which will allow you to upload files by right clicking on the file you want to upload.

This script will upload all file types that I have tested.

Requirements:
Ruby - sudo apt-get install ruby
Curl - sudo apt-get install curl (Should be installed by default on Crunchbang)
Zenity - sudo apt-get install zenity (I think this is installed by default on Crunchbang)
Thunar - Thunar is a file manager. I use it instead of PCmanFM. You can find out about it at http://thunar.xfce.org/index.html . To install: sudo apt-get install thunar

The following is the ruby script. Save the file as: .upload
Save it in your home directory: ~/

#!/usr/bin/env ruby
#
# Copyright 2007-2009 David Shakaryan <omp@gentoo.org>
# Copyright 2007-2009 Brenden Matthews <brenden@rty.ca>
#
# Distributed under the terms of the GNU General Public License v3
#

require 'tempfile'

argv = Array.new

quiet = false
url_only = false
help = false
skip = false
filename = 'pasta'

$stdin.fcntl(4, File::NONBLOCK)
stdin = $stdin.read if !$stdin.eof
unless stdin.nil?
    argv << ''
end

ARGV.each_index do |i|
    if skip
        skip = false
        next
    end
    if ARGV[i] =~ /-q|--quiet/
        quiet = true
    elsif ARGV[i] =~ /-u|--url/
        url_only = true
    elsif ARGV[i] =~ /-h|--help/
        help = true
    elsif ARGV[i] =~ /-f|--filename/
        filename = ARGV[i + 1]
        skip = true
    else
        argv << ARGV[i]
    end
end

nocurl = false
curl = %x{curl --version 2> /dev/null}
if curl.empty?
    nocurl = true
    $stderr.puts 'Error: curl missing or not in path.  Cannot continue.'
    $stderr.puts 
end

if (ARGV.size < 1 and (stdin.nil? or stdin.empty?)) or help or nocurl
    $stderr.puts 'Usage:  ompload [-h|--help] [options] [file(s)]'
    $stderr.puts '  -q, --quiet     Only output errors and warnings'
    $stderr.puts '  -u, --url       Only output URL when finished'
    $stderr.puts '  -f, --filename  Filename to use when posting data'
    $stderr.puts '                  from stdin'
    $stderr.puts 
    $stderr.puts '  You can supply a list of files or data via stdin (or both)'
    $stderr.puts 
    $stderr.puts '  This script requires a copy of cURL in the path.'
    Process.exit
end

errors = 0

wait = 5

Url = 'http://omploader.org/'
Max_size = 2**30

used_stdin = false
first = true

argv.each do |arg|

    if stdin.nil? and !used_stdin and !File.file?(arg)
        $stderr.puts "Invalid argument '#{arg}': file does not exist (or is not a regular file)."
        errors += 1
        next
    elsif File.size(arg) > Max_size
        $stderr.puts "Error omploading '#{arg}': file exceeds " + (Max_size).to_s + " bytes (size was " + File.size(arg).to_s + ")."
        errors += 1
        next
    end

    if !first
        # try not to hammer the server
        puts 'Sleeping for ' + wait.to_s + 's' if !quiet and !url_only
        sleep(wait)
    else
        first = false
    end

    tmp = Tempfile.new(filename)
    if !stdin.nil? and !used_stdin
        # upload from stdin
        puts "Progress for '#{arg}'" if !quiet and !url_only
        if quiet or url_only
            p = IO.popen("curl -s -F 'file1=@-;filename=\"#{filename}\"' #{Url}upload -o '#{tmp.path}'", "w+")
        else
            p = IO.popen("curl -# -F 'file1=@-;filename=\"#{filename}\"' #{Url}upload -o '#{tmp.path}'", "w+")
        end
        p.puts stdin
        p.close_write
        Process.wait
        used_stdin = true
    else
        # upload file
        puts "Progress for '#{arg}'" if !quiet and !url_only
        # escape quotes
        tmp_path = arg.gsub('"', '\"')
        if quiet or url_only
            %x{curl -s -F file1=@"#{tmp_path}" #{Url}upload -o '#{tmp.path}'}
        else
            %x{curl -# -F file1=@"#{tmp_path}" #{Url}upload -o '#{tmp.path}'}
        end
    end
    if !File.size?(tmp.path)
        $stderr.puts "Error omploading '#{arg}'"
        errors += 1
        next
    end
    output = IO.read(tmp.path)

    # parse for an ID
    if output =~ /View file: <a href="v([A-Za-z0-9+\/]+)">/
        id = $1
        puts "Omploaded '#{arg}' to #{Url}v#{id}" if !quiet
        %x{zenity --title 'Omploaded' --info --text '#{Url}v#{id}'} if !quiet
        wait = 5
    elsif output =~ /Slow down there, cowboy\./
        wait += 60
        argv << arg
        $stderr.puts "Got throttled when trying to ompload '#{arg}'"
        $stderr.puts "Increasing wait and attempting to continue..."
        errors += 1
    else
        $stderr.puts "Error omploading '#{arg}'"
        errors += 1
    end

end

if !quiet and !url_only
    if errors < 1
        puts "Success."
    else
        puts "Finished with #{errors} errors."
    end
end

Next, open a terminal and type: chmod +x ~/.upload

This will allow your file to be executed.

Now to create the Custom Action in thunar:

1.) Open: Thunar
2.) Goto: Edit >> Configure custom actions
3.) Click the + sign
4.) Name: Upload
5.) Description: can be left blank
6.) Command: terminator --command='ruby ~/.upload %f'
NOTE: I am using terminator, it is not required but it is default on Crunchbang. For other terminals you may need to figure out how to run a command in this fashion.
7.) Icon: Select Action Icons from the drop down list. Choose one of the Up Arrows
8.) Choose the Appearance Conditions tab.
9.) Be sure that file pattern is a * and that all the checkboxes are selected EXCEPT directories.
10.) Hit ok and close
11.) right click a file, even the script itself, and choose upload. It should return a screen like this when done correctly:
http://omploader.org/vMjN4Ng (it is left as a link as to not stretch the forum)
12.) Enjoy!

Special Thanks to slipshot for finding the original script, curtis for helping with the zenity, and Brenden Matthews and David Shakaryan for writing the original upload script, and omploader.org for being an awesome upload site.

NOTE: Right now you can only upload one file at a time, and if you upload too many files in too short of a time frame, it will throttle you.

Last edited by sircrazy (2009-09-29 13:16:34)


Sigs do it better

Offline

Be excellent to each other!

#2 2009-08-08 03:45:08

NWAdawg
Bob Da Dawg!
From: Arkansas US
Registered: 2008-11-27
Posts: 192
Website

Re: Thunar + Uploader

Great how to! sircrazy.


-Bob- 
Ubuntu User #24005, Linux User #480025
identi.ca  friendfeed  facebook

Offline

#3 2009-10-01 20:19:53

Zwopper
The GIMP Pimp
From: Deep in The Swedish Woods
Registered: 2008-11-28
Posts: 580
Website

Re: Thunar + Uploader

Works manually, but not as a Thunar action.. sad

Last edited by Zwopper (2009-10-01 21:16:40)


My artwork at deviantART   |    My Tweet   | My upcoming web page
Crea diem!
Lenovo ThinkPad E320 | 8GB | 512GB Samsung 840 PRO SSD | Xubuntu 13.04 & #! Waldorf

Offline

#4 2009-10-01 21:01:40

Zwopper
The GIMP Pimp
From: Deep in The Swedish Woods
Registered: 2008-11-28
Posts: 580
Website

Re: Thunar + Uploader

I changed the surrounding ' to " and it worked for me! smile

Last edited by Zwopper (2009-10-01 21:36:56)


My artwork at deviantART   |    My Tweet   | My upcoming web page
Crea diem!
Lenovo ThinkPad E320 | 8GB | 512GB Samsung 840 PRO SSD | Xubuntu 13.04 & #! Waldorf

Offline

#5 2009-12-03 05:05:05

Pi
#! Member
Registered: 2009-10-12
Posts: 73

Re: Thunar + Uploader

Thanks, this works great. big_smile


Toadsworth on #crunchbang

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo