fix(comicvine): update Comicvine ID handling for issues and volumes in metadata extraction (#864)
This commit is contained in:
-66
@@ -1,66 +0,0 @@
|
|||||||
package org.booklore.model.dto.response.comicvineapi;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class ComicvineIssueResponse {
|
|
||||||
private String error;
|
|
||||||
private int limit;
|
|
||||||
private int offset;
|
|
||||||
private int number_of_page_results;
|
|
||||||
private int number_of_total_results;
|
|
||||||
private int status_code;
|
|
||||||
private IssueResults results;
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public static class IssueResults {
|
|
||||||
@JsonProperty("person_credits")
|
|
||||||
private List<Comic.PersonCredit> personCredits;
|
|
||||||
|
|
||||||
@JsonProperty("character_credits")
|
|
||||||
private List<Comic.CharacterCredit> characterCredits;
|
|
||||||
|
|
||||||
@JsonProperty("team_credits")
|
|
||||||
private List<Comic.TeamCredit> teamCredits;
|
|
||||||
|
|
||||||
@JsonProperty("story_arc_credits")
|
|
||||||
private List<Comic.StoryArcCredit> storyArcCredits;
|
|
||||||
|
|
||||||
@JsonProperty("location_credits")
|
|
||||||
private List<Comic.LocationCredit> locationCredits;
|
|
||||||
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
private String deck;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String aliases;
|
|
||||||
|
|
||||||
@JsonProperty("issue_number")
|
|
||||||
private String issueNumber;
|
|
||||||
|
|
||||||
@JsonProperty("cover_date")
|
|
||||||
private String coverDate;
|
|
||||||
|
|
||||||
@JsonProperty("store_date")
|
|
||||||
private String storeDate;
|
|
||||||
|
|
||||||
private Comic.Image image;
|
|
||||||
|
|
||||||
private Comic.Volume volume;
|
|
||||||
|
|
||||||
@JsonProperty("api_detail_url")
|
|
||||||
private String apiDetailUrl;
|
|
||||||
|
|
||||||
@JsonProperty("site_detail_url")
|
|
||||||
private String siteDetailUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package org.booklore.model.dto.response.comicvineapi;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class ComicvineSingleResponse {
|
||||||
|
private String error;
|
||||||
|
private int limit;
|
||||||
|
private int offset;
|
||||||
|
@JsonProperty("number_of_page_results")
|
||||||
|
private int numberOfPageResults;
|
||||||
|
@JsonProperty("number_of_total_results")
|
||||||
|
private int numberOfTotalResults;
|
||||||
|
@JsonProperty("status_code")
|
||||||
|
private int statusCode;
|
||||||
|
private Comic results;
|
||||||
|
private String version;
|
||||||
|
}
|
||||||
+8
-1
@@ -35,7 +35,8 @@ public class CbxMetadataExtractor implements FileMetadataExtractor {
|
|||||||
// URL Patterns
|
// URL Patterns
|
||||||
private static final Pattern GOODREADS_URL_PATTERN = Pattern.compile("goodreads\\.com/book/show/(\\d+)(?:-[\\w-]+)?");
|
private static final Pattern GOODREADS_URL_PATTERN = Pattern.compile("goodreads\\.com/book/show/(\\d+)(?:-[\\w-]+)?");
|
||||||
private static final Pattern AMAZON_URL_PATTERN = Pattern.compile("amazon\\.com/dp/([A-Z0-9]{10})");
|
private static final Pattern AMAZON_URL_PATTERN = Pattern.compile("amazon\\.com/dp/([A-Z0-9]{10})");
|
||||||
private static final Pattern COMICVINE_URL_PATTERN = Pattern.compile("comicvine\\.gamespot\\.com/issue/(?:[^/]+/)?([\\w-]+)");
|
private static final Pattern COMICVINE_URL_PATTERN = Pattern.compile("comicvine\\.gamespot\\.com/(?:issue|volume)/(?:[^/]+/)?(\\d+-\\d+)");
|
||||||
|
private static final Pattern COMICVINE_SITE_URL_PATTERN = Pattern.compile("comicvine\\.gamespot\\.com/(?:[^/]+/)?(40(?:00|50)-\\d+)/?");
|
||||||
private static final Pattern HARDCOVER_URL_PATTERN = Pattern.compile("hardcover\\.app/books/([\\w-]+)");
|
private static final Pattern HARDCOVER_URL_PATTERN = Pattern.compile("hardcover\\.app/books/([\\w-]+)");
|
||||||
|
|
||||||
private final ArchiveService archiveService;
|
private final ArchiveService archiveService;
|
||||||
@@ -317,6 +318,12 @@ public class CbxMetadataExtractor implements FileMetadataExtractor {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java.util.regex.Matcher cvSiteMatcher = COMICVINE_SITE_URL_PATTERN.matcher(url);
|
||||||
|
if (cvSiteMatcher.find()) {
|
||||||
|
builder.comicvineId(cvSiteMatcher.group(1));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
java.util.regex.Matcher hcMatcher = HARDCOVER_URL_PATTERN.matcher(url);
|
java.util.regex.Matcher hcMatcher = HARDCOVER_URL_PATTERN.matcher(url);
|
||||||
if (hcMatcher.find()) {
|
if (hcMatcher.find()) {
|
||||||
builder.hardcoverId(hcMatcher.group(1));
|
builder.hardcoverId(hcMatcher.group(1));
|
||||||
|
|||||||
+101
-49
@@ -8,7 +8,7 @@ import org.booklore.model.dto.ComicMetadata;
|
|||||||
import org.booklore.model.dto.request.FetchMetadataRequest;
|
import org.booklore.model.dto.request.FetchMetadataRequest;
|
||||||
import org.booklore.model.dto.response.comicvineapi.Comic;
|
import org.booklore.model.dto.response.comicvineapi.Comic;
|
||||||
import org.booklore.model.dto.response.comicvineapi.ComicvineApiResponse;
|
import org.booklore.model.dto.response.comicvineapi.ComicvineApiResponse;
|
||||||
import org.booklore.model.dto.response.comicvineapi.ComicvineIssueResponse;
|
import org.booklore.model.dto.response.comicvineapi.ComicvineSingleResponse;
|
||||||
import org.booklore.model.enums.MetadataProvider;
|
import org.booklore.model.enums.MetadataProvider;
|
||||||
import org.booklore.service.appsettings.AppSettingService;
|
import org.booklore.service.appsettings.AppSettingService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -25,6 +25,7 @@ import java.time.LocalDate;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.format.DateTimeParseException;
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -57,6 +58,18 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
private static final Pattern TRAILING_SLASHES_PATTERN = Pattern.compile("/+$");
|
private static final Pattern TRAILING_SLASHES_PATTERN = Pattern.compile("/+$");
|
||||||
private static final Pattern VOLUME_SUFFIX_PATTERN = Pattern.compile("\\s+Vol\\.?\\s*\\d+$");
|
private static final Pattern VOLUME_SUFFIX_PATTERN = Pattern.compile("\\s+Vol\\.?\\s*\\d+$");
|
||||||
|
|
||||||
|
private static final String RESOURCE_TYPE_ISSUE = "4000";
|
||||||
|
private static final String RESOURCE_TYPE_VOLUME = "4050";
|
||||||
|
private static final String PREFIX_ISSUE = RESOURCE_TYPE_ISSUE + "-";
|
||||||
|
private static final String PREFIX_VOLUME = RESOURCE_TYPE_VOLUME + "-";
|
||||||
|
|
||||||
|
private static final long CACHE_EXPIRATION_MS = 600_000; // 10 minutes
|
||||||
|
private static final int MAX_VOLUMES_TO_CHECK = 3;
|
||||||
|
private static final int SEARCH_LIMIT_DEFAULT = 25;
|
||||||
|
private static final int FILTER_LIMIT_DEFAULT = 20;
|
||||||
|
private static final int ISSUE_LIMIT_DEFAULT = 5;
|
||||||
|
private static final int GENERAL_SEARCH_LIMIT = 10;
|
||||||
|
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
private final AppSettingService appSettingService;
|
private final AppSettingService appSettingService;
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
@@ -65,7 +78,7 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
private final AtomicLong rateLimitResetTime = new AtomicLong(0);
|
private final AtomicLong rateLimitResetTime = new AtomicLong(0);
|
||||||
private final AtomicLong lastRequestTime = new AtomicLong(0);
|
private final AtomicLong lastRequestTime = new AtomicLong(0);
|
||||||
private final AtomicLong apiCallCounter = new AtomicLong(0);
|
private final AtomicLong apiCallCounter = new AtomicLong(0);
|
||||||
private final Map<String, CachedVolumes> volumeCache = new java.util.concurrent.ConcurrentHashMap<>();
|
private final Map<String, CachedVolumes> volumeCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private static class CachedVolumes {
|
private static class CachedVolumes {
|
||||||
final List<Comic> volumes;
|
final List<Comic> volumes;
|
||||||
@@ -77,7 +90,7 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isExpired() {
|
boolean isExpired() {
|
||||||
return System.currentTimeMillis() - timestamp > 600_000;
|
return System.currentTimeMillis() - timestamp > CACHE_EXPIRATION_MS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +118,9 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
if (metadataList.isEmpty()) return null;
|
if (metadataList.isEmpty()) return null;
|
||||||
|
|
||||||
BookMetadata top = metadataList.getFirst();
|
BookMetadata top = metadataList.getFirst();
|
||||||
if (top.getComicvineId() != null && (top.getComicMetadata() == null || !hasComicDetails(top.getComicMetadata()))) {
|
String topId = top.getComicvineId();
|
||||||
|
boolean isVolume = topId != null && topId.startsWith(PREFIX_VOLUME);
|
||||||
|
if (topId != null && !isVolume && (top.getComicMetadata() == null || !hasComicDetails(top.getComicMetadata()))) {
|
||||||
BookMetadata detailed = fetchDetailedMetadata(top.getComicvineId());
|
BookMetadata detailed = fetchDetailedMetadata(top.getComicvineId());
|
||||||
if (detailed != null && detailed.getComicMetadata() != null) {
|
if (detailed != null && detailed.getComicMetadata() != null) {
|
||||||
top.setComicMetadata(detailed.getComicMetadata());
|
top.setComicMetadata(detailed.getComicMetadata());
|
||||||
@@ -201,20 +216,27 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
final String finalSeriesName = seriesName;
|
final String finalSeriesName = seriesName;
|
||||||
log.debug("searchVolumesAndIssues: seriesName='{}', issueNumber='{}', year='{}'", finalSeriesName, issueNumber, extractedYear);
|
log.debug("searchVolumesAndIssues: seriesName='{}', issueNumber='{}', year='{}'", finalSeriesName, issueNumber, extractedYear);
|
||||||
|
|
||||||
List<Comic> volumes = searchVolumes(finalSeriesName);
|
// searchVolumes may return immutable snapshots (e.g. from cache). We wrap in a mutable
|
||||||
|
// ArrayList to enable in-place ranking/sorting to ensure the best matches are prioritized.
|
||||||
|
List<Comic> volumes = new ArrayList<>(searchVolumes(finalSeriesName));
|
||||||
if (volumes.isEmpty()) {
|
if (volumes.isEmpty()) {
|
||||||
log.debug("No volumes found for series '{}'", finalSeriesName);
|
log.debug("No volumes found for series '{}'", finalSeriesName);
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<Comic, Integer> originalIndex = new IdentityHashMap<>(volumes.size());
|
||||||
|
for (int idx = 0; idx < volumes.size(); idx++) {
|
||||||
|
originalIndex.put(volumes.get(idx), idx);
|
||||||
|
}
|
||||||
|
|
||||||
volumes.sort((v1, v2) -> {
|
volumes.sort((v1, v2) -> {
|
||||||
int score1 = calculateVolumeScore(v1, finalSeriesName, normalizedIssue, extractedYear);
|
int score1 = calculateVolumeScore(v1, finalSeriesName, normalizedIssue, extractedYear, originalIndex.get(v1));
|
||||||
int score2 = calculateVolumeScore(v2, finalSeriesName, normalizedIssue, extractedYear);
|
int score2 = calculateVolumeScore(v2, finalSeriesName, normalizedIssue, extractedYear, originalIndex.get(v2));
|
||||||
return Integer.compare(score2, score1);
|
return Integer.compare(score2, score1);
|
||||||
});
|
});
|
||||||
|
|
||||||
List<BookMetadata> results = new ArrayList<>();
|
List<BookMetadata> results = new ArrayList<>();
|
||||||
int limit = Math.min(volumes.size(), 3);
|
int limit = Math.min(volumes.size(), MAX_VOLUMES_TO_CHECK);
|
||||||
|
|
||||||
for (int i = 0; i < limit; i++) {
|
for (int i = 0; i < limit; i++) {
|
||||||
Comic volume = volumes.get(i);
|
Comic volume = volumes.get(i);
|
||||||
@@ -233,9 +255,12 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calculateVolumeScore(Comic volume, String seriesName, String normalizedIssue, Integer extractedYear) {
|
private int calculateVolumeScore(Comic volume, String seriesName, String normalizedIssue, Integer extractedYear, int originalIndex) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
|
|
||||||
|
// Relevance bonus from API search order
|
||||||
|
score += Math.max(0, 25 - originalIndex);
|
||||||
|
|
||||||
if (extractedYear != null && matchesYear(volume, extractedYear)) {
|
if (extractedYear != null && matchesYear(volume, extractedYear)) {
|
||||||
score += 100;
|
score += 100;
|
||||||
}
|
}
|
||||||
@@ -293,14 +318,15 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
String apiToken = getApiToken();
|
String apiToken = getApiToken();
|
||||||
if (apiToken == null) return Collections.emptyList();
|
if (apiToken == null) return Collections.emptyList();
|
||||||
|
|
||||||
|
log.debug("Searching for volumes via /search/ endpoint: '{}'", seriesName);
|
||||||
URI uri = UriComponentsBuilder.fromUriString(COMICVINE_URL)
|
URI uri = UriComponentsBuilder.fromUriString(COMICVINE_URL)
|
||||||
.path("/volumes/")
|
.path("/search/")
|
||||||
.queryParam("api_key", apiToken)
|
.queryParam("api_key", apiToken)
|
||||||
.queryParam("format", "json")
|
.queryParam("format", "json")
|
||||||
.queryParam("filter", "name:" + seriesName)
|
.queryParam("resources", "volume")
|
||||||
.queryParam("limit", 20)
|
.queryParam("query", seriesName)
|
||||||
|
.queryParam("limit", SEARCH_LIMIT_DEFAULT)
|
||||||
.queryParam("field_list", VOLUME_FIELDS)
|
.queryParam("field_list", VOLUME_FIELDS)
|
||||||
.queryParam("sort", "count_of_issues:desc")
|
|
||||||
.build()
|
.build()
|
||||||
.toUri();
|
.toUri();
|
||||||
|
|
||||||
@@ -308,12 +334,12 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
List<Comic> volumes = response != null && response.getResults() != null ? response.getResults() : Collections.emptyList();
|
List<Comic> volumes = response != null && response.getResults() != null ? response.getResults() : Collections.emptyList();
|
||||||
|
|
||||||
if (volumes.isEmpty()) {
|
if (volumes.isEmpty()) {
|
||||||
log.debug("No volumes found via /volumes filter, trying /search for '{}'", seriesName);
|
log.debug("No volumes found via /search/ endpoint, falling back to /volumes/ filter for '{}'", seriesName);
|
||||||
volumes = searchVolumesViaSearch(seriesName, apiToken);
|
volumes = searchVolumesViaFilter(seriesName, apiToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!volumes.isEmpty()) {
|
if (!volumes.isEmpty()) {
|
||||||
volumeCache.put(cacheKey, new CachedVolumes(volumes));
|
volumeCache.put(cacheKey, new CachedVolumes(List.copyOf(volumes)));
|
||||||
} else if (seriesName.contains(" - ")) {
|
} else if (seriesName.contains(" - ")) {
|
||||||
String alternativeName = seriesName.replace(" - ", ": ");
|
String alternativeName = seriesName.replace(" - ", ": ");
|
||||||
log.debug("No results for '{}', trying alternative name '{}'", seriesName, alternativeName);
|
log.debug("No results for '{}', trying alternative name '{}'", seriesName, alternativeName);
|
||||||
@@ -323,14 +349,13 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
return volumes;
|
return volumes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Comic> searchVolumesViaSearch(String seriesName, String apiToken) {
|
private List<Comic> searchVolumesViaFilter(String seriesName, String apiToken) {
|
||||||
URI uri = UriComponentsBuilder.fromUriString(COMICVINE_URL)
|
URI uri = UriComponentsBuilder.fromUriString(COMICVINE_URL)
|
||||||
.path("/search/")
|
.path("/volumes/")
|
||||||
.queryParam("api_key", apiToken)
|
.queryParam("api_key", apiToken)
|
||||||
.queryParam("format", "json")
|
.queryParam("format", "json")
|
||||||
.queryParam("resources", "volume")
|
.queryParam("filter", "name:" + seriesName)
|
||||||
.queryParam("query", seriesName)
|
.queryParam("limit", FILTER_LIMIT_DEFAULT)
|
||||||
.queryParam("limit", 10)
|
|
||||||
.queryParam("field_list", VOLUME_FIELDS)
|
.queryParam("field_list", VOLUME_FIELDS)
|
||||||
.build()
|
.build()
|
||||||
.toUri();
|
.toUri();
|
||||||
@@ -353,7 +378,7 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
.queryParam("format", "json")
|
.queryParam("format", "json")
|
||||||
.queryParam("filter", "volume:" + volume.getId() + ",issue_number:" + normalizedIssue)
|
.queryParam("filter", "volume:" + volume.getId() + ",issue_number:" + normalizedIssue)
|
||||||
.queryParam("field_list", ISSUE_LIST_FIELDS)
|
.queryParam("field_list", ISSUE_LIST_FIELDS)
|
||||||
.queryParam("limit", 5)
|
.queryParam("limit", ISSUE_LIMIT_DEFAULT)
|
||||||
.build()
|
.build()
|
||||||
.toUri();
|
.toUri();
|
||||||
|
|
||||||
@@ -384,7 +409,52 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BookMetadata fetchDetailedMetadata(String comicvineId) {
|
public BookMetadata fetchDetailedMetadata(String comicvineId) {
|
||||||
return fetchIssueDetails(Integer.parseInt(comicvineId), null);
|
if (comicvineId == null || comicvineId.isEmpty()) return null;
|
||||||
|
|
||||||
|
String prefix = RESOURCE_TYPE_ISSUE;
|
||||||
|
String idStr = comicvineId;
|
||||||
|
|
||||||
|
if (comicvineId.contains("-")) {
|
||||||
|
String[] parts = comicvineId.split("-", 2);
|
||||||
|
prefix = parts[0];
|
||||||
|
idStr = parts[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
int id;
|
||||||
|
try {
|
||||||
|
id = Integer.parseInt(idStr);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
log.warn("Invalid comicvineId format: {}", comicvineId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RESOURCE_TYPE_VOLUME.equals(prefix)) {
|
||||||
|
return fetchVolumeDetails(id);
|
||||||
|
} else if (RESOURCE_TYPE_ISSUE.equals(prefix)) {
|
||||||
|
return fetchIssueDetails(id, null);
|
||||||
|
} else {
|
||||||
|
log.warn("Unsupported Comicvine resource prefix '{}' for id '{}'", prefix, comicvineId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BookMetadata fetchVolumeDetails(int volumeId) {
|
||||||
|
String apiToken = getApiToken();
|
||||||
|
if (apiToken == null) return null;
|
||||||
|
|
||||||
|
URI uri = UriComponentsBuilder.fromUriString(COMICVINE_URL)
|
||||||
|
.path("/volume/{type}-{id}/")
|
||||||
|
.queryParam("api_key", apiToken)
|
||||||
|
.queryParam("format", "json")
|
||||||
|
.queryParam("field_list", VOLUME_FIELDS)
|
||||||
|
.buildAndExpand(RESOURCE_TYPE_VOLUME, volumeId)
|
||||||
|
.toUri();
|
||||||
|
|
||||||
|
ComicvineSingleResponse response = sendRequest(uri, ComicvineSingleResponse.class);
|
||||||
|
if (response != null && response.getResults() != null) {
|
||||||
|
return buildVolumeMetadata(response.getResults());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BookMetadata fetchIssueDetails(int issueId, Comic volumeContext) {
|
private BookMetadata fetchIssueDetails(int issueId, Comic volumeContext) {
|
||||||
@@ -392,16 +462,16 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
if (apiToken == null) return null;
|
if (apiToken == null) return null;
|
||||||
|
|
||||||
URI uri = UriComponentsBuilder.fromUriString(COMICVINE_URL)
|
URI uri = UriComponentsBuilder.fromUriString(COMICVINE_URL)
|
||||||
.path("/issue/4000-" + issueId + "/")
|
.path("/issue/{type}-{id}/")
|
||||||
.queryParam("api_key", apiToken)
|
.queryParam("api_key", apiToken)
|
||||||
.queryParam("format", "json")
|
.queryParam("format", "json")
|
||||||
.queryParam("field_list", ISSUE_DETAIL_FIELDS)
|
.queryParam("field_list", ISSUE_DETAIL_FIELDS)
|
||||||
.build()
|
.buildAndExpand(RESOURCE_TYPE_ISSUE, issueId)
|
||||||
.toUri();
|
.toUri();
|
||||||
|
|
||||||
ComicvineIssueResponse response = sendRequest(uri, ComicvineIssueResponse.class);
|
ComicvineSingleResponse response = sendRequest(uri, ComicvineSingleResponse.class);
|
||||||
if (response != null && response.getResults() != null) {
|
if (response != null && response.getResults() != null) {
|
||||||
return convertToBookMetadata(response.getResults(), issueId, volumeContext);
|
return convertToBookMetadata(response.getResults(), volumeContext);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -416,7 +486,7 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
.queryParam("format", "json")
|
.queryParam("format", "json")
|
||||||
.queryParam("resources", "volume,issue")
|
.queryParam("resources", "volume,issue")
|
||||||
.queryParam("query", term)
|
.queryParam("query", term)
|
||||||
.queryParam("limit", 10)
|
.queryParam("limit", GENERAL_SEARCH_LIMIT)
|
||||||
.queryParam("field_list", SEARCH_FIELDS)
|
.queryParam("field_list", SEARCH_FIELDS)
|
||||||
.build()
|
.build()
|
||||||
.toUri();
|
.toUri();
|
||||||
@@ -597,7 +667,7 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
|
|
||||||
BookMetadata metadata = BookMetadata.builder()
|
BookMetadata metadata = BookMetadata.builder()
|
||||||
.provider(MetadataProvider.Comicvine)
|
.provider(MetadataProvider.Comicvine)
|
||||||
.comicvineId(String.valueOf(comic.getId()))
|
.comicvineId(PREFIX_ISSUE + comic.getId())
|
||||||
.title(formattedTitle)
|
.title(formattedTitle)
|
||||||
.authors(authors)
|
.authors(authors)
|
||||||
.thumbnailUrl(comic.getImage() != null ? comic.getImage().getMediumUrl() : null)
|
.thumbnailUrl(comic.getImage() != null ? comic.getImage().getMediumUrl() : null)
|
||||||
@@ -626,7 +696,7 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
|
|
||||||
return BookMetadata.builder()
|
return BookMetadata.builder()
|
||||||
.provider(MetadataProvider.Comicvine)
|
.provider(MetadataProvider.Comicvine)
|
||||||
.comicvineId(String.valueOf(volume.getId()))
|
.comicvineId(PREFIX_VOLUME + volume.getId())
|
||||||
.title(volume.getName())
|
.title(volume.getName())
|
||||||
.seriesName(volume.getName())
|
.seriesName(volume.getName())
|
||||||
.seriesTotal(volume.getCountOfIssues())
|
.seriesTotal(volume.getCountOfIssues())
|
||||||
@@ -639,25 +709,7 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private BookMetadata convertToBookMetadata(ComicvineIssueResponse.IssueResults issue, int issueId, Comic volumeContext) {
|
|
||||||
Comic comic = new Comic();
|
|
||||||
comic.setId(issueId);
|
|
||||||
comic.setIssueNumber(issue.getIssueNumber());
|
|
||||||
comic.setVolume(issue.getVolume());
|
|
||||||
comic.setName(issue.getName());
|
|
||||||
comic.setPersonCredits(issue.getPersonCredits());
|
|
||||||
comic.setCharacterCredits(issue.getCharacterCredits());
|
|
||||||
comic.setTeamCredits(issue.getTeamCredits());
|
|
||||||
comic.setStoryArcCredits(issue.getStoryArcCredits());
|
|
||||||
comic.setLocationCredits(issue.getLocationCredits());
|
|
||||||
comic.setImage(issue.getImage());
|
|
||||||
comic.setDescription(issue.getDescription());
|
|
||||||
comic.setDeck(issue.getDeck());
|
|
||||||
comic.setStoreDate(issue.getStoreDate());
|
|
||||||
comic.setCoverDate(issue.getCoverDate());
|
|
||||||
comic.setSiteDetailUrl(issue.getSiteDetailUrl());
|
|
||||||
return convertToBookMetadata(comic, volumeContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasComicDetails(ComicMetadata comic) {
|
private boolean hasComicDetails(ComicMetadata comic) {
|
||||||
return hasNonEmptySet(comic.getCharacters())
|
return hasNonEmptySet(comic.getCharacters())
|
||||||
|
|||||||
@@ -226,7 +226,18 @@ public class CbxMetadataWriter implements MetadataWriter {
|
|||||||
if (metadata.getHardcoverBookId() != null && !metadata.getHardcoverBookId().isBlank()) {
|
if (metadata.getHardcoverBookId() != null && !metadata.getHardcoverBookId().isBlank()) {
|
||||||
primaryUrl = "https://hardcover.app/books/" + metadata.getHardcoverBookId();
|
primaryUrl = "https://hardcover.app/books/" + metadata.getHardcoverBookId();
|
||||||
} else if (metadata.getComicvineId() != null && !metadata.getComicvineId().isBlank()) {
|
} else if (metadata.getComicvineId() != null && !metadata.getComicvineId().isBlank()) {
|
||||||
primaryUrl = "https://comicvine.gamespot.com/issue/" + metadata.getComicvineId();
|
String cvId = metadata.getComicvineId();
|
||||||
|
if (cvId.startsWith("4050-")) {
|
||||||
|
primaryUrl = "https://comicvine.gamespot.com/volume/" + cvId + "/";
|
||||||
|
} else if (cvId.startsWith("4000-")) {
|
||||||
|
primaryUrl = "https://comicvine.gamespot.com/issue/" + cvId + "/";
|
||||||
|
} else if (cvId.matches("\\d+-\\d+")) {
|
||||||
|
// Already prefixed with some other Comicvine namespace; preserve as-is.
|
||||||
|
primaryUrl = "https://comicvine.gamespot.com/issue/" + cvId + "/";
|
||||||
|
} else {
|
||||||
|
// Legacy bare-numeric ID — assume issue.
|
||||||
|
primaryUrl = "https://comicvine.gamespot.com/issue/4000-" + cvId + "/";
|
||||||
|
}
|
||||||
} else if (metadata.getGoodreadsId() != null && !metadata.getGoodreadsId().isBlank()) {
|
} else if (metadata.getGoodreadsId() != null && !metadata.getGoodreadsId().isBlank()) {
|
||||||
primaryUrl = "https://www.goodreads.com/book/show/" + metadata.getGoodreadsId();
|
primaryUrl = "https://www.goodreads.com/book/show/" + metadata.getGoodreadsId();
|
||||||
} else if (metadata.getAsin() != null && !metadata.getAsin().isBlank()) {
|
} else if (metadata.getAsin() != null && !metadata.getAsin().isBlank()) {
|
||||||
|
|||||||
+11
-10
@@ -59,7 +59,7 @@ public class ComicvineBookParserTest {
|
|||||||
HttpResponse<String> response = getResponse(statusCode, payload);
|
HttpResponse<String> response = getResponse(statusCode, payload);
|
||||||
when(
|
when(
|
||||||
httpClient.<String>send(
|
httpClient.<String>send(
|
||||||
argThat(arg -> arg != null && arg.uri().toString().startsWith(("https://comicvine.gamespot.com/api" + uri))),
|
argThat(arg -> arg != null && arg.uri().toString().contains(uri)),
|
||||||
any()
|
any()
|
||||||
)
|
)
|
||||||
).thenReturn(response);
|
).thenReturn(response);
|
||||||
@@ -107,17 +107,11 @@ public class ComicvineBookParserTest {
|
|||||||
@Test
|
@Test
|
||||||
public void fetchTopMetadata_getsTitle() throws IOException, InterruptedException {
|
public void fetchTopMetadata_getsTitle() throws IOException, InterruptedException {
|
||||||
mockResponse(
|
mockResponse(
|
||||||
"/search/?api_key=example&format=json&resources=volume,issue&query=Example&",
|
"/search/",
|
||||||
200,
|
200,
|
||||||
readFixture("search.json")
|
readFixture("search.json")
|
||||||
);
|
);
|
||||||
|
|
||||||
mockResponse(
|
|
||||||
"/issue/4000-60593/",
|
|
||||||
200,
|
|
||||||
readFixture("issue.json")
|
|
||||||
);
|
|
||||||
|
|
||||||
Book book = getBook("EXAMPLE");
|
Book book = getBook("EXAMPLE");
|
||||||
FetchMetadataRequest request = FetchMetadataRequest.builder()
|
FetchMetadataRequest request = FetchMetadataRequest.builder()
|
||||||
.title("Example")
|
.title("Example")
|
||||||
@@ -131,14 +125,21 @@ public class ComicvineBookParserTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fetchTopMetadata_parsesSeriesInfoFromTitle() throws IOException, InterruptedException {
|
public void fetchTopMetadata_parsesSeriesInfoFromTitle() throws IOException, InterruptedException {
|
||||||
|
// The parser first tries /search/ endpoint for volumes
|
||||||
mockResponse(
|
mockResponse(
|
||||||
"/volumes/?api_key=example&format=json&filter=name:The%20Example&",
|
"/search/?api_key=example&format=json&resources=volume&query=The%20Example",
|
||||||
|
200,
|
||||||
|
"{\"results\": []}"
|
||||||
|
);
|
||||||
|
|
||||||
|
mockResponse(
|
||||||
|
"/volumes/?api_key=example&format=json&filter=name:The%20Example",
|
||||||
200,
|
200,
|
||||||
readFixture("search.json")
|
readFixture("search.json")
|
||||||
);
|
);
|
||||||
|
|
||||||
mockResponse(
|
mockResponse(
|
||||||
"/issues/?api_key=example&format=json&filter=volume:60593,issue_number:1&",
|
"/issues/?api_key=example&format=json&filter=volume:60593,issue_number:1",
|
||||||
200,
|
200,
|
||||||
readFixture("issues.json")
|
readFixture("issues.json")
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user