-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
120 additions
and
13 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
26 changes: 26 additions & 0 deletions
26
src/main/java/mServer/crawler/sender/orf/json/OrfMoreEpisodesDeserializer.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,26 @@ | ||
package mServer.crawler.sender.orf.json; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import mServer.crawler.sender.base.CrawlerUrlDTO; | ||
import mServer.crawler.sender.base.JsonUtils; | ||
import mServer.crawler.sender.base.UrlUtils; | ||
import mServer.crawler.sender.orf.OrfConstants; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.Optional; | ||
|
||
public class OrfMoreEpisodesDeserializer implements JsonDeserializer<CrawlerUrlDTO> { | ||
|
||
private static final String ATTRIBUTE_URL = "url"; | ||
|
||
@Override | ||
public CrawlerUrlDTO deserialize( | ||
JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { | ||
|
||
final Optional<String> url = | ||
JsonUtils.getAttributeAsString(jsonElement.getAsJsonObject(), ATTRIBUTE_URL); | ||
return url.map(s -> new CrawlerUrlDTO(UrlUtils.addDomainIfMissing(s, OrfConstants.URL_BASE))).orElse(null); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/mServer/crawler/sender/orf/parser/OrfMoreEpisodesParser.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,27 @@ | ||
package mServer.crawler.sender.orf.parser; | ||
|
||
|
||
import mServer.crawler.sender.orf.TopicUrlDTO; | ||
import org.jsoup.nodes.Document; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class OrfMoreEpisodesParser { | ||
private static final String EPISODES_SELECTOR = "article.b-teaser > a.teaser-link"; | ||
private static final String ATTRIBUTE_HREF = "href"; | ||
|
||
public List<TopicUrlDTO> parse(final Document document, final String topic) { | ||
final List<TopicUrlDTO> result = new ArrayList<>(); | ||
|
||
document | ||
.select(EPISODES_SELECTOR) | ||
.forEach( | ||
episode -> { | ||
final String url = episode.attr(ATTRIBUTE_HREF); | ||
result.add(new TopicUrlDTO(topic, url)); | ||
}); | ||
|
||
return result; | ||
} | ||
} |
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