Make loading of resolution more robust

The loading of the reosultion might fail, if the URL in StreamInfo is
outdated. Remove StreamInfo from cache in that case and retry.
This commit is contained in:
0xboobface 2018-10-03 15:03:54 +02:00
parent 0e41599ecb
commit 866e73ccff
1 changed files with 35 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package ctbrec; package ctbrec;
import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -118,6 +119,15 @@ public class Model {
return Chaturbate.INSTANCE.getResolution(getName()); return Chaturbate.INSTANCE.getResolution(getName());
} }
/**
* Invalidates the entries in StreamInfo and resolution cache for this model
* and thus causes causes the LoadingCache to update them
*/
public void invalidateCacheEntries() {
Chaturbate.INSTANCE.streamInfoCache.invalidate(getName());
Chaturbate.INSTANCE.streamResolutionCache.invalidate(getName());
}
public String getOnlineState() throws IOException, ExecutionException { public String getOnlineState() throws IOException, ExecutionException {
return getOnlineState(false); return getOnlineState(false);
} }
@ -251,6 +261,9 @@ public class Model {
return res; return res;
} }
EOFException ex = null;
for(int i=0; i<2; i++) {
try {
MasterPlaylist master = getMasterPlaylist(modelName); MasterPlaylist master = getMasterPlaylist(modelName);
for (PlaylistData playlistData : master.getPlaylists()) { for (PlaylistData playlistData : master.getPlaylists()) {
if(playlistData.hasStreamInfo() && playlistData.getStreamInfo().hasResolution()) { if(playlistData.hasStreamInfo() && playlistData.getStreamInfo().hasResolution()) {
@ -262,6 +275,20 @@ public class Model {
} }
} }
} }
ex = null;
break; // this attempt worked, exit loop
} catch(EOFException e) {
// the cause might be, that the playlist url in streaminfo is outdated,
// so let's remove it from cache and retry in the next iteration
streamInfoCache.invalidate(modelName);
ex = e;
}
}
if(ex != null) {
throw ex;
}
streamResolutionCache.put(modelName, res); streamResolutionCache.put(modelName, res);
return res; return res;
} }