Skip to content

Commit

Permalink
Merge pull request #34 from darkman97i/issue/33
Browse files Browse the repository at this point in the history
download torrent timeout
  • Loading branch information
darkman97i authored Feb 19, 2022
2 parents 6cb498d + a5fc704 commit d1d6886
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Utility to get torrent download links from the web without advertisements:
```
mkdir /utils
cd /utils
wget https://github.com/darkman97i/torrent-web-parser/releases/download/v.1.4/torrent-web-parser-1.4.zip
unzip torrent-web-parser-1.4.zip
java -jar torrent-web-parser -g /utils/torrent-web-parser-1.4/geckodriver -d /utils/torrent-web-parser-1.4 -f universe,dry
wget https://github.com/darkman97i/torrent-web-parser/releases/download/v.1.5/torrent-web-parser-1.5.zip
unzip torrent-web-parser-1.5.zip
java -jar torrent-web-parser -g /utils/torrent-web-parser-1.5/geckodriver -d /utils/torrent-web-parser-1.5 -f universe,dry
```

### Parameters
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/info/llort/torrent/util/PctmixWebParserV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public static void capture(String urlWebToParse, String geckoDriverPath, List<St
Console.println("Torrent page link: " + pli.getUrl(), WHITE);
}

Set<PageLinkInfo> downloadTorrentLinks = downloadTorrentLinks(torrentPageLinks, driver, proxy);
for (PageLinkInfo pli : downloadTorrentLinks) {
Console.println("Download link: " + pli.getUrl(), WHITE);
downloadTorrentFile(pli, driver, downloadTimeOut, proxy);
}
Set<PageLinkInfo> downloadTorrentLinks = downloadTorrentLinks(torrentPageLinks, driver, proxy, downloadTimeOut);
// for (PageLinkInfo pli : downloadTorrentLinks) {
// Console.println("Download link: " + pli.getUrl(), WHITE);
// downloadTorrentFile(pli, driver, downloadTimeOut, proxy);
// }
}

public static Set<PageLinkInfo> findMainPageLinks(String url, String geckoDriverPath, List<String> filters, WebDriver driver) throws IOException {
Expand Down Expand Up @@ -97,7 +97,7 @@ public static Set<PageLinkInfo> findPageTorrentLinks(Set<PageLinkInfo> pageLinks
return links;
}

public static Set<PageLinkInfo> downloadTorrentLinks(Set<PageLinkInfo> pageLinks, WebDriver driver, BrowserMobProxy proxy) throws IOException {
public static Set<PageLinkInfo> downloadTorrentLinks(Set<PageLinkInfo> pageLinks, WebDriver driver, BrowserMobProxy proxy, long downloadTimeOut) throws IOException, InterruptedException {
Set<PageLinkInfo> links = new HashSet<>();
for (PageLinkInfo pli : pageLinks) {
// Setting referer before jump to the page
Expand Down Expand Up @@ -125,12 +125,14 @@ public static Set<PageLinkInfo> downloadTorrentLinks(Set<PageLinkInfo> pageLinks
Console.println("executing javascript: " + js, YELLOW);
Object result = ((JavascriptExecutor) driver).executeScript(js);
Console.println("Javascript result: " + js, GREEN);
String torrentFileLinkValue = "https://atomixhq.art/t_download/" + result;
String torrentFileLinkValue = "https://atomixhq.art" + result;
Console.println("torrentFileLinkValue: " + torrentFileLinkValue, GREEN);
PageLinkInfo newPli = new PageLinkInfo();
newPli.setUrl(torrentFileLinkValue);
newPli.setReferer(pli.getUrl());
links.add(newPli);
// Must donwload here because downtime
downloadTorrentFile(newPli, driver, downloadTimeOut, proxy);
}

} else {
Expand All @@ -143,7 +145,9 @@ public static Set<PageLinkInfo> downloadTorrentLinks(Set<PageLinkInfo> pageLinks
public static void downloadTorrentFile(PageLinkInfo pli, WebDriver driver, long timeOut, BrowserMobProxy proxy) throws InterruptedException {
try {
// Referer must be atomtt
proxy.addHeader(HttpHeaders.REFERER, pli.getReferer());
proxy.addHeader(HttpHeaders.REFERER, "https://atomtt.com/"); // Referer is the page what contains the torrent link //atomtt etc...
proxy.addHeader("authority", "atomixhq.art");
proxy.addHeader("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36");
// Set timeout otherwise the driver lock
driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(timeOut));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(timeOut));
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/info/jllort/torrent/ParserCheckIssue31.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static void main(String[] args) throws UnknownHostException, InterruptedE
String dstPath = Config.FILESYSTEM_DOWNLOAD_PATH;
long timeOut = Config.FILE_DOWNLOAD_TIMEOUT;

String referer = "https://atomixhq.art/descargar/torrent/serie/el-pacificador/temporada-1/capitulo-08/";
String link = "https://atomtt.com/t_download/168542/el-pacificador---temporada-1/";
String referer = "https://atomixhq.art/descargar/torrent/peliculas-castellano/venganza-a-golpes-2022-/blurayrip-ac3-5-1/";
String link = "https://atomtt.com/t_download/168581/venganza-a-golpes--2022-/";

// Creating proxy
BrowserMobProxy proxy = new BrowserMobProxyServer();
Expand Down Expand Up @@ -82,9 +82,9 @@ public static void main(String[] args) throws UnknownHostException, InterruptedE
System.out.println("intValue found: " + intValue);
if (driver instanceof JavascriptExecutor) {
// Referer must be atomtt
proxy.addHeader(HttpHeaders.REFERER, "https://atomtt.com/t_download/168542/el-pacificador---temporada-1/");
proxy.addHeader(HttpHeaders.REFERER, link);
// Javascript request to be executed by selenium
String js = "var values = {'t':'168542'};\n"; // the variable
String js = "var values = {'t':'168581'};\n"; // the variable
js += "var xhr = new XMLHttpRequest();\n";
js += "xhr.open('POST', 'https://atomtt.com/to.php', false);\n";
js += "xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');\n";
Expand All @@ -95,13 +95,15 @@ public static void main(String[] args) throws UnknownHostException, InterruptedE
System.out.println("Result value of cal to top: " + result);
// result = ((JavascriptExecutor) driver).executeScript("alert('Welcome to Guru99');");
// download URl = https://atomixhq.art/t_download/temp/17022022/168542/El-Pacificador---Temporada-1--HDTV.torrent?md5=b611CNys8mldMTSN_atN6A&expires=1645101721
String torrentFileLinkValue = "https://atomixhq.art/t_download/" + result;
String torrentFileLinkValue = "https://atomixhq.art" + result;
System.out.println(torrentFileLinkValue);
driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(timeOut));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(timeOut));
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(timeOut));
// Other referer
proxy.addHeader(HttpHeaders.REFERER, link); // Referer is the page what contains the torrent link //atomtt etc...
proxy.addHeader(HttpHeaders.REFERER, "https://atomtt.com/"); // Referer is the page what contains the torrent link //atomtt etc...
proxy.addHeader("authority", "atomixhq.art");
proxy.addHeader("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36");
driver.navigate().to(torrentFileLinkValue);
}
}
Expand Down

0 comments on commit d1d6886

Please sign in to comment.