-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Lime Torrent ✌️ and Proxy for pirate bay ⚠️
- Loading branch information
1 parent
f953397
commit e38f6ca
Showing
13 changed files
with
498 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/main/java/com/project/eniac/engine/impl/duckduckgo/DuckDuckGoGeneralSearchEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
src/main/java/com/project/eniac/engine/impl/limetorrent/LimeTorrentSearchEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
* Copyright 2021 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.project.eniac.engine.impl.limetorrent; | ||
|
||
import com.project.eniac.constant.RequestHeaders; | ||
import com.project.eniac.engine.EngineConstant; | ||
import com.project.eniac.engine.spec.TorrentSearchEngine; | ||
import com.project.eniac.entity.EngineResultEntity.SearchResultEntity; | ||
import com.project.eniac.entity.EngineResultEntity.TorrentSearchResultEntity; | ||
import com.project.eniac.entity.SearchRequestEntity; | ||
import com.project.eniac.service.spec.HttpClientProviderService; | ||
import com.project.eniac.types.EngineResultType; | ||
import com.project.eniac.utils.ConversionUtil; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.apache.http.client.utils.URIBuilder; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.jsoup.select.Elements; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class LimeTorrentSearchEngine extends TorrentSearchEngine { | ||
|
||
private final HttpClientProviderService httpClientProviderService; | ||
|
||
private static final String BASE_URL = "https://limetorrents.unblockninja.com/"; | ||
|
||
@Override | ||
public String getEngineName() { | ||
return EngineConstant.ENGINE_LIME_TORRENT; | ||
} | ||
|
||
@Override | ||
public HttpClientProviderService getHttpClientService() { | ||
return this.httpClientProviderService; | ||
} | ||
|
||
@Override | ||
public HttpUriRequest getRequest(SearchRequestEntity searchEntity) { | ||
String url = new StringBuilder(BASE_URL) | ||
.append("search/all/") | ||
.append(ConversionUtil.encodeURL(searchEntity.getQuery())) | ||
.append("/seeds/1/").toString(); | ||
try { | ||
|
||
URI uri = new URIBuilder(url).build(); | ||
|
||
HttpGet request = new HttpGet(uri); | ||
request.addHeader(RequestHeaders.KEY_ACCEPT_LANGUAGE, RequestHeaders.VALUE_ACCEPT_LANGUAGE); | ||
request.addHeader(RequestHeaders.KEY_ACCEPT, RequestHeaders.VALUE_ACCEPT_HTML); | ||
|
||
return request; | ||
} catch (URISyntaxException exception) { | ||
log.error("Exception on Creating URL : {}", url); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public SearchResultEntity<TorrentSearchResultEntity> getResponse(String response) { | ||
List<TorrentSearchResultEntity> searchResultEntity = new ArrayList<>(); | ||
|
||
Document document = Jsoup.parse(response); | ||
Elements elements = document.select("table.table2 > tbody > tr"); // Select all results | ||
|
||
for (Element element : elements) { | ||
if (!element.hasAttr("bgcolor")) continue; | ||
|
||
TorrentSearchResultEntity torrentSearchResultEntity = this.extractEntity(element); | ||
if (ObjectUtils.isNotEmpty(torrentSearchResultEntity)) searchResultEntity.add(torrentSearchResultEntity); | ||
} | ||
|
||
SearchResultEntity.SearchResultEntityBuilder<TorrentSearchResultEntity> resultEntityBuilder = SearchResultEntity | ||
.<TorrentSearchResultEntity>builder() | ||
.engineName(this.getEngineName()) | ||
.engineType(this.getEngineType()); | ||
|
||
// Result Delivery | ||
if (searchResultEntity.size() > 0) { | ||
return resultEntityBuilder | ||
.searchResults(searchResultEntity) | ||
.engineResultType(EngineResultType.FOUND_SEARCH_RESULT) | ||
.build(); | ||
} else if (elements.isEmpty()) { | ||
return resultEntityBuilder | ||
.engineResultType(EngineResultType.NO_SEARCH_RESULT) | ||
.build(); | ||
} else { | ||
return resultEntityBuilder | ||
.engineResultType(EngineResultType.ENGINE_BREAK_DOWN) | ||
.build(); | ||
} | ||
} | ||
|
||
private TorrentSearchResultEntity extractEntity(Element element) { | ||
if (ObjectUtils.isEmpty(element)) return null; | ||
TorrentSearchResultEntity.TorrentSearchResultEntityBuilder searchResultEntity = TorrentSearchResultEntity.builder(); | ||
|
||
Element seederElement = element.selectFirst("td.tdseed"); | ||
Element leechElement = element.selectFirst("td.tdleech"); | ||
Elements anchorElements = element.select("div.tt-name > a"); | ||
Elements dateTypeAndSizeElements = element.select("td.tdnormal"); | ||
|
||
if (ObjectUtils.anyNull(seederElement, leechElement)) return null; | ||
if (ObjectUtils.anyNull(anchorElements, dateTypeAndSizeElements)) return null; | ||
|
||
String seedCount = seederElement.text().replace(",", ""); | ||
searchResultEntity.seeders(ConversionUtil.parseInt(seedCount)); | ||
|
||
String leechCount = leechElement.text().replace(",", ""); | ||
searchResultEntity.leechers(ConversionUtil.parseInt(leechCount)); | ||
|
||
for (Element anchorElement : anchorElements) { | ||
if (anchorElement.hasClass("csprite_dl14")) { | ||
String url = anchorElement.attr("href"); | ||
String magneticLink = this.extractMagneticLink(url); | ||
searchResultEntity.torrentUrl(url); | ||
searchResultEntity.magneticLink(magneticLink); | ||
} else { | ||
searchResultEntity.torrentName(anchorElement.text()); | ||
} | ||
} | ||
|
||
for (Element dateTypeAndSizeElement : dateTypeAndSizeElements) { | ||
String content = dateTypeAndSizeElement.text(); | ||
String[] splittedContent = content.split(" - in "); | ||
if (splittedContent.length > 1) { | ||
searchResultEntity.uploadedDate(splittedContent[0]); | ||
searchResultEntity.category(splittedContent[1]); | ||
} else { | ||
searchResultEntity.torrentSize(content); | ||
} | ||
} | ||
|
||
return searchResultEntity.build(); | ||
} | ||
|
||
private String extractMagneticLink(String url) { | ||
if (StringUtils.isBlank(url)) return null; | ||
|
||
String domainRemoved = url.replace("http://itorrents.org/torrent/", ""); | ||
String[] splittedUrl = domainRemoved.split(".torrent"); | ||
|
||
if (ObjectUtils.isEmpty(splittedUrl)) return null; | ||
return new StringBuilder("magnet:?xt=urn:btih:") | ||
.append(splittedUrl[0]) | ||
.toString(); | ||
} | ||
|
||
} |
Oops, something went wrong.