import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import javax.net.ssl.*;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.text.NumberFormat;
class main {
static boolean cereproc_printPageLoads = false;
static File cereproc_silent(String voice, String text) {
text = cereproc_preprocess(text);
return cereproc_silent_preprocessed(voice, text);
}
static File cereproc_silent_preprocessed(String voice, String text) {
File file = cereproc_file(voice, text);
if (!file.exists()) {
Object anim = miniLoadingAnim("Speaking...");
try {
String url = getSoundURLCereproc(text, voice);
if (cereproc_printPageLoads)
print("CEREPROC: " + text);
//saveBinaryFile(file, loadBinaryPageSilently(url));
loadBinaryPageToFile(url, file);
if (cereproc_printPageLoads)
print("CEREPROC DONE");
} finally {
disposeWindow(anim);
}
}
return file;
}
static String cereproc_preprocess(String text) {
text = trim(text);
if (empty(text)) return null;
text = text.replaceAll("\\s+", " ");
String text2 = shorten(text, 1000);
if (neq(text, text2)) print("Cereproc: Text shortened from " + l(text) + " to " + l(text2) + " chars");
return text2;
}
static File cereproc_file(String voice, String text) {
text = cereproc_preprocess(text);
//print("[" + voice + "] " + text);
String text2 = text;
if (l(text2) >= 100) text2 = shorten(text, 100) + "-" + md5(text);
return prepareCacheProgramFile("#1004759", voice + "/" + urlencodeForFileName(text2) + ".mp3");
}
static JWindow miniLoadingAnim(String text) {
return miniLoadingAnim(); // text is ignored
}
static JWindow miniLoadingAnim() {
return showAnimationInTopRightCorner("#1009613");
}
static String getSoundURLCereproc(String text, String voice) {
return getSoundURLCereproc_raw(htmlencode(text), voice);
}
static String getSoundURLCereproc_raw(String text, String voice) { try {
String format = "mp3";
String post = "" + htmlencode(voice) + "" + text + "" + format + "\n" +
"";
String url = "https://www.cereproc.com/livedemo.php";
URL _url = new URL(url);
URLConnection conn = _url.openConnection();
conn.setRequestProperty("Content-Type", "text/plain;charset=UTF-8");
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
conn.setRequestProperty("Accept-Language", "en-US,en;q=0.8,de;q=0.6");
conn.setRequestProperty("Cookie", "has_js=1; _ga=GA1.2.1903717829.1455235694; Drupal.visitor.liveDemo=2k4fhzwgr8eka9k9");
conn.setRequestProperty("Origin", "https://www.cereproc.com");
conn.setRequestProperty("Referer", "https://www.cereproc.com/");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36");
conn.setDoOutput(true);
//OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
writer.write(post);
writer.flush();
String encoding = conn.getContentEncoding();
//print("Encoding: " + encoding);
String contentType = conn.getContentType();
//print("Content type: " + contentType);
byte[] response = loadBinaryPage(conn);
//print("Bytes read: " + response.length);
if ("gzip".equals(encoding))
response = gunzipBinaryData(response);
//print("Bytes unpacked: " + response.length);
String s = new String(response, "UTF-8");
//print(s);
String oggUrl = null;
List tok = htmlcoarsetok(s);
for (int i = 1; i < tok.size(); i += 2)
if (isTag(tok.get(i), "url")) {
oggUrl = tok.get(i+1);
break;
}
if (oggUrl == null) throw fail("No sound URL found");
return oggUrl;
} catch (Exception __e) { throw rethrow(__e); } }
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal