forked from j62/ctbrec
1
0
Fork 0

Remove ordering by sequence

This was used for Chaturbate, because the filename format was known.
With several camsites the filename format can differ and this is not a
good solution anymore. Instead we now just sort filename. To make sure,
the files have the right order, HlsDownload now creates a prefix for
each segment.
This commit is contained in:
0xboobface 2018-12-14 23:53:10 +01:00
parent 1ce9a111a9
commit b2d1d41abc
2 changed files with 12 additions and 19 deletions

View File

@ -9,8 +9,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -48,10 +46,8 @@ public class PlaylistGenerator {
Arrays.sort(files, (f1, f2) -> {
String n1 = f1.getName();
int seq1 = getSequence(n1);
String n2 = f2.getName();
int seq2 = getSequence(n2);
return seq1 - seq2;
return n1.compareTo(n2);
});
// create a track containing all files
@ -102,16 +98,6 @@ public class PlaylistGenerator {
return output;
}
private int getSequence(String filename) {
filename = filename.substring(0, filename.lastIndexOf('.')); // cut off file suffix
Matcher matcher = Pattern.compile(".*?(\\d+)").matcher(filename);
if(matcher.matches()) {
return Integer.parseInt(matcher.group(1));
} else {
return -1;
}
}
private void updateProgressListeners(double percentage) {
int p = (int) (percentage*100);
if(p > lastPercentage) {

View File

@ -13,6 +13,8 @@ import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
@ -39,6 +41,9 @@ public class HlsDownload extends AbstractHlsDownload {
protected Path downloadDir;
private int segmentCounter = 1;
private NumberFormat nf = new DecimalFormat("000000");
public HlsDownload(HttpClient client) {
super(client);
}
@ -78,7 +83,8 @@ public class HlsDownload extends AbstractHlsDownload {
for (int i = nextSegment; i < lsp.seq; i++) {
URL segmentUrl = new URL(first.replaceAll(Integer.toString(seq), Integer.toString(i)));
LOG.debug("Reloading segment {} for model {}", i, model.getName());
downloadThreadPool.submit(new SegmentDownload(segmentUrl, downloadDir, client));
String prefix = nf.format(segmentCounter++);
downloadThreadPool.submit(new SegmentDownload(segmentUrl, downloadDir, client, prefix));
}
// TODO switch to a lower bitrate/resolution ?!?
}
@ -88,7 +94,8 @@ public class HlsDownload extends AbstractHlsDownload {
skip--;
} else {
URL segmentUrl = new URL(segment);
downloadThreadPool.submit(new SegmentDownload(segmentUrl, downloadDir, client));
String prefix = nf.format(segmentCounter++);
downloadThreadPool.submit(new SegmentDownload(segmentUrl, downloadDir, client, prefix));
//new SegmentDownload(segment, downloadDir).call();
}
}
@ -150,11 +157,11 @@ public class HlsDownload extends AbstractHlsDownload {
private Path file;
private HttpClient client;
public SegmentDownload(URL url, Path dir, HttpClient client) {
public SegmentDownload(URL url, Path dir, HttpClient client, String prefix) {
this.url = url;
this.client = client;
File path = new File(url.getPath());
file = FileSystems.getDefault().getPath(dir.toString(), path.getName());
file = FileSystems.getDefault().getPath(dir.toString(), prefix + '_' + path.getName());
}
@Override