Move getSegmentPlaylistUrl from AbstractModel to AbstractDownload
This commit is contained in:
parent
dbd5a42dbc
commit
97e2338cec
|
@ -2,17 +2,12 @@ package ctbrec;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import com.iheartradio.m3u8.ParseException;
|
||||
import com.iheartradio.m3u8.PlaylistException;
|
||||
import com.squareup.moshi.JsonReader;
|
||||
import com.squareup.moshi.JsonWriter;
|
||||
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
|
||||
public abstract class AbstractModel implements Model {
|
||||
|
||||
private String url;
|
||||
|
@ -87,19 +82,6 @@ public abstract class AbstractModel implements Model {
|
|||
this.streamUrlIndex = streamUrlIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSegmentPlaylistUrl() throws IOException, ExecutionException, ParseException, PlaylistException {
|
||||
List<StreamSource> streamSources = getStreamSources();
|
||||
String url = null;
|
||||
if(getStreamUrlIndex() >= 0 && getStreamUrlIndex() < streamSources.size()) {
|
||||
url = streamSources.get(getStreamUrlIndex()).getMediaPlaylistUrl();
|
||||
} else {
|
||||
Collections.sort(streamSources);
|
||||
url = streamSources.get(streamSources.size()-1).getMediaPlaylistUrl();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSiteSpecificData(JsonReader reader) throws IOException {
|
||||
// noop default implementation, can be overriden by concrete models
|
||||
|
|
|
@ -29,7 +29,6 @@ public interface Model {
|
|||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException;
|
||||
public String getOnlineState(boolean failFast) throws IOException, ExecutionException;
|
||||
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException;
|
||||
public String getSegmentPlaylistUrl() throws IOException, ExecutionException, ParseException, PlaylistException;
|
||||
public void invalidateCacheEntries();
|
||||
public void receiveTip(int tokens) throws IOException;
|
||||
public int[] getStreamResolution(boolean failFast) throws ExecutionException;
|
||||
|
|
|
@ -6,7 +6,9 @@ import java.io.InputStream;
|
|||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
@ -20,6 +22,7 @@ import com.iheartradio.m3u8.data.MediaPlaylist;
|
|||
import com.iheartradio.m3u8.data.Playlist;
|
||||
import com.iheartradio.m3u8.data.TrackData;
|
||||
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
@ -69,6 +72,19 @@ public abstract class AbstractHlsDownload implements Download {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
String getSegmentPlaylistUrl(Model model) throws IOException, ExecutionException, ParseException, PlaylistException {
|
||||
List<StreamSource> streamSources = model.getStreamSources();
|
||||
String url = null;
|
||||
if(model.getStreamUrlIndex() >= 0 && model.getStreamUrlIndex() < streamSources.size()) {
|
||||
url = streamSources.get(model.getStreamUrlIndex()).getMediaPlaylistUrl();
|
||||
} else {
|
||||
Collections.sort(streamSources);
|
||||
url = streamSources.get(streamSources.size()-1).getMediaPlaylistUrl();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
return alive;
|
||||
|
|
|
@ -48,7 +48,7 @@ public class HlsDownload extends AbstractHlsDownload {
|
|||
throw new IOException(model.getName() +"'s room is not public");
|
||||
}
|
||||
|
||||
String segments = model.getSegmentPlaylistUrl();
|
||||
String segments = getSegmentPlaylistUrl(model);
|
||||
if(segments != null) {
|
||||
if (!Files.exists(downloadDir, LinkOption.NOFOLLOW_LINKS)) {
|
||||
Files.createDirectories(downloadDir);
|
||||
|
|
|
@ -101,7 +101,7 @@ public class MergedHlsDownload extends AbstractHlsDownload {
|
|||
target = new File(targetFile.getAbsolutePath().replaceAll("\\.ts", "-00000.ts"));
|
||||
}
|
||||
|
||||
String segments = model.getSegmentPlaylistUrl();
|
||||
String segments = getSegmentPlaylistUrl(model);
|
||||
mergeThread = createMergeThread(target, null, true);
|
||||
mergeThread.start();
|
||||
if(segments != null) {
|
||||
|
|
Loading…
Reference in New Issue