SEARCH

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

You are not logged in.

#1 2009-08-05 00:10:26

slipshot
#! CrunchBanger
Registered: 2009-05-13
Posts: 171

Iggykoopa! can you please!

I found this little script for uploading images to omploader and it returns the url.
The only thing is, that it is a command line tool. I dont mind using the command line but my girl friend thinks having to use it is equal to death it's self. I was wondering how hard it would be to make some kinda front end for it? Just some GUI to select the image and return the url would be fine. Im far from a coder and have no idea where to start on such a thing, but i thought i might ask you to see what you thought of the idea and how hard it would be.
I'm pretty sure the script calls on curl and ruby, if that helps anything.
I would be thankful if you could look at this for me.

#!/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 = '[url]http://omploader.org/[/url]'
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
        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

Offline

Help fund CrunchBang, donate to the project!

#2 2009-08-05 05:45:18

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,480

Re: Iggykoopa! can you please!

I'm a little rusty on my ruby(it's been about two years since I played with ruby on rails) but when I get out of work I can take a look at it.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#3 2009-08-05 10:43:11

slipshot
#! CrunchBanger
Registered: 2009-05-13
Posts: 171

Re: Iggykoopa! can you please!

ok cool iggykoopa, when ever you get the time will be fine. thankyou!:D

Offline

#4 2009-08-05 11:09:04

Awebb
The Singularity
Registered: 2009-07-23
Posts: 2,812

Re: Iggykoopa! can you please!

@slipshot: In the meantime, why don't you try to tinker a little bash script using zenity?


I'm so meta, even this acronym

Offline

#5 2009-08-05 12:07:15

slipshot
#! CrunchBanger
Registered: 2009-05-13
Posts: 171

Re: Iggykoopa! can you please!

Good idea Awebb! Though i have looked into zenity, and aint had much luck with it. Im trying to wrap my head around this programing thing but thus far aint had much luck. I guess i'll learn it in time.

Offline

#6 2009-08-05 14:39:55

rigosantana3
Banned
Registered: 2009-02-10
Posts: 312

Re: Iggykoopa! can you please!

Slipshot
If your using firefox you could just get this add-on:
https://addons.mozilla.org/en-US/firefox/addon/5638

Offline

#7 2009-08-05 18:20:46

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,480

Re: Iggykoopa! can you please!

here you go:

#!/bin/sh

chooseFile=$(zenity --file-selection)
curl -F file1=$chooseFile http://omploader.org/upload -o /tmp/omp.html
location=`grep -o -m 1 href=\"/v[a-zA-Z0-9]* /tmp/omp.html | grep -o v[a-zA-Z0-9]*`
zenity --info --text "file loaded to http://omploader.org/${location}"

it doesn't have any nice error checking or anything, so if it fails it will act weird. It should work for the basics though. Save it and chmod +x it, then map it to a shortcut key if you use it alot.

edit: I was working on a nice conversion to python with gtk and everything, but urllib wasn't cooperating so I got frustrated and just made this.....hope it still works for you.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#8 2009-08-06 00:54:40

slipshot
#! CrunchBanger
Registered: 2009-05-13
Posts: 171

Re: Iggykoopa! can you please!

thankyou iggy it works perfect! big_smile YOU THE MAN!
You should call it Crunch-upload

Last edited by slipshot (2009-08-06 01:01:00)

Offline

#9 2009-08-06 01:06:34

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

Re: Iggykoopa! can you please!

iggy, i like where you are going with this, however, it isnt attaching the $location at the end of the url in the dialog box for me. Any ideas.


Sigs do it better

Offline

#10 2009-08-06 01:12:46

slipshot
#! CrunchBanger
Registered: 2009-05-13
Posts: 171

Re: Iggykoopa! can you please!

Well i thought it did! the url it is returning just has the path to where the file im trying to upload is stored. hmmmmmm... interesting.....

Offline

#11 2009-08-06 02:28:49

rigosantana3
Banned
Registered: 2009-02-10
Posts: 312

Re: Iggykoopa! can you please!

And thats why iggy is called the script master..

Last edited by rigosantana3 (2009-08-06 02:29:22)

Offline

#12 2009-08-06 05:37:58

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,480

Re: Iggykoopa! can you please!

I can fix it when I get home... you want the shortcut for forums and stuff? or the thumbnail? Or is it already working right and I'm misunderstanding? sorry I hadn't used omploader before so I just tested it enough to make sure it was working, uploaded the same picture like 8 times getting it right lol.

sircrazy: is it just blank? do you have curl installed? like I said it doesn't have any error checking, trying running it from a terminal, that will give you the output from curl and tell you if something is going wrong.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#13 2009-08-06 12:12:05

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

Re: Iggykoopa! can you please!

alright iggy, let me try to explain it again. I have the tendency to be confusing in my explanations

First, I have the original ruby script, it works great in thunar, I am going to add a how-to in here.

The Problem with the original ruby script is that you cannot choose the file, which you have so graciously created a script that starts with a --file-selection in zenity. This makes it prime for use with a shortcut key and quick uploading any file you choose. +1!!!

The issue is that when the script shows the --info dialog, it is supposed to show: file loaded to http://www.omploader.org/${location} , where $location is the specific id for the upload. When I run the script it only shows: file loaded to http://www.omploader.org/ , the ${location}/specific id is absent from the dialog box.

In the case of slipshot, he IS able to get an id showing in his dialog box. He accomplished this with uploading a .jpg screenshot. His issue is that it does not upload correctly. Instead of uploading the actual file, it actually uploaded just the path. If you were to click the link generated by his upload, it shows a blank screen with his path to the screenshot he wanted to upload.

I hope this clears up what we were meaning with the script. Gratz for tackling this.


Sigs do it better

Offline

#14 2009-08-06 19:21:53

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,480

Re: Iggykoopa! can you please!

was this fixed for you? I noticed you made the thunar + uploader post so it looks like it's fixed for you. By the way much better job with what you did, I was just staying away from ruby because I'm not that familiar with it.

edit: it was really bugging me that I couldn't do this natively in python. Did some more research and it turns out urllib doesn't do multi-part form data, found a module that someone hacked it to work, so almost done with a python version big_smile ...probably wont be done for another day or two though


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#15 2009-08-06 20:03:33

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

Re: Iggykoopa! can you please!

well, the ruby one is what we started with. i modified it to work with selected file in thunar. I think what slipshot is more after is like your script where you choose a file first with --file-selection then it uploads, so thunar wont have to be open.


Sigs do it better

Offline

#16 2009-08-07 06:11:11

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,480

Re: Iggykoopa! can you please!

I was thinking about it last night and once I get the python version working totally I'll be able to have it work both ways. If it's passed a file from thunar it can just upload that, if not it can open a file selection dialog. Also I was thinking of having it check the file size like the ruby version, but if it's too big have it automatically turn up the compression on it and resize until it gets down small enough.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#17 2009-08-07 22:13:03

slipshot
#! CrunchBanger
Registered: 2009-05-13
Posts: 171

Re: Iggykoopa! can you please!

Sounds great Iggykoopa, take all the time you need. smile

Offline

#18 2009-08-10 21:04:29

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

Re: Iggykoopa! can you please!

Hey iggy, just checking on if this py script is still coming along. I should really learn py


Sigs do it better

Offline

#19 2009-08-11 05:57:20

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,480

Re: Iggykoopa! can you please!

Sorry I've been super busy lately, I should be able to get back on it tonight. Need to go clothes shopping for my daughter first though, you know a way to make kids stop growing? wink

edit: also python isn't too difficult to pick up in your spare time, theres some pretty decent beginner tutorials around if you wanna try it out. I still only consider myself a beginner though, there are a lot of the more advanced concepts that I haven't really bothered to wrap my head around yet. I'm still just a scripter at heart, not really a programmer wink


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#20 2009-08-11 16:37:36

slipshot
#! CrunchBanger
Registered: 2009-05-13
Posts: 171

Re: Iggykoopa! can you please!

Iggykoopa, I can understand about the cloths shopping. I have a daughter also and school just started back, so i know where your coming from.
And i have looked into python, thus far it looks like greek to my but im still trying.
Thank you and please take your time, there is no rush here.

Offline

#21 2009-08-11 20:25:47

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

Re: Iggykoopa! can you please!

I still want to see your py script if you want to still make it. But I have put together a quick solution for that ruby script.

Before we begin:
You must have the following installed:
Ruby
Curl - is installed by default on crunchbang main
Zenity - is installed by default on crunchbang main

First save the following modified ruby script in your ~/.scripts dir. Save it as "upload"
(You do have one right?)

#!/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

It looks the same but there are a couple added lines to make it compatible.

Next create a new file called "upload.sh"
This should be in the same directory as the "upload" ruby script.

Here is what should be in the "upload.sh" shell script file:

#!/bin/bash

chooseFile=$(zenity --file-selection)
~/.scripts/upload $chooseFile

Now open a terminal and type:
chmod +x ~/.scripts/upload
chmod +x ~/.scripts/upload.sh

Now all you have to do is set a shortcut key to run:
~/.scripts/upload.sh
And a file selection box will pop up.
Choose the file to upload and hit Ok, the file should upload and return a dialog box with the url to your upload.

REMINDER: If you also use my thunar mod for uploading, and you moved your file as directed in here (this is the same ruby file for thunar), update the custom action in thunar from:
terminator --command='ruby ~/.upload %f'
to
terminator --command='ruby ~/.scripts/upload %f'
for the command.


Sigs do it better

Offline

#22 2009-08-11 20:30:01

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,480

Re: Iggykoopa! can you please!

All done, here you go http://crunchbanglinux.org/pastebin/311 . If you launch it with no arguments it opens a gui, if you launch it cli with a path it returns everything on the command line. Also checks if the file is too big, but the limit for omploader is 1gb so you shouldn't have issues. Hope it works well for you, and let me know if there are any issues.

edit: just realized some people launch it from thunar actions, I forgot so returning stuff on the commandline may be bad, I'll fix it later...too late tonight


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#23 2009-08-11 20:48:40

slipshot
#! CrunchBanger
Registered: 2009-05-13
Posts: 171

Re: Iggykoopa! can you please!

Thanks Iggykoopa it works great! Your the best! Thank you! big_smile smile

Offline

#24 2009-08-11 20:52:58

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,480

Re: Iggykoopa! can you please!

ok heres an updated version http://crunchbanglinux.org/pastebin/313 . if your using a thunar action just change the line to something like this:
terminator --command='/path/to/omploader.py %f gui'


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

Be excellent to each other!

#25 2009-08-11 21:14:45

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

Re: Iggykoopa! can you please!

iggy, amazing, beats the pants off of my work around. good job.


Sigs do it better

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