Added the number of lines the importer just added to our database
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
2f5195ad0a
commit
af35537353
@ -5,6 +5,7 @@ import com.github.wtekiela.opensub4j.response.ResponseStatus;
|
|||||||
import com.github.wtekiela.opensub4j.response.SubtitleFile;
|
import com.github.wtekiela.opensub4j.response.SubtitleFile;
|
||||||
import com.github.wtekiela.opensub4j.response.SubtitleInfo;
|
import com.github.wtekiela.opensub4j.response.SubtitleInfo;
|
||||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||||
|
import discord4j.core.spec.EmbedCreateSpec;
|
||||||
import discord4j.rest.util.Color;
|
import discord4j.rest.util.Color;
|
||||||
import org.apache.xmlrpc.XmlRpcException;
|
import org.apache.xmlrpc.XmlRpcException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -52,7 +53,19 @@ public class Download extends Command {
|
|||||||
else if (SubtitleManager.getSubtitlesId(movie, languageId) > 0)
|
else if (SubtitleManager.getSubtitlesId(movie, languageId) > 0)
|
||||||
embed.setDescription("This movie already has already this language imported.")
|
embed.setDescription("This movie already has already this language imported.")
|
||||||
.setColor(Color.ORANGE);
|
.setColor(Color.ORANGE);
|
||||||
else {
|
else
|
||||||
|
computeImportation(event, args, languageId, embed, movie);
|
||||||
|
} catch (XmlRpcException | IOException e) {
|
||||||
|
logger.error("An error occurred while fetching the data from opensubtitles: {}", e.getMessage());
|
||||||
|
embed.setDescription("An error occurred, please contact my administrator.");
|
||||||
|
}
|
||||||
|
embed.setTimestamp(Instant.now());
|
||||||
|
}
|
||||||
|
))).then(event.getMessage().removeSelfReaction(WAITING)).then();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void computeImportation(MessageCreateEvent event, List<String> args,
|
||||||
|
int languageId, EmbedCreateSpec embed, Movie movie) throws XmlRpcException {
|
||||||
Stream<SubtitleInfo> subtitleInfoStream = OpenSubtitles.getSubtitleStreamFromMovie(movie);
|
Stream<SubtitleInfo> subtitleInfoStream = OpenSubtitles.getSubtitleStreamFromMovie(movie);
|
||||||
Optional<SubtitleInfo> subtitleInfo = subtitleInfoStream == null ? Optional.empty() :
|
Optional<SubtitleInfo> subtitleInfo = subtitleInfoStream == null ? Optional.empty() :
|
||||||
subtitleInfoStream.filter(info ->
|
subtitleInfoStream.filter(info ->
|
||||||
@ -71,18 +84,11 @@ public class Download extends Command {
|
|||||||
event.getMember().isPresent() ? event.getMessage().getId() : null);
|
event.getMember().isPresent() ? event.getMessage().getId() : null);
|
||||||
embed.setColor(Color.MEDIUM_SEA_GREEN).setDescription("Everything went well. " +
|
embed.setColor(Color.MEDIUM_SEA_GREEN).setDescription("Everything went well. " +
|
||||||
"Congratulations and thank you for your contribution!");
|
"Congratulations and thank you for your contribution!");
|
||||||
|
embed.addField("You imported", blocks.size() + " lines into my database", false);
|
||||||
} else {
|
} else {
|
||||||
logger.error("Could not download subtitle '{}': {}", args.get(0), subs.getStatus());
|
logger.error("Could not download subtitle '{}': {}", args.get(0), subs.getStatus());
|
||||||
embed.setDescription("An error occurred. Please contact my administrator.");
|
embed.setDescription("An error occurred. Please contact my administrator.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (XmlRpcException | IOException e) {
|
|
||||||
logger.error("An error occurred while fetching the data from opensubtitles: {}", e.getMessage());
|
|
||||||
embed.setDescription("An error occurred, please contact my administrator.");
|
|
||||||
}
|
|
||||||
embed.setTimestamp(Instant.now());
|
|
||||||
}
|
|
||||||
))).then(event.getMessage().removeSelfReaction(WAITING)).then();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user