🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #48

JAVA. azureus plugin buscatorrents en español casi acabao kien me ayuda a ordenar clikeando en columnas

#48
From: terrex
Date: Sat, 21 Feb 2004 01:09
495 lines
19600 bytes
JAVA. azureus plugin buscatorrents en espa�ol casi acabao kien me ayuda a 
ordenar clikeando en columnas
////////////////////////////////////////
///buscatorrents.jar/plugin.properties//
////////////////////////////////////////
plugin.class=Plugin
////////////////////////////////////////
///buscatorrents.jar/Plugin.java////////
////////////////////////////////////////

import org.gudy.azureus2.plugins.PluginInterface;

/**
  * Establece la interfaz de aplicaci�n
  * como no es un Applet, sino que es un Plugin,
  * asi lo debe conocer el Azureus.
  * Bueno, est� bien
  * no se paque sirve, pero s� que tiene que estar
  * que mas quieres!!?? es lo primero que hago
  * en Java :P
  */
public class Plugin implements org.gudy.azureus2.plugins.Plugin {
     private PluginInterface pluginInterface;

     public void initialize(PluginInterface pluginInterface) {
         this.pluginInterface = pluginInterface;
         this.pluginInterface.addView(new View(pluginInterface));
     }
}
////////////////////////////////////////
///buscatorrents.jar/View.java//////////
////////////////////////////////////////
/**
  * Buscador de torrents en espa�ol
  * usando emt y emw
  * terrex
  * terrex20@terra.es
  */

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.PluginView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

/**
  * @author terrex
  */
public class View extends PluginView {
     private Display display;
     private Composite composite;                //To_do esto es swt
     Button buscar;                              //Bot�n que dice "BUSCAR" 
para comenzar la b�squeda.
     Table listTable;                            //Tabla de resultados, 
grid con filas y columnas.
     Text query;                                 //EditBox 'escribe la 
cadena de busqueda'
     Combo categoria;                            //ComboBox Categoria de 
busqueda (aplicable solo a elmejortracker)
     Combo mostrarsinseeds;                      //ComboBox 0 solo 
seedeados 1 tambien los de 0 seeds
     boolean ellegadoalfin = false;              //Comprobador del final de 
los resultados de emt (salen en paginas de 30 en 30)
     String[] oktextos = new String[12];         //Temporal almacenador de 
variables en elmejortracker
     int okactual = 0;                           //cursor de lo de arriba
     int numeroderesultados = 0;                 //para poder decir X 
resultados.

     PluginInterface pluginInterface;            //interfaz de plugin nuse

     /**
      * Lo dice la misma palabra ;P
      *
      * @param pluginInterface
      */
     public View(PluginInterface pluginInterface) {
         this.pluginInterface = pluginInterface;
     }

     /**
      * El composite :S algo del swt
      *
      * @return
      */
     public Composite getComposite() {
         return this.composite;
     }

     /**
      * cadena nombre del plugin
      *
      * @return
      */
     public String getPluginViewName() {
         return "Buscatorrents";
     }

     /**
      * cadena segundo nombre del plugin
      *
      * @return
      */
     public String getFullTitle() {
         return "Buscatorrents";
     }

     /**
      * creando el entorno gr�fico.
      *
      * @param parent
      */
     public void initialize(Composite parent) {
         this.display = parent.getDisplay();
         this.composite = new Composite(parent, SWT.NULL);       //Nuestro 
grid tendr� 2 filas y 4 columnas
         GridLayout layout = new GridLayout();
         layout.numColumns = 4;
         composite.setLayout(layout);
         query = new Text(composite, SWT.NULL);                  //EditBox 
cadena de busqueda. Elemento primero
         query.setText("Escribe algo o d�jalo en blanco para buscar todos 
los archivos.");       //Texto inicial
         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);     
//Aumentar de tama�o horizontalmente
         query.setLayoutData(gridData);                          //ok
         categoria = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY | 
SWT.SIMPLE);   //combobox categoria. Elemento segundo
         categoria.add("(todos)");           //Categorias
         categoria.add("Pel�culas");         //se usa el indice de la 
seleccion
         categoria.add("M�sica");            //para pasarlo como parametro
         categoria.add("Series");            //al request url del 
elmejortracker
         categoria.add("Juegos");
         categoria.add("Programas");
         categoria.add("Miscel�nea");
         categoria.add("XXX");
         categoria.add("VideoClips");
         categoria.add("Anime");
         categoria.select(0);                //Por defecto, todas las 
categorias.
         mostrarsinseeds = new Combo(composite, SWT.DROP_DOWN | 
SWT.READ_ONLY | SWT.SIMPLE);     //combo sinconseeds. Elemento tercero
         mostrarsinseeds.add("s�lo los seedeados");
         mostrarsinseeds.add("todos");
         mostrarsinseeds.select(0);          //Por defecto solo seedeados
         buscar = new Button(composite, SWT.PUSH);       //Boton BUSCAR. 
Cuarto elemento
         buscar.setText("�BUSCA!");                      //Caption
         buscar.addListener(SWT.Selection, new Listener() {
             /**
              * Qu� hacer en caso de click en el boton. Simplemente llama a 
ok().
              *
              * @param e
              */
             public void handleEvent(Event e) {
                 ok();       //M�todo evento hacer click en el boton buscar
             }
         });

         //Cambio de fila. Estamos en la fila segunda.
         listTable = new Table(composite, SWT.SINGLE | SWT.BORDER | 
SWT.FULL_SELECTION);   //Tabla. elemento unico
         listTable.setHeaderVisible(true);
         final String[] columnNames = {"Categor�a", "Nombre", "URL", 
"Archivos", "Comentarios", "Valoraci�n", "A�adido", "Tama�o", 
"Completado", "Seeds", "Leechers", "Subido por"};
         int[] columnWidths = {75, 410, 0, 30, 30, 40, 70, 80, 80, 35, 35, 
90};
         //Initialise this table
         for (int i = 0; i < columnNames.length; i++) {
             TableColumn column = new TableColumn(listTable, SWT.NULL);
             column.setText(columnNames[i]);
             column.setWidth(columnWidths[i]);
         }
         gridData = new GridData(GridData.FILL_BOTH);
         gridData.horizontalSpan = 4;
         listTable.setLayoutData(gridData);             //hacer que la 
tabla ocupe lo maximo en ancho y alto
         listTable.addMouseListener(new MouseAdapter() {
             /**
              * Evento doble click en la tabla
              *
              * @param event
              */
             public void mouseDoubleClick(MouseEvent event) {
                 if (listTable == null || listTable.isDisposed())
                     return;
                 TableItem[] items = listTable.getSelection();
                 if (items.length == 1) {
                     TableItem item = items[0];
                     if (item.getText(2).length() > 0) 
Program.launch(item.getText(2)); 
//pluginInterface.openTorrentURL(item.getText(2));
                 }
             }
         });
         addTableElement("terrex20@terra.es", "Plugin programado en 
IntellijIDEA 4 por tx", "mailto:terrex20@terra.es", "", "", "", "", "", 
"", "", "", "");
         addTableElement("www.elmejorwarez.org", "Buscando en el tracker 
privado y publico de www.elmejorwarez.org", "http://www.elmejorwarez.org", 
"", "", "", "", "", "", "", "", "");
         addTableElement("Registro", "Reg�strate en elmejortracker.com", 
"http://www.elmejortracker.com/signup.php", "", "", "", "", "", "", "", 
"", "");
     }

     /**
      * A�ade una l�nea a la tabla de resultados. To_do se trata como 
Strings
      *
      * @param categoria
      * @param nombre
      * @param url
      * @param archivos
      * @param comentarios
      * @param valoracion
      * @param anadido
      * @param tamano
      * @param completado
      * @param seeds
      * @param leechers
      * @param subidopor
      */
     private void addTableElement(final String categoria, final String 
nombre, final String url, final String archivos, final String comentarios, 
final String valoracion, final String anadido, final String tamano, final 
String completado, final String seeds, final String leechers, final String 
subidopor) {
         if (display == null || display.isDisposed())
             return;
         display.asyncExec(new Runnable() {
             /**
              * HUM?�?
              */
             public void run() {
                 if (listTable == null || listTable.isDisposed())
                     return;
                 TableItem item = new TableItem(listTable, SWT.NULL);    
//Item de tabla
                 item.setText(0, categoria);                             
//Columnas del �tem
                 item.setText(1, nombre);
                 item.setText(2, url);
                 item.setText(3, archivos);
                 item.setText(4, comentarios);
                 item.setText(5, valoracion);
                 item.setText(6, anadido);
                 item.setText(7, tamano);
                 item.setText(8, completado);
                 item.setText(9, seeds);
                 item.setText(10, leechers);
                 item.setText(11, subidopor);
             }
         });
     }

     /**
      * Responde al envento hacer click en BUSCAR
      */
     private void ok() {
         ok_empieza();   //Variables iniciales
         int i = 0;      //Para el control de resultados de 30 en 30 de 
emt. (i=n�mero de pagina)
         while (!ellegadoalfin) {
             ok_recibe(i);     //Petici�n de la p�gina
             i++;
         }
         btclub_recibe("http://www.bt-club.com:6969");   //Petici�n del 
announce del tracker privado
         ok_acaba();     //Recuperar variables iniciales
     }

     /**
      * Parte primera de la respuesta al evento BUSCAR
      */
     private void ok_empieza() {
         buscar.setEnabled(false);
         query.setEditable(false);
         listTable.removeAll();
         categoria.setEnabled(false);
         mostrarsinseeds.setEnabled(false);
         ellegadoalfin = false;
         numeroderesultados = 0;
     }

     /**
      * Parte ultima de la respuesta al evento BUSCAR
      */
     private void ok_acaba() {
         buscar.setEnabled(true);
         query.setEditable(true);
         categoria.setEnabled(true);
         mostrarsinseeds.setEnabled(true);
         ellegadoalfin = false;
         if (numeroderesultados != 0) {
             addTableElement("", numeroderesultados + " .torrents 
encontrados.", "", "", "", "", "", "", "", "", "", "");
             addTableElement("", "Haz doble click para descargarlo.", "", 
"", "", "", "", "", "", "", "", "");
         } else {
             addTableElement("", "No hay ninguno.", "", "", "", "", "", "", 
"", "", "", "");
         }
     }

     /**
      * Recibir una pagina de resultados de emt
      *
      * @param pagina
      */
     private void ok_recibe(int pagina) {
         ellegadoalfin = true;
         try {
             URL yahoo = new URL("http://www.elmejortracker.com/?search=" 
+ URLEncoder.encode(query.getText()) + "&cat=" 
+ categoria.getSelectionIndex() + "&incldead=" 
+ mostrarsinseeds.getSelectionIndex() + "&page=" + pagina);
             BufferedReader in = new BufferedReader(new 
InputStreamReader(yahoo.openStream()));
             String inputLine;
             while ((inputLine = in.readLine()) != null) {
                 //Comprobaciones iniciales para hacer valido el proceso
                 //de la linea por parte de ok_analizaLinea
                 if ((inputLine != "") && (inputLine.length() > 2) && 
(inputLine.charAt(0) == '<')) ok_analizaLinea(inputLine);
             }
             in.close();
             return;
         } catch (MalformedURLException me) {
             return;
         } catch (IOException ioe) {
             return;
         }
     }

     /**
      * Recibir la pagina de archivos de btclub
      *
      * @param url
      */
     private void btclub_recibe(String url) {
         try {
             URL yahoo = new URL(url);
             BufferedReader in = new BufferedReader(new 
InputStreamReader(yahoo.openStream()));
             String inputLine;
             while ((inputLine = in.readLine()) != null) {
                 //Comprobaciones iniciales para hacer valido el proceso
                 //de la linea por parte de btclub_analizaLinea
                 if ((inputLine != "") && (inputLine.length() > 2) && 
(inputLine.indexOf("<tr><td><code>") == 0) && 
(inputLine.indexOf("</td></tr>") > 0)) btclub_analizaLinea(inputLine);
             }
             in.close();
             return;
         } catch (MalformedURLException me) {
             return;
         } catch (IOException ioe) {
             return;
         }
     }

     /**
      * Analizar linea en emt
      *
      * @param txt
      */
     private void ok_analizaLinea(String txt) {
         if (txt.indexOf("<tr>") == 0) { //Fila interesante
             okactual = 0;
             //Celda interesante de la fila interesante
         } else if ((txt.indexOf("<td bgcolor=ECECEC align=center>") == 0) 
|| (txt.indexOf("<td bgcolor=F7F7F7 align=center>") == 0)) {
             if (okactual != 2) {
                 oktextos[okactual] = textolibre(txt);
             } else {
                 oktextos[okactual] = parseurl(txt);
             }
             okactual++;
             //terminacion de fila interesnante
         } else if ((txt.indexOf("</tr>") == 0) && (okactual == 12)) {
             okactual = 0;
             if (oktextos[1] != "") {
                 if (mostrarsinseeds.getSelectionIndex() == 1) {
                     addTableElement(oktextos[0], oktextos[1], oktextos[2], 
oktextos[3], oktextos[4], oktextos[5], oktextos[6], oktextos[7], 
oktextos[8], oktextos[9], oktextos[10], oktextos[11]);
                     numeroderesultados++;
                 } else {
                     if (oktextos[9].charAt(0) != '0') {
                         addTableElement(oktextos[0], oktextos[1], 
oktextos[2], oktextos[3], oktextos[4], oktextos[5], oktextos[6], 
oktextos[7], oktextos[8], oktextos[9], oktextos[10], oktextos[11]);
                         numeroderesultados++;
                     }
                 }
             }
             ellegadoalfin = false;
             //Sin resultados
         } else if (txt == "<h2>No se encontro nada!</h2> ") {
             ellegadoalfin = true;
         }
     }

     /**
      * Analizador de linea de btclub
      *
      * @param txt
      */
     private void btclub_analizaLinea(String txt) {
         String hash;
         String nombre;
         String tamano;
         String seeds;
         String leechers;
         String completados;
         //Captura las celdas utiles en sus sitios apropiados
         hash = textolibre(txt);
         txt = txt.replaceFirst(hash, "");
         nombre = textolibre(txt);
         //Si no coincide con la cadena de busqueda sin diferenciar
         //mayusculas de minusculas, puerta
         if (nombre.toUpperCase().indexOf(query.getText().toUpperCase()) == 
-1) return;
         txt = txt.replaceFirst("<tr><td><code></code></td><td>", "");
         txt = txt.substring(txt.indexOf("<"));
         tamano = textolibre(txt);
         txt = txt.replaceFirst(tamano, "");
         seeds = textolibre(txt);
         //Si no tiene seeds y queremos que lo tenga, puerta
         if ((mostrarsinseeds.getSelectionIndex() == 0) && (seeds.charAt(0) 
== '0')) return;
         txt = txt.replaceFirst(seeds, "");
         leechers = textolibre(txt);
         txt = txt.replaceFirst(leechers, "");
         completados = textolibre(txt);
         //a�adir linea buena
         addTableElement("bt-club.com", nombre, 
"http://www.elmejorwarez.org", "", "", hash, "", tamano, completados + " 
veces", seeds, leechers, "emw");
         numeroderesultados++;
     }

     /**
      * Devuelve el primer texto libre entre etiquetas html
      * ejemplo
      * 
<jjj><jjjjkjk><kjhjkhkj>textolibredevuelto</eehsuhd></edjdhj></fkfj><kjd>estetextonosecogeria<fhfhjs><sjhs>
      *
      * @param txt
      * @return
      */
     private String textolibre(String txt) {
         int gt = txt.indexOf(">");
         if (gt == -1 || gt + 1 >= txt.length()) return "";
         txt = txt.substring(gt + 1);
         if (txt.charAt(0) == '<') txt = textolibre(txt);
         gt = txt.indexOf("<");
         if (gt != -1) txt = txt.substring(0, gt);
         return txt;
     }

     /**
      * Devuelve un url de .torrent de emt
      *
      * @param txt
      * @return
      */
     private String parseurl(String txt) {
         txt = txt.replaceFirst("<td bgcolor=ECECEC align=center><a 
href=\"", "");
         txt = txt.replaceFirst("\"><img src=\"pic/dl.gif\" 
border=0></a></td>", "");
         return "http://www.elmejortracker.com/" + txt;
     }

     //TODO queda el orden de las columnas.

     //TODO mas importante queda el recoge "solo un resultado".

}
Technical Details
Message-ID: <opr3o36itw11a7ln@localhost>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!nsnmpen1-lo.nuria.telefonica-data.net!telenews.teleline.es!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f78ff,a9275d0b54a5e04f,start
X-Google-Attributes: gidf78ff,public
X-Google-Thread: f86c8,a9275d0b54a5e04f,start
X-Google-Attributes: gidf86c8,public
X-Google-Thread: 10d088,a9275d0b54a5e04f,start
X-Google-Attributes: gid10d088,public
X-Google-Thread: 1116f3,a9275d0b54a5e04f,start
X-Google-Attributes: gid1116f3,public
X-Google-ArrivalTime: 2004-02-20 17:09:49 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!nsnmpen1-lo.nuria.telefonica-data.net!telenews.teleline.es!not-for-mail
X-Trace-PostClient-IP: 62.42.29.220
Newsgroups: es.comp.os.linux.programacion,es.comp.os.ms-windows.programacion,esp.comp.so.linux.programacion,es.comp.lenguajes.java
Followup-To: es.comp.os.linux.programacion,es.comp.os.ms-windows.programacion,esp.comp.so.linux.programacion,es.comp.lenguajes.java
Subject: JAVA. azureus plugin buscatorrents en español casi acabao kien me ayuda a ordenar clikeando en columnas
From: terrex <negativo@terra.es>
Content-Type: text/plain; format=flowed; charset=iso-8859-15
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Message-ID: <opr3o36itw11a7ln@localhost>
User-Agent: Opera7.21/Win32 M2 build 3218
Lines: 495
Date: Sat, 21 Feb 2004 01:09:48 GMT
NNTP-Posting-Host: 10.20.31.4
X-Complaints-To: usenet@teleline.es
X-Trace: telenews.teleline.es 1077325788 10.20.31.4 (Sat, 21 Feb 2004 02:09:48 MET)
NNTP-Posting-Date: Sat, 21 Feb 2004 02:09:48 MET
Organization: Terra Networks