3232
3333import 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
4247public 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