PiToLoKo

Shack (Imageshack uploader)

Mar 19th, 2012
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.32 KB | None | 0 0
  1. # -*- coding: UTF-8 -*-
  2.  
  3.  
  4.  
  5. # Modulos
  6.  
  7. require 'rest_client'
  8. exit if Object.const_defined?(:Ocra)
  9.  
  10.  
  11.  
  12. # Metodos
  13.  
  14. def logo()
  15.   print "
  16.     @@
  17.    @   @                  
  18.   @    @      @@@   @@@  @   @
  19.    @   @         @ @   @ @  @
  20.     @  @ @@      @ @     @ @
  21.      @ @@  @  @@@@ @     @@
  22.      @ @   @ @   @ @     @ @
  23.  @  @  @   @ @   @ @   @ @  @
  24.   @@   @   @  @@@@  @@@  @   @
  25.  
  26.  
  27.                                By Elektro H@cker\n\n"
  28. end
  29.  
  30. def help()
  31.   print "\n Modo de empleo:\n\n"
  32.   print "  " + __FILE__.split('/').last + " [Opci\u00F3n] [Imagen]\n\n"
  33.   print "\n Ejemplo:\n\n"
  34.   print "  " + __FILE__.split('/').last + " -d C:\\Test.jpg \n\n"
  35.   print "\n Opciones: \n\n"
  36.   print "  -a --all \n       Devuelve el enlace de la imagen en todos los formatos. \n\n"
  37.   print "  -b --bb \n       Devuelve el enlace de la imagen en formato BB. \n\n"
  38.   print "  -d --directo \n       Devuelve el enlace directo a la imagen. \n\n"
  39.   print "  -h --html \n       Devuelve el enlace de la imagen en formato HTML. \n\n"
  40.   print "  -t --thumb \n       Devuelve el thumb de la imagen. \n\n"
  41.   print "  -k --key \n       Establece su Developer key. \n\n"  
  42.   print "  /?   Muestra esta ayuda. \n\n"
  43.   Process.exit
  44. end
  45.  
  46. def keycode(imput)
  47.  if ARGV[1] == () or not imput.length.eql? 40
  48.    puts "\n Porfavor introduzca una developer key válida..."
  49.    puts "\n Ejemplo:\n\n " + __FILE__.split('/').last + " --key 148CAPSV9465b858a45dc1b4cdb32dee95ff6f59 \n\n"
  50.    puts "\n Para más información, Visite: http://stream.imageshack.us/api/"
  51.    Process.exit
  52.   end # length
  53.  
  54.  if File.exist?("key")
  55.    oldkey = File.read('key')
  56.    print "\n ¿Desea reemplazar el archivo que contiene su developer key?\n\n"
  57.    print " Clave anterior: " + oldkey
  58.    print "\n Clave nueva   : " + imput
  59.    print  "\n\n [SI/NO] \n\n>> "
  60.    $sino = STDIN.gets
  61.     if $sino[/si/i]
  62.       keyfile = File.new("key", "w")
  63.       keyfile.print(imput)
  64.       print "\nClave reemplazada correctamente.\n"
  65.     elsif $sino[/no/i]
  66.       Process.exit
  67.     elsif
  68.       keycode(imput)
  69.     end # Reemplazar
  70.   else
  71.       keyfile = File.new("key", "w")
  72.       keyfile.print(imput)
  73.       print "\nClave configurada correctamente.\n"
  74.  end # File exist
  75. end
  76.  
  77. def subir(file)
  78.  print "\n Subiendo la imagen, Espere...\n\n"
  79.  $Imagen = RestClient.post('http://www.imageshack.us/upload_api.php',
  80.    :key => $devkey,
  81. #  :a_username => "USUARIO",
  82. #  :a_password => "PASSWORD",
  83.    :fileupload => File.new(file)
  84.  )
  85. end
  86.  
  87. def show(opcion)
  88.   if opcion == "-d" or opcion == "--directo"
  89.     print $Imagen.split("<image_link>").last.split("</image_link>").first + "\n"
  90.   elsif opcion == "-b" or opcion == "--bb"
  91.     print $Imagen.split("<image_bb>").last.split("</image_bb>").first + "\n"
  92.   elsif opcion == "-h" or opcion == "--html"
  93.     print $Imagen.split("<image_html>").last.split("</image_html>").first.gsub("&gt;", ">").gsub("&lt;", "<").gsub("&quot;", "'") + "\n"
  94.   elsif opcion == "-t" or opcion == "--thumb"
  95.     print $Imagen.split("<thumb_link>").last.split("</thumb_link>").first + "\n"
  96.   elsif opcion == "-a" or opcion == "--all"
  97.     print "\nDirecto: \n" + $Imagen.split("<image_link>").last.split("</image_link>").first + "\n\n"
  98.     print "BB Forum: \n" + $Imagen.split("<image_bb>").last.split("</image_bb>").first + "\n\n"
  99.     print "HTML: \n" + $Imagen.split("<image_html>").last.split("</image_html>").first.gsub("&gt;", ">").gsub("&lt;", "<").gsub("&quot;", "'") + "\n\n"
  100.     print "Thumb: \n" + $Imagen.split("<thumb_link>").last.split("</thumb_link>").first + "\n"
  101.   end
  102.  Process.exit
  103. end
  104.  
  105.  
  106.  
  107. # Control de errores
  108.  
  109. logo()
  110.  
  111. if ARGV[0] == "-k" or ARGV[0] == "--key"
  112.   keycode(ARGV[1])
  113.   Process.exit
  114. end
  115.  
  116. if not File.exist?("key")
  117.   print "\n ERROR.   Debe configurar su developer key para usar este programa...\n"
  118.   puts "\n Ejemplo:\n\n " + __FILE__.split('/').last + " --key 148CAPSV9465b858a45dc1b4cdb32dee95ff6f59 \n\n"
  119.   puts "\n Para más información, Visite: http://stream.imageshack.us/api/"
  120.   Process.exit
  121. elsif
  122.   $devkey = File.read('key')
  123. end
  124.  
  125. if (ARGV.empty?) or ARGV[0] == "/?"
  126.   help()
  127. end
  128.  
  129. if (ARGV[1])==()
  130.   print "\n ERROR.   Debe introducir la ruta local de la imagen...\n"
  131.   Process.exit
  132. end
  133.  
  134. if not File.exist?(ARGV[1])
  135.   print "\n ERROR.   La imagen no existe...\n"
  136.   Process.exit
  137. 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]
  138.     print "\n ERROR.   Archivo de imagen no soportado...\n"
  139.     print "\n Formatos soportados: .BMP, .GIF, .ICO, .JPG, .JPEG, .PNG, .TIF, .TIFF\n"
  140.   Process.exit
  141. end
  142.  
  143. 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"
  144.   print "\n ERROR.   Opcion incorrecta...\n\n"
  145.   print " Use la opcion [/?] para mostrar la ayuda. \n\n"
  146.   print " " +__FILE__.split('/').last +  " /?  \n"
  147.   Process.exit
  148. end
  149.  
  150.  
  151.  
  152. # Proceso
  153.  
  154. subir(ARGV[1])
  155. show(ARGV[0])
Add Comment
Please, Sign In to add comment