Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: UTF-8 -*-
- # Modulos
- require 'rest_client'
- exit if Object.const_defined?(:Ocra)
- # Metodos
- def logo()
- print "
- @@
- @ @
- @ @ @@@ @@@ @ @
- @ @ @ @ @ @ @
- @ @ @@ @ @ @ @
- @ @@ @ @@@@ @ @@
- @ @ @ @ @ @ @ @
- @ @ @ @ @ @ @ @ @ @
- @@ @ @ @@@@ @@@ @ @
- By Elektro H@cker\n\n"
- end
- def help()
- print "\n Modo de empleo:\n\n"
- print " " + __FILE__.split('/').last + " [Opci\u00F3n] [Imagen]\n\n"
- print "\n Ejemplo:\n\n"
- print " " + __FILE__.split('/').last + " -d C:\\Test.jpg \n\n"
- print "\n Opciones: \n\n"
- print " -a --all \n Devuelve el enlace de la imagen en todos los formatos. \n\n"
- print " -b --bb \n Devuelve el enlace de la imagen en formato BB. \n\n"
- print " -d --directo \n Devuelve el enlace directo a la imagen. \n\n"
- print " -h --html \n Devuelve el enlace de la imagen en formato HTML. \n\n"
- print " -t --thumb \n Devuelve el thumb de la imagen. \n\n"
- print " -k --key \n Establece su Developer key. \n\n"
- print " /? Muestra esta ayuda. \n\n"
- Process.exit
- end
- def keycode(imput)
- if ARGV[1] == () or not imput.length.eql? 40
- puts "\n Porfavor introduzca una developer key válida..."
- puts "\n Ejemplo:\n\n " + __FILE__.split('/').last + " --key 148CAPSV9465b858a45dc1b4cdb32dee95ff6f59 \n\n"
- puts "\n Para más información, Visite: http://stream.imageshack.us/api/"
- Process.exit
- end # length
- if File.exist?("key")
- oldkey = File.read('key')
- print "\n ¿Desea reemplazar el archivo que contiene su developer key?\n\n"
- print " Clave anterior: " + oldkey
- print "\n Clave nueva : " + imput
- print "\n\n [SI/NO] \n\n>> "
- $sino = STDIN.gets
- if $sino[/si/i]
- keyfile = File.new("key", "w")
- keyfile.print(imput)
- print "\nClave reemplazada correctamente.\n"
- elsif $sino[/no/i]
- Process.exit
- elsif
- keycode(imput)
- end # Reemplazar
- else
- keyfile = File.new("key", "w")
- keyfile.print(imput)
- print "\nClave configurada correctamente.\n"
- end # File exist
- end
- def subir(file)
- print "\n Subiendo la imagen, Espere...\n\n"
- $Imagen = RestClient.post('http://www.imageshack.us/upload_api.php',
- :key => $devkey,
- # :a_username => "USUARIO",
- # :a_password => "PASSWORD",
- :fileupload => File.new(file)
- )
- end
- def show(opcion)
- if opcion == "-d" or opcion == "--directo"
- print $Imagen.split("<image_link>").last.split("</image_link>").first + "\n"
- elsif opcion == "-b" or opcion == "--bb"
- print $Imagen.split("<image_bb>").last.split("</image_bb>").first + "\n"
- elsif opcion == "-h" or opcion == "--html"
- print $Imagen.split("<image_html>").last.split("</image_html>").first.gsub(">", ">").gsub("<", "<").gsub(""", "'") + "\n"
- elsif opcion == "-t" or opcion == "--thumb"
- print $Imagen.split("<thumb_link>").last.split("</thumb_link>").first + "\n"
- elsif opcion == "-a" or opcion == "--all"
- print "\nDirecto: \n" + $Imagen.split("<image_link>").last.split("</image_link>").first + "\n\n"
- print "BB Forum: \n" + $Imagen.split("<image_bb>").last.split("</image_bb>").first + "\n\n"
- print "HTML: \n" + $Imagen.split("<image_html>").last.split("</image_html>").first.gsub(">", ">").gsub("<", "<").gsub(""", "'") + "\n\n"
- print "Thumb: \n" + $Imagen.split("<thumb_link>").last.split("</thumb_link>").first + "\n"
- end
- Process.exit
- end
- # Control de errores
- logo()
- if ARGV[0] == "-k" or ARGV[0] == "--key"
- keycode(ARGV[1])
- Process.exit
- end
- if not File.exist?("key")
- print "\n ERROR. Debe configurar su developer key para usar este programa...\n"
- puts "\n Ejemplo:\n\n " + __FILE__.split('/').last + " --key 148CAPSV9465b858a45dc1b4cdb32dee95ff6f59 \n\n"
- puts "\n Para más información, Visite: http://stream.imageshack.us/api/"
- Process.exit
- elsif
- $devkey = File.read('key')
- end
- if (ARGV.empty?) or ARGV[0] == "/?"
- help()
- end
- if (ARGV[1])==()
- print "\n ERROR. Debe introducir la ruta local de la imagen...\n"
- Process.exit
- end
- if not File.exist?(ARGV[1])
- print "\n ERROR. La imagen no existe...\n"
- Process.exit
- elsif not (ARGV[1].split('.').last)[/bmp\z/i] and not (ARGV[1].split('.').last)[/bmp\z/i] and not (ARGV[1].split('.').last)[/gif\z/i] and not (ARGV[1].split('.').last)[/ico\z/i] and not (ARGV[1].split('.').last)[/jpg\z/i] and not (ARGV[1].split('.').last)[/jpeg\z/i] and not (ARGV[1].split('.').last)[/png\z/i] and not (ARGV[1].split('.').last)[/tif\z/i] and not (ARGV[1].split('.').last)[/tiff\z/i]
- print "\n ERROR. Archivo de imagen no soportado...\n"
- print "\n Formatos soportados: .BMP, .GIF, .ICO, .JPG, .JPEG, .PNG, .TIF, .TIFF\n"
- Process.exit
- end
- if not ARGV[0] == "-d" and not ARGV[0] == "--directo" and not ARGV[0] == "-a" and not ARGV[0] == "--all" and not ARGV[0] == "-b" and not ARGV[0] == "--bb" and not ARGV[0] == "-h" and not ARGV[0] == "--html" and not ARGV[0] == "-t" and not ARGV[0] == "--thumb"
- print "\n ERROR. Opcion incorrecta...\n\n"
- print " Use la opcion [/?] para mostrar la ayuda. \n\n"
- print " " +__FILE__.split('/').last + " /? \n"
- Process.exit
- end
- # Proceso
- subir(ARGV[1])
- show(ARGV[0])
Add Comment
Please, Sign In to add comment