-
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
1 parent
5a91a39
commit 0c3cb99
Showing
10 changed files
with
1,257 additions
and
10 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
26 changes: 26 additions & 0 deletions
26
src/main/java/de/mediathekview/mserver/crawler/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 de.mediathekview.mserver.crawler.orf.json; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import de.mediathekview.mserver.base.utils.JsonUtils; | ||
import de.mediathekview.mserver.base.utils.UrlUtils; | ||
import de.mediathekview.mserver.crawler.basic.CrawlerUrlDTO; | ||
import de.mediathekview.mserver.crawler.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); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/de/mediathekview/mserver/crawler/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,25 @@ | ||
package de.mediathekview.mserver.crawler.orf.parser; | ||
|
||
import de.mediathekview.mserver.base.HtmlConsts; | ||
import de.mediathekview.mserver.crawler.basic.TopicUrlDTO; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.jsoup.nodes.Document; | ||
|
||
public class OrfMoreEpisodesParser { | ||
private static final String EPISODES_SELECTOR = "article.b-teaser > a.teaser-link"; | ||
|
||
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(HtmlConsts.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
23 changes: 23 additions & 0 deletions
23
src/test/java/de/mediathekview/mserver/crawler/orf/json/OrfMoreEpisodesDeserializerTest.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,23 @@ | ||
package de.mediathekview.mserver.crawler.orf.json; | ||
|
||
import com.google.gson.JsonElement; | ||
import de.mediathekview.mserver.crawler.basic.CrawlerUrlDTO; | ||
import de.mediathekview.mserver.testhelper.JsonFileReader; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class OrfMoreEpisodesDeserializerTest { | ||
|
||
@Test | ||
void testDeserialize() { | ||
final JsonElement jsonElement = JsonFileReader.readJson("/orf/orf_film_more_episodes.json"); | ||
|
||
final OrfMoreEpisodesDeserializer target = new OrfMoreEpisodesDeserializer(); | ||
final CrawlerUrlDTO actual = target.deserialize(jsonElement, null, null); | ||
|
||
assertNotNull(actual); | ||
assertEquals("https://tvthek.orf.at/lane-plus/other_episodes_of_profile?profileId=13895917&profileSlug=Biester", actual.getUrl()); | ||
|
||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/de/mediathekview/mserver/crawler/orf/parser/OrfMoreEpisodesParserTest.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,39 @@ | ||
package de.mediathekview.mserver.crawler.orf.parser; | ||
|
||
import de.mediathekview.mserver.crawler.basic.TopicUrlDTO; | ||
import de.mediathekview.mserver.testhelper.FileReader; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class OrfMoreEpisodesParserTest { | ||
@Test | ||
void parseDocumentWithEpisodes() { | ||
TopicUrlDTO[] expectedFilms = new TopicUrlDTO[] { | ||
new TopicUrlDTO("Biester", "https://tvthek.orf.at/profile/Biester/13895917/Biester-Folge-9/14207236"), | ||
new TopicUrlDTO("Biester", "https://tvthek.orf.at/profile/Biester/13895917/Biester-Folge-8/14207235"), | ||
new TopicUrlDTO("Biester", "https://tvthek.orf.at/profile/Biester/13895917/Biester-Folge-7/14207234"), | ||
new TopicUrlDTO("Biester", "https://tvthek.orf.at/profile/Biester/13895917/Biester-Folge-6/14207233"), | ||
new TopicUrlDTO("Biester", "https://tvthek.orf.at/profile/Biester/13895917/Biester-Folge-5/14207232"), | ||
new TopicUrlDTO("Biester", "https://tvthek.orf.at/profile/Biester/13895917/Biester-Folge-4/14207231"), | ||
new TopicUrlDTO("Biester", "https://tvthek.orf.at/profile/Biester/13895917/Biester-Folge-3/14207230"), | ||
new TopicUrlDTO("Biester", "https://tvthek.orf.at/profile/Biester/13895917/Biester-Folge-2/14207229"), | ||
new TopicUrlDTO("Biester", "https://tvthek.orf.at/profile/Biester/13895917/Alle-Folgen-jetzt-Biester-1-10/14207227"), | ||
new TopicUrlDTO("Biester", "https://tvthek.orf.at/profile/Biester/13895917/Biester-Folge-10/14207252"), | ||
}; | ||
|
||
final Document document = Jsoup.parse(FileReader.readFile("/orf/orf_film_more_episodes.html")); | ||
|
||
OrfMoreEpisodesParser target = new OrfMoreEpisodesParser(); | ||
final List<TopicUrlDTO> actual = target.parse(document, "Biester"); | ||
|
||
assertEquals(10, actual.size()); | ||
MatcherAssert.assertThat(actual, Matchers.containsInAnyOrder(expectedFilms)); | ||
} | ||
} |
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
Oops, something went wrong.