-
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.
Merge branch 'hotfix/arte_recents' into hotfix/3.1.228
- Loading branch information
Showing
10 changed files
with
1,245 additions
and
36 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
55 changes: 55 additions & 0 deletions
55
src/main/java/mServer/crawler/sender/arte/ArteListBaseDeserializer.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,55 @@ | ||
package mServer.crawler.sender.arte; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import de.mediathekview.mlib.tool.Log; | ||
import mServer.crawler.sender.base.JsonUtils; | ||
import mServer.crawler.sender.base.UrlUtils; | ||
|
||
import java.util.Optional; | ||
|
||
public abstract class ArteListBaseDeserializer { | ||
|
||
private static final String JSON_ELEMENT_DATA = "data"; | ||
private static final String JSON_ELEMENT_PROGRAMID = "programId"; | ||
private static final String JSON_ELEMENT_PAGINATION = "pagination"; | ||
private static final String JSON_ELEMENT_LINKS = "links"; | ||
private static final String JSON_ELEMENT_NEXT = "next"; | ||
|
||
protected Optional<String> parsePagination(JsonObject jsonObject) { | ||
if (jsonObject.has(JSON_ELEMENT_PAGINATION) && !jsonObject.get(JSON_ELEMENT_PAGINATION).isJsonNull()) { | ||
final JsonObject pagionationObject = jsonObject.get(JSON_ELEMENT_PAGINATION).getAsJsonObject(); | ||
if(pagionationObject.has(JSON_ELEMENT_LINKS)) { | ||
final JsonObject linksObject = pagionationObject.get(JSON_ELEMENT_LINKS).getAsJsonObject(); | ||
final Optional<String> nextUrl = JsonUtils.getAttributeAsString(linksObject, JSON_ELEMENT_NEXT); | ||
if (nextUrl.isPresent()) { | ||
return Optional.of(UrlUtils.addDomainIfMissing(nextUrl.get().replace("/api/emac/", "/api/rproxy/emac/"), "https://www.arte.tv")); | ||
} | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
|
||
protected void extractProgramIdFromData(JsonObject jsonObectWithData, ArteCategoryFilmsDTO dto) { | ||
if (jsonObectWithData.has(JSON_ELEMENT_DATA)) { | ||
for(JsonElement dataElement : jsonObectWithData.get(JSON_ELEMENT_DATA).getAsJsonArray()) { | ||
if (!dataElement.getAsJsonObject().get(JSON_ELEMENT_PROGRAMID).isJsonNull()) { | ||
Optional<String> programId = JsonUtils.getAttributeAsString(dataElement.getAsJsonObject(), JSON_ELEMENT_PROGRAMID); | ||
if (programId.isPresent()) { | ||
if (programId.get().startsWith("RC-")) { | ||
try { | ||
long collectionId = Long.parseLong(programId.get().replace("RC-", "")); | ||
dto.addCollection(String.format("RC-%06d", collectionId)); | ||
} catch (NumberFormatException e) { | ||
Log.errorLog(12834939, "Invalid collection id: " + programId); | ||
} | ||
} else { | ||
dto.addProgramId(programId.get()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/mServer/crawler/sender/arte/ArteSubPageDeserializer.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,28 @@ | ||
package mServer.crawler.sender.arte; | ||
|
||
import com.google.gson.*; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.Optional; | ||
|
||
public class ArteSubPageDeserializer extends ArteListBaseDeserializer implements JsonDeserializer<ArteCategoryFilmsDTO> { | ||
private static final String JSON_ELEMENT_VALUE = "value"; | ||
|
||
@Override | ||
public ArteCategoryFilmsDTO deserialize(JsonElement aJsonElement, Type aType, JsonDeserializationContext aContext) throws JsonParseException { | ||
final ArteCategoryFilmsDTO dto = new ArteCategoryFilmsDTO(); | ||
|
||
JsonElement rootElement = aJsonElement; | ||
if (aJsonElement.getAsJsonObject().has(JSON_ELEMENT_VALUE)) { | ||
rootElement = aJsonElement.getAsJsonObject().get(JSON_ELEMENT_VALUE); | ||
} | ||
|
||
JsonObject rootObject = rootElement.getAsJsonObject(); | ||
extractProgramIdFromData(rootObject, dto); | ||
|
||
Optional<String> url = parsePagination(rootObject); | ||
url.ifPresent(dto::setNextPageUrl); | ||
|
||
return dto; | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
src/test/developTest/java/mServer/crawler/sender/arte/ArteSubPageDeserializerTest.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,55 @@ | ||
package mServer.crawler.sender.arte; | ||
|
||
import com.google.gson.JsonObject; | ||
import mServer.test.JsonFileReader; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Set; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
@RunWith(Parameterized.class) | ||
public class ArteSubPageDeserializerTest { | ||
|
||
private final String jsonFile; | ||
private final String[] expectedProgramIds; | ||
private final boolean expectedHasNextPage; | ||
private final String expectedNextPageUrl; | ||
private final ArteSubPageDeserializer target; | ||
public ArteSubPageDeserializerTest(String aJsonFile, String[] aProgramIds, boolean aNextPage, String nextPageUrl) { | ||
jsonFile = aJsonFile; | ||
expectedProgramIds = aProgramIds; | ||
expectedHasNextPage = aNextPage; | ||
expectedNextPageUrl = nextPageUrl; | ||
this.target = new ArteSubPageDeserializer(); | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> data() { | ||
return Arrays.asList(new Object[][]{ | ||
{"/arte/arte_video_list2.json", new String[]{"099708-000-A", "098846-000-A", "111648-001-A", "112235-000-A", "113043-139-A"}, true, "https://www.arte.tv/api/rproxy/emac/v4/de/web/zones/82b597d7-a83b-4dd8-bea8-ad71675fdf23/content?abv=A&authorizedCountry=DE&page=3&pageId=MOST_VIEWED&zoneIndexInPage=0"}, | ||
{"/arte/arte_video_list_last.json", new String[]{"102805-000-A","104017-000-A", "106273-006-A"}, false, null} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testDeserialize() { | ||
|
||
JsonObject jsonObject = JsonFileReader.readJson(jsonFile); | ||
|
||
ArteCategoryFilmsDTO actual = target.deserialize(jsonObject, ArteCategoryFilmsDTO.class, null); | ||
|
||
assertThat(actual, notNullValue()); | ||
assertThat(actual.hasNextPage(), equalTo(expectedHasNextPage)); | ||
Set<String> actualProgramIds = actual.getProgramIds(); | ||
assertThat(actualProgramIds, Matchers.containsInAnyOrder(expectedProgramIds)); | ||
assertThat(actual.getNextPageUrl(), equalTo(expectedNextPageUrl)); | ||
} | ||
} |
Oops, something went wrong.