diff --git a/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java b/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java index b04bc4d58..b00d8c39f 100644 --- a/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java +++ b/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java @@ -28,9 +28,8 @@ public ArteCategoryFilmsDTO deserialize(JsonElement aJsonElement, Type aType, Js String programId = jsonElement.getAsJsonObject().get(JSON_ELEMENT_PROGRAMID).getAsString(); if (programId != null) { if (programId.startsWith("RC-")) { - // add 1 to collection id to get list of episodes try { - long collectionId = Long.parseLong(programId.replace("RC-", "")) + 1; + long collectionId = Long.parseLong(programId.replace("RC-", "")); dto.addCollection(String.format("RC-%06d", collectionId)); } catch (NumberFormatException e) { Log.errorLog(12834939, "Invalid collection id: " + programId); diff --git a/src/main/java/mServer/crawler/sender/arte/ArteCollectionDeserializer.java b/src/main/java/mServer/crawler/sender/arte/ArteCollectionChildDeserializer.java similarity index 94% rename from src/main/java/mServer/crawler/sender/arte/ArteCollectionDeserializer.java rename to src/main/java/mServer/crawler/sender/arte/ArteCollectionChildDeserializer.java index f1302c848..f659d3768 100644 --- a/src/main/java/mServer/crawler/sender/arte/ArteCollectionDeserializer.java +++ b/src/main/java/mServer/crawler/sender/arte/ArteCollectionChildDeserializer.java @@ -5,7 +5,7 @@ import java.lang.reflect.Type; -public class ArteCollectionDeserializer implements JsonDeserializer { +public class ArteCollectionChildDeserializer implements JsonDeserializer { private static final String ATTRIBUTE_PROGRAM_ID = "programId"; private static final String ELEMENT_PROGRAMS = "programs"; private static final String ELEMENT_VIDEOS = "videos"; diff --git a/src/main/java/mServer/crawler/sender/arte/ArteCollectionParentDeserializer.java b/src/main/java/mServer/crawler/sender/arte/ArteCollectionParentDeserializer.java new file mode 100644 index 000000000..ef5dfc917 --- /dev/null +++ b/src/main/java/mServer/crawler/sender/arte/ArteCollectionParentDeserializer.java @@ -0,0 +1,41 @@ +package mServer.crawler.sender.arte; + + +import com.google.gson.*; +import mServer.crawler.sender.base.JsonUtils; + +import java.lang.reflect.Type; +import java.util.Optional; + +public class ArteCollectionParentDeserializer implements JsonDeserializer { + private static final String ATTRIBUTE_KIND = "kind"; + private static final String ATTRIBUTE_PROGRAM_ID = "programId"; + private static final String ELEMENT_PROGRAMS = "programs"; + private static final String ELEMENT_CHILDREN = "children"; + + public ArteCategoryFilmsDTO deserialize(final JsonElement aJsonElement, final Type aType, final JsonDeserializationContext aJsonDeserializationContext) throws JsonParseException { + final ArteCategoryFilmsDTO result = new ArteCategoryFilmsDTO(); + if (aJsonElement.isJsonObject()) { + final JsonObject mainObj = aJsonElement.getAsJsonObject(); + + if (JsonUtils.checkTreePath(mainObj, ELEMENT_PROGRAMS)) { + final JsonArray programs = mainObj.get(ELEMENT_PROGRAMS).getAsJsonArray(); + programs.forEach(program -> { + final JsonObject programObject = program.getAsJsonObject(); + if (JsonUtils.checkTreePath(programObject, ELEMENT_CHILDREN)) { + programObject.get(ELEMENT_CHILDREN).getAsJsonArray().forEach(filmElement -> { + final JsonObject filmObject = filmElement.getAsJsonObject(); + final Optional kind = JsonUtils.getAttributeAsString(filmObject, ATTRIBUTE_KIND); + final Optional programId = JsonUtils.getAttributeAsString(filmObject, ATTRIBUTE_PROGRAM_ID); + + if (kind.isPresent() && kind.get().equalsIgnoreCase("TV_SERIES") && programId.isPresent()) { + result.addCollection(programId.get()); + } + }); + } + }); + } + } + return result; + } +} diff --git a/src/main/java/mServer/crawler/sender/arte/MediathekArte.java b/src/main/java/mServer/crawler/sender/arte/MediathekArte.java index ef98ebc09..8a8101237 100644 --- a/src/main/java/mServer/crawler/sender/arte/MediathekArte.java +++ b/src/main/java/mServer/crawler/sender/arte/MediathekArte.java @@ -225,15 +225,18 @@ private void loadSubCategory(String sender, String langCode, String aCategory, S Gson gson = new GsonBuilder() .registerTypeAdapter(ArteCategoryFilmsDTO.class, new ArteCategoryFilmListDeserializer()) .create(); - Gson gsonCollection = new GsonBuilder() - .registerTypeAdapter(ArteCategoryFilmsDTO.class, new ArteCollectionDeserializer()) + Gson gsonCollectionParent = new GsonBuilder() + .registerTypeAdapter(ArteCategoryFilmsDTO.class, new ArteCollectionParentDeserializer()) + .create(); + Gson gsonCollectionChild = new GsonBuilder() + .registerTypeAdapter(ArteCategoryFilmsDTO.class, new ArteCollectionChildDeserializer()) .create(); // erste Seite laden int i = 2; ArteCategoryFilmsDTO dto = loadSubCategoryPage(gson, sender, aUrl); if (dto != null) { - loadCollections(sender, langCode, gsonCollection, dto); + loadCollections(sender, langCode, gsonCollectionParent, gsonCollectionChild, dto); ArteCategoryFilmsDTO nextDto = dto; while (PARSE_SUBCATEGORY_SUB_PAGES && nextDto != null && nextDto.hasNextPage()) { @@ -242,7 +245,7 @@ private void loadSubCategory(String sender, String langCode, String aCategory, S String url = String.format(URL_SUBCATEGORY, langCode.toLowerCase(), aCategory, i); nextDto = loadSubCategoryPage(gson, sender, url); if (nextDto != null) { - loadCollections(sender, langCode, gsonCollection, nextDto); + loadCollections(sender, langCode, gsonCollectionParent, gsonCollectionChild, nextDto); nextDto.getProgramIds().forEach(programId -> dto.addProgramId(programId)); } @@ -256,13 +259,19 @@ private void loadSubCategory(String sender, String langCode, String aCategory, S } } - private void loadCollections(String sender, String langCode, Gson gson, ArteCategoryFilmsDTO dto) { + private void loadCollections(String sender, String langCode, Gson gsonParent, Gson gsonChild, ArteCategoryFilmsDTO dto) { dto.getCollectionIds().forEach(collectionId -> { final String url = String.format(COLLECTION_URL, langCode, collectionId); try { - final ArteCategoryFilmsDTO collectionDto = ArteHttpClient.executeRequest(sender, LOG, gson, url, ArteCategoryFilmsDTO.class); - if (collectionDto != null) { - collectionDto.getProgramIds().forEach(dto::addProgramId); + final ArteCategoryFilmsDTO parentDto = ArteHttpClient.executeRequest(sender, LOG, gsonParent, url, ArteCategoryFilmsDTO.class); + if (parentDto != null) { + parentDto.getCollectionIds().forEach(childCollectionId -> { + final String urlChild = String.format(COLLECTION_URL, langCode, childCollectionId); + final ArteCategoryFilmsDTO collectionDto = ArteHttpClient.executeRequest(sender, LOG, gsonChild, urlChild, ArteCategoryFilmsDTO.class); + if (collectionDto != null) { + collectionDto.getProgramIds().forEach(dto::addProgramId); + } + }); } } catch (Exception e) { Log.errorLog(894330855, e, url);