X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Ftriggers%2FNewEpisodeTrigger.java;h=075c6f6a998c71ea06070bbc7720de572096f390;hb=5253e286451ddd50cc5f94654f0e8d04322846cf;hp=f3aee94649bad172516d4b4a18ba25bd9365d920;hpb=4d8b603aea34464189cfeca62cb80f69ef9012fb;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 f3aee94..075c6f6 100644 --- a/src/main/java/net/pterodactylus/rhynodge/triggers/NewEpisodeTrigger.java +++ b/src/main/java/net/pterodactylus/rhynodge/triggers/NewEpisodeTrigger.java @@ -89,15 +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(); + int oldSize = existingEpisode.torrentFiles().size(); + existingEpisode.addTorrentFile(torrentFile); + int newSize = existingEpisode.torrentFiles().size(); if (oldSize != newSize) { newTorrentFiles.add(torrentFile); } - if (!newEpisodes.contains(episode) && (oldSize != newSize)) { - changedEpisodes.add(episode); + if (!newEpisodes.contains(existingEpisode) && (oldSize != newSize)) { + changedEpisodes.add(existingEpisode); } } } @@ -129,8 +130,8 @@ 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; } @@ -143,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"); @@ -212,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(); }