+ String gamePage = request(gameUrl);
+ String pgn = regex(
+ gamePage,
+ getSettings().getGameUrlRegex()
+ );
+ if (pgn == null) {
+ pgn = regex(
+ gamePage,
+ getSettings().getGameJsonUrlRegex()
+ );
+ if (pgn == null) {
+ throw new ChessHogScannerException(
+ String.format("Failed to get source data for requesting URL: %s", gameUrl)
+ );
+ }
+ GameFormat gameFormat = Format.formatGame(pgn);
+ return new PGNGame(
+ gameFormat.id(),
+ gameFormat.pgn()
+ );
+ } else {
+ pgn = StringEscapeUtils.unescapeHtml4(pgn);
+ if (!isPgnFormat(pgn)) {
+ throw new ChessHogScannerException(
+ String.format("Failed to get PGN for requesting URL: %s", gameUrl)
+ );
+ }
+ return new PGNGame(
+ regex(pgn, getSettings().getGameIdRegex()),
+ pgn
+ );
+ }