|
28 | 28 | import java.nio.charset.StandardCharsets; |
29 | 29 | import java.security.MessageDigest; |
30 | 30 | import java.util.ArrayList; |
| 31 | +import java.util.HashMap; |
| 32 | +import java.util.Map; |
31 | 33 |
|
32 | 34 | public final class SponsorBlockUtils { |
33 | 35 | private static final Application APP = App.getApp(); |
34 | 36 | private static final String TAG = SponsorBlockUtils.class.getSimpleName(); |
35 | 37 | private static final boolean DEBUG = MainActivity.DEBUG; |
| 38 | + private static Map<String, VideoSegment[]> videoSegmentsCache = new HashMap<>(); |
36 | 39 |
|
37 | 40 | private SponsorBlockUtils() { |
38 | 41 | } |
@@ -120,6 +123,11 @@ public static VideoSegment[] getYouTubeVideoSegments(final Context context, |
120 | 123 | final String params = "skipSegments/" + videoIdHash.substring(0, 4) |
121 | 124 | + "?categories=" + categoryParams; |
122 | 125 |
|
| 126 | + final VideoSegment[] alreadyFetchedVideoSegments = videoSegmentsCache.get(params); |
| 127 | + if (alreadyFetchedVideoSegments != null) { |
| 128 | + return alreadyFetchedVideoSegments; |
| 129 | + } |
| 130 | + |
123 | 131 | if (!isConnected()) { |
124 | 132 | return null; |
125 | 133 | } |
@@ -177,8 +185,9 @@ public static VideoSegment[] getYouTubeVideoSegments(final Context context, |
177 | 185 | result.add(segment); |
178 | 186 | } |
179 | 187 | } |
180 | | - |
181 | | - return result.toArray(new VideoSegment[0]); |
| 188 | + final VideoSegment[] segments = result.toArray(new VideoSegment[0]); |
| 189 | + videoSegmentsCache.put(params, segments); |
| 190 | + return segments; |
182 | 191 | } |
183 | 192 |
|
184 | 193 | private static boolean isConnected() { |
|
0 commit comments