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=745a1f8db6082b1ed582f51816fac5d93b24c179;hpb=2043167af2768e03603504c94ca6550dd25d2560;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 745a1f8..4d97868 100644 --- a/src/main/java/net/pterodactylus/rhynodge/triggers/NewEpisodeTrigger.java +++ b/src/main/java/net/pterodactylus/rhynodge/triggers/NewEpisodeTrigger.java @@ -59,6 +59,8 @@ public class NewEpisodeTrigger implements Trigger { /** All changed episodes. */ private final Collection changedEpisodes = Sets.newHashSet(); + /** All new torrent files. */ + private final Collection newTorrentFiles = Sets.newHashSet(); // // TRIGGER METHODS @@ -74,6 +76,7 @@ public class NewEpisodeTrigger implements Trigger { newEpisodes.clear(); changedEpisodes.clear(); this.allEpisodes.clear(); + newTorrentFiles.clear(); Map allEpisodes = Maps.newHashMap(FluentIterable.from(((EpisodeState) previousState).episodes()).toMap(new Function() { @Override @@ -86,12 +89,16 @@ public class NewEpisodeTrigger implements Trigger { allEpisodes.put(episode, episode); newEpisodes.add(episode); } + Episode existingEpisode = allEpisodes.get(episode); for (TorrentFile torrentFile : Lists.newArrayList(episode.torrentFiles())) { - int oldSize = allEpisodes.get(episode).torrentFiles().size(); - allEpisodes.get(episode).addTorrentFile(torrentFile); - int newSize = allEpisodes.get(episode).torrentFiles().size(); - if (!newEpisodes.contains(episode) && (oldSize != newSize)) { - changedEpisodes.add(episode); + int oldSize = existingEpisode.torrentFiles().size(); + existingEpisode.addTorrentFile(torrentFile); + int newSize = existingEpisode.torrentFiles().size(); + if (oldSize != newSize) { + newTorrentFiles.add(torrentFile); + } + if (!newEpisodes.contains(existingEpisode) && (oldSize != newSize)) { + changedEpisodes.add(existingEpisode); } } } @@ -123,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 // /** @@ -137,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"); @@ -206,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"); + /* 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"); - } - 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"); - 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"); + 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(); }