use of com.glitchcog.fontificator.emoji.EmojiOperation in project ChatGameFontificator by GlitchCog.
the class ConfigEmoji method setWorkCompleted.
/**
* Mark work as being completed by setting the loaded and cached member variables of this emoji config
*
* @param job
* Contains the type, op, and channel of the job completed
*/
public void setWorkCompleted(EmojiJob job) {
logger.trace(job.toString() + " completed");
final EmojiType emojiType = job.getType();
final EmojiOperation emojiOp = job.getOp();
if (EmojiType.TWITCH_BADGE.equals(emojiType)) {
this.twitchBadgesLoadedChannel = job.getChannel();
} else if (EmojiType.FRANKERFACEZ_BADGE.equals(emojiType)) {
this.ffzBadgesLoadedChannel = job.getChannel();
} else if (// This would also include TWITCH_BADGE, but it's already checked above
emojiType.isTwitchEmote()) {
if (EmojiOperation.LOAD == emojiOp) {
this.twitchLoaded = true;
} else if (EmojiOperation.CACHE == emojiOp) {
this.twitchCached = true;
}
} else if (emojiType.isFrankerFaceZEmote()) {
if (EmojiOperation.LOAD == emojiOp) {
if (emojiType == EmojiType.FRANKERFACEZ_CHANNEL) {
this.ffzLoadedChannel = job.getChannel();
} else if (emojiType == EmojiType.FRANKERFACEZ_GLOBAL) {
this.ffzGlobalLoaded = true;
}
} else if (EmojiOperation.CACHE == emojiOp) {
this.ffzCached = true;
}
} else if (emojiType.isBetterTtvEmote()) {
if (EmojiOperation.LOAD == emojiOp) {
if (emojiType == EmojiType.BETTER_TTV_CHANNEL) {
this.bttvLoadedChannel = job.getChannel();
} else if (emojiType == EmojiType.BETTER_TTV_GLOBAL) {
this.bttvGlobalLoaded = true;
}
} else if (EmojiOperation.CACHE == emojiOp) {
this.bttvCached = true;
}
}
}
use of com.glitchcog.fontificator.emoji.EmojiOperation in project ChatGameFontificator by GlitchCog.
the class EmojiWorker method doInBackground.
@Override
protected Integer doInBackground() throws Exception {
if (job.getType() == null || job.getOp() == null) {
return Integer.valueOf(1);
}
try {
terminateWork = false;
final EmojiOperation opType = job.getOp();
final EmojiType emojiType = job.getType();
final String channel = job.getChannel();
final String oauth = job.getOauth();
if (EmojiOperation.LOAD == opType) {
// Some custom loading required to get the set map from Twitch API, if it's Twitch V2/V3 emotes being loaded
String jsonSetMapData = null;
if (emojiType.isLoadSetMap()) {
loader.prepLoad(TWITCH_URL_EMOTE_ID_TO_SET_ID_MAP);
jsonSetMapData = runLoader(emojiType);
}
// The proper load for the emoji
loader.prepLoad(emojiType, channel, oauth);
String data = runLoader(emojiType);
if (data != null) {
parser.putJsonEmojiIntoManager(manager, emojiType, data, jsonSetMapData);
}
// Some custom loading required for custom FFZ moderator badges
if (emojiType == EmojiType.FRANKERFACEZ_BADGE) {
loader.prepLoad(FFZ_BASE_NO_EMOTES_URL + channel);
String ffzRoomJson = runLoader(emojiType);
parser.parseFrankerFaceZModBadge(manager, ffzRoomJson);
}
// Some custom loading required for the Twitch Prime badge
if (emojiType == EmojiType.TWITCH_BADGE) {
TypedEmojiMap tbMap = manager.getEmojiByType(EmojiType.TWITCH_BADGE);
tbMap.put("prime", new LazyLoadEmoji("prime", TWITCH_BADGE_PRIME, EmojiType.TWITCH_BADGE));
}
Thread.sleep(1L);
} else if (EmojiOperation.CACHE == opType) {
List<String> regexes;
List<Integer> ids;
if (emojiType.isTwitchEmote()) {
// This is for Twitch emote V2 or V3. It typically will be whichever is set as the default in the
// emoji control panel
regexes = new ArrayList<String>(TWITCH_EMOTES_BASIC.length + TWITCH_EMOTES_GLOBAL.length);
Collections.addAll(regexes, TWITCH_EMOTES_BASIC);
Collections.addAll(regexes, TWITCH_EMOTES_GLOBAL);
// This is for Twitch V1 emotes, done by ID. This is how Twitch emotes are actually used, so it
// should always be tripped
ids = new ArrayList<Integer>(TWITCH_EMOTE_IDS_BASIC.length + TWITCH_EMOTE_IDS_GLOBAL.length);
Collections.addAll(ids, TWITCH_EMOTE_IDS_BASIC);
Collections.addAll(ids, TWITCH_EMOTE_IDS_GLOBAL);
} else if (emojiType.isFrankerFaceZEmote()) {
Collection<String> ffzChannelRegexes = manager.getEmojiByType(EmojiType.FRANKERFACEZ_CHANNEL).keySet();
Collection<String> ffzGlobalRegexes = manager.getEmojiByType(EmojiType.FRANKERFACEZ_GLOBAL).keySet();
regexes = new ArrayList<String>(ffzChannelRegexes.size() + ffzGlobalRegexes.size());
regexes.addAll(ffzChannelRegexes);
regexes.addAll(ffzGlobalRegexes);
// Unused for FFZ
ids = new ArrayList<Integer>();
} else if (emojiType.isBetterTtvEmote()) {
Collection<String> bttvChannelRegexes = manager.getEmojiByType(EmojiType.BETTER_TTV_CHANNEL).keySet();
Collection<String> bttvGlobalRegexes = manager.getEmojiByType(EmojiType.BETTER_TTV_GLOBAL).keySet();
regexes = new ArrayList<String>(bttvChannelRegexes.size() + bttvGlobalRegexes.size());
regexes.addAll(bttvChannelRegexes);
regexes.addAll(bttvGlobalRegexes);
// Unused for BTTV
ids = new ArrayList<Integer>();
} else {
// Nothing to do
regexes = new ArrayList<String>();
ids = new ArrayList<Integer>();
}
publish(new EmojiWorkerReport("Caching " + emojiType.getDescription(), 0));
Thread.sleep(1L);
int count = 0;
List<LazyLoadEmoji> emojiToCache = new ArrayList<LazyLoadEmoji>();
for (String regex : regexes) {
LazyLoadEmoji emoji = manager.getEmoji(emojiType, regex, null);
emojiToCache.add(emoji);
}
for (Integer id : ids) {
LazyLoadEmoji emoji = manager.getEmojiById(id, null, null);
emojiToCache.add(emoji);
}
for (LazyLoadEmoji emoji : emojiToCache) {
if (emoji != null) {
emoji.cacheImage();
}
count++;
// This is safe from divide by zero exceptions, because we won't be here if emojiToCache is empty
int percentComplete = (int) (100.0f * count / emojiToCache.size());
publish(new EmojiWorkerReport("Caching " + emojiType.getDescription(), percentComplete));
if (terminateWork) {
throw new EmojiCancelException();
}
Thread.sleep(1L);
}
publish(new EmojiWorkerReport(emojiType.getDescription() + " caching complete", 100));
Thread.sleep(1L);
}
return Integer.valueOf(0);
} catch (EmojiHaltException e) {
// Don't let it get caught by the generic Exception, send it on up instead
publish(new EmojiWorkerReport(job.toString() + " halted", 100, false, false, true));
try {
Thread.sleep(1L);
} catch (Exception sleepException) {
logger.debug("Couldn't sleep for halt", sleepException);
}
throw e;
} catch (EmojiCancelException e) {
// Don't let it get caught by the generic Exception, send it on up instead
publish(new EmojiWorkerReport(job.toString() + " canceled", 100, false, true, false));
try {
Thread.sleep(1L);
} catch (Exception sleepException) {
logger.debug("Couldn't sleep for cancel", sleepException);
}
throw e;
} catch (FileNotFoundException e) {
publish(new EmojiWorkerReport("URL not found trying to " + job.toString(), 100, true, false, true));
Thread.sleep(1L);
return Integer.valueOf(2);
} catch (Exception e) {
e.printStackTrace();
final String errorMsg = "Unknown error trying to " + job.getOp().getDescription() + " " + job.getType().getDescription() + (job.getChannel() != null ? " for channel " + job.getChannel() : "");
publish(new EmojiWorkerReport(errorMsg, 100, true, false, true));
Thread.sleep(1L);
return Integer.valueOf(3);
}
}
Aggregations