X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Ftriggers%2FNewEpisodeTrigger.java;h=4d9786806a3964b409ccf68f50a85125d9c34798;hb=22e98b8896aa47b397ba89d887bfdbe212850517;hp=5f095603eab212611102db38ce6941b99a0a150c;hpb=6de37ebbf253a84d904d85cad2760dc71b9be913;p=rhynodge.git diff --git a/src/main/java/net/pterodactylus/rhynodge/triggers/NewEpisodeTrigger.java b/src/main/java/net/pterodactylus/rhynodge/triggers/NewEpisodeTrigger.java index 5f09560..4d97868 100644 --- a/src/main/java/net/pterodactylus/rhynodge/triggers/NewEpisodeTrigger.java +++ b/src/main/java/net/pterodactylus/rhynodge/triggers/NewEpisodeTrigger.java @@ -130,13 +130,13 @@ public class NewEpisodeTrigger implements Trigger { summary = String.format("%d changed Torrent(s) for “%s!”", changedEpisodes.size(), reaction.name()); } DefaultOutput output = new DefaultOutput(summary); - output.addText("text/plain", generatePlainText(reaction, newEpisodes, changedEpisodes, allEpisodes)); - output.addText("text/html", generateHtmlText(reaction, newEpisodes, changedEpisodes, allEpisodes)); + output.addText("text/plain", generatePlainText(reaction)); + output.addText("text/html", generateHtmlText(reaction)); return output; } // - // STATIC METHODS + // PRIVATE METHODS // /** @@ -144,15 +144,9 @@ public class NewEpisodeTrigger implements Trigger { * * @param reaction * The reaction that was triggered - * @param newEpisodes - * The new episodes - * @param changedEpisodes - * The changed episodes - * @param allEpisodes - * All episodes * @return The plain text output */ - private static String generatePlainText(Reaction reaction, Collection newEpisodes, Collection changedEpisodes, Collection allEpisodes) { + private String generatePlainText(Reaction reaction) { StringBuilder stringBuilder = new StringBuilder(); if (!newEpisodes.isEmpty()) { stringBuilder.append(reaction.name()).append(" - New Episodes\n\n"); @@ -213,70 +207,57 @@ public class NewEpisodeTrigger implements Trigger { * * @param reaction * The reaction that was triggered - * @param newEpisodes - * The new episodes - * @param changedEpisodes - * The changed episodes - * @param allEpisodes - * All episodes * @return The HTML output */ - private static String generateHtmlText(Reaction reaction, Collection newEpisodes, Collection changedEpisodes, Collection allEpisodes) { + private String generateHtmlText(Reaction reaction) { StringBuilder htmlBuilder = new StringBuilder(); htmlBuilder.append("\n"); - htmlBuilder.append("

").append(StringEscapeUtils.escapeHtml4(reaction.name())).append("

\n"); - if (!newEpisodes.isEmpty()) { - htmlBuilder.append("

New Episodes

\n"); - htmlBuilder.append("
    \n"); - for (Episode episode : newEpisodes) { - htmlBuilder.append("
  • Season ").append(episode.season()).append(", Episode ").append(episode.episode()).append("
  • \n"); - htmlBuilder.append("
      \n"); - for (TorrentFile torrentFile : episode) { - htmlBuilder.append("
    • ").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append("
    • \n"); - htmlBuilder.append("
      "); - htmlBuilder.append("").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append(", "); - htmlBuilder.append("").append(torrentFile.fileCount()).append(" file(s), "); - htmlBuilder.append("").append(torrentFile.seedCount()).append(" seed(s), "); - htmlBuilder.append("").append(torrentFile.leechCount()).append(" leecher(s)
      \n"); - htmlBuilder.append("
      "); - if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) { - htmlBuilder.append("Magnet "); - } - if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) { - htmlBuilder.append("Download"); - } - htmlBuilder.append("
      \n"); - } - htmlBuilder.append("
    \n"); - } - htmlBuilder.append("
\n"); - } - if (!changedEpisodes.isEmpty()) { - htmlBuilder.append("

Changed Episodes

\n"); - htmlBuilder.append("
    \n"); - for (Episode episode : changedEpisodes) { - htmlBuilder.append("
  • Season ").append(episode.season()).append(", Episode ").append(episode.episode()).append("
  • \n"); - htmlBuilder.append("
      \n"); + /* show all known episodes. */ + htmlBuilder.append("\n\n"); + htmlBuilder.append("\n"); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append("\n"); + htmlBuilder.append("\n"); + htmlBuilder.append("\n"); + Episode lastEpisode = null; + for (Entry> seasonEntry : FluentIterable.from(Ordering.natural().reverse().sortedCopy(allEpisodes)).index(Episode.BY_SEASON).asMap().entrySet()) { + for (Episode episode : seasonEntry.getValue()) { for (TorrentFile torrentFile : episode) { - htmlBuilder.append("
    • ").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append("
    • \n"); - htmlBuilder.append("
      "); - htmlBuilder.append("").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append(", "); - htmlBuilder.append("").append(torrentFile.fileCount()).append(" file(s), "); - htmlBuilder.append("").append(torrentFile.seedCount()).append(" seed(s), "); - htmlBuilder.append("").append(torrentFile.leechCount()).append(" leecher(s)
      \n"); - htmlBuilder.append("
      "); - if ((torrentFile.magnetUri() != null) && (torrentFile.magnetUri().length() > 0)) { - htmlBuilder.append("Magnet "); + if (newEpisodes.contains(episode)) { + htmlBuilder.append("
      "); + } else if (newTorrentFiles.contains(torrentFile)) { + htmlBuilder.append(""); + } else { + htmlBuilder.append(""); } - if ((torrentFile.downloadUri() != null) && (torrentFile.downloadUri().length() > 0)) { - htmlBuilder.append("Download"); + if ((lastEpisode == null) || !lastEpisode.equals(episode)) { + htmlBuilder.append(""); + } else { + htmlBuilder.append(""); } - htmlBuilder.append("\n"); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append(""); + htmlBuilder.append("\n"); + lastEpisode = episode; } - htmlBuilder.append("\n"); } - htmlBuilder.append("\n"); } + htmlBuilder.append("\n"); + htmlBuilder.append("
      All Known Episodes
      SeasonEpisodeFilenameSizeFile(s)SeedsLeechersMagnetDownload
      ").append(episode.season()).append("").append(episode.episode()).append("").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append("").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append("").append(torrentFile.fileCount()).append("").append(torrentFile.seedCount()).append("").append(torrentFile.leechCount()).append("LinkLink
      \n"); htmlBuilder.append("\n"); return htmlBuilder.toString(); }