Skip to content

Instantly share code, notes, and snippets.

@ramon-rd
Last active February 18, 2016 17:45
Show Gist options
  • Save ramon-rd/449bc6d7a451c3455684 to your computer and use it in GitHub Desktop.
Save ramon-rd/449bc6d7a451c3455684 to your computer and use it in GitHub Desktop.
/*
The MIT License (MIT)
Copyright (c) 2016 sinfonier-project
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package com.sinfonier.bolts;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class ArchiveTorrentBolt1 extends BaseSinfonierBolt {
// Class variables
public String BUSQUEDA;
// Must implement constructor. Do not touch
public ArchiveTorrentBolt1(String path) {
super(path);
}
@Override
public void userprepare() {
// Initialize your DB Connections or non-serializable classes.
// This method will be executed once.
this.BUSQUEDA = getParam("busqueda");
}
@Override
public void userexecute() {
// TO-DO: Write code here. This method will be called every ingoing tuple
String url = this.getField(this.BUSQUEDA).toString();
Document doc;
try {
// need http protocol
doc = Jsoup.connect(url).get();
// get page title
String title = doc.title();
// get all links
Elements loginform = doc.getElementsByClass("boxy");
int j = 0;
for (Element link : loginform) {
if(j==2){
if(!link.getElementsByClass("stealth").text().equals("null")){
this.addField("usuariotorrent",(link.getElementsByClass("stealth").text()));
}
else
this.addField("usuariotorrent", "0");
j=0;
}
j++;
}
} catch (IOException e) {
e.printStackTrace();
}
this.emit();
}
@Override
public void usercleanup() {
// Close connections, clean resources
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment