Skip to content

Commit 5b53c1f

Browse files
committed
Fix LanguageEnumBuilder and update languages
1 parent ce09fd1 commit 5b53c1f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/main/java/org/eu/zajc/akiwrapper/Akiwrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public enum Language {
8585
PORTUGESE("pt", Theme.CHARACTER),
8686
RUSSIAN("ru", Theme.CHARACTER),
8787
TURKISH("tr", Theme.CHARACTER),
88-
INDONESIAN("id", Theme.CHARACTER);
88+
INDONESIAN("id", Theme.CHARACTER),
89+
VIETNAMESE("vi", Theme.CHARACTER);
8990

9091
@Nonnull private final String languageCode;
9192
@Nonnull private final Set<Theme> supportedThemes;

src/main/java/org/eu/zajc/akiwrapper/core/utils/LanguageEnumBuilder.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@
3232

3333
import javax.annotation.*;
3434

35+
import org.eu.zajc.akiwrapper.Akiwrapper.Language;
36+
3537
/**
3638
* <b>Note:</b> This is an internal class and its internals are subject to change
3739
* without prior deprecation. Use with caution.<br>
40+
* <br>
41+
* A manual utility for language enum generation. The result is to be placed into
42+
* {@link Language}.
3843
*
3944
* @author Marko Zajc
4045
*/
4146
@SuppressWarnings("javadoc") // internal
4247
public class LanguageEnumBuilder {
4348

44-
private static final Pattern LANGUAGE_REGEX = compile(".*changeLocale\\(\\&\\#39\\;([^\\)]+)\\&\\#39\\;\\)");
45-
private static final Pattern THEME_REGEX = compile(".*chooseTheme\\(\\&\\#39\\;(\\d+)\\&\\#39\\;\\)");
49+
private static final Pattern LANGUAGE_REGEX = compile(".*changeLocale\\('([^\\)]+)'\\)");
50+
private static final Pattern THEME_REGEX = compile(".*chooseTheme\\('(\\d+)'\\)");
4651

4752
@Nullable
4853
private static String getGuessType(int code) {
@@ -97,6 +102,8 @@ private static String getLanguageName(String code) {
97102
return "Turkish";
98103
case "id":
99104
return "Indonesian";
105+
case "vi":
106+
return "Vietnamese";
100107
default:
101108
return "Unknown";
102109
}
@@ -107,7 +114,9 @@ private static String getLanguageName(String code) {
107114
private static String get(@Nonnull String format, @Nonnull Object... args) {
108115
try {
109116
return HttpClient.newHttpClient()
110-
.send(HttpRequest.newBuilder(new URI(format(format, args))).build(), BodyHandlers.ofString())
117+
.send(HttpRequest.newBuilder(new URI(format(format, args)))
118+
.header("user-agent", "Mozilla/5.0 (X11; Linux x86_64; rv:137.0) Gecko/20100101 Firefox/137.0")
119+
.build(), BodyHandlers.ofString())
111120
.body();
112121
} catch (IOException | URISyntaxException e) {
113122
throw new RuntimeException(e);
@@ -121,7 +130,7 @@ private static String get(@Nonnull String format, @Nonnull Object... args) {
121130
@SuppressWarnings({ "resource", "null" })
122131
private static Stream<String> getGuessTypes(String language) {
123132
return concat(Stream.of("CHARACTER"),
124-
new Scanner(get("https://%s.akinator.com/theme_selection", language)).findAll(THEME_REGEX)
133+
new Scanner(get("https://%s.akinator.com/theme-selection", language)).findAll(THEME_REGEX)
125134
.map(m -> m.group(1))
126135
.mapToInt(Integer::parseInt)
127136
.mapToObj(LanguageEnumBuilder::getGuessType)

0 commit comments

Comments
 (0)