forked from j62/ctbrec
Fix Camsoda recordings (thx @Ban)
Applied the patch from @Ban to fix Camsoda recordings
This commit is contained in:
parent
9cb96f97b8
commit
947994f524
|
@ -1,35 +1,10 @@
|
||||||
package ctbrec.sites.camsoda;
|
package ctbrec.sites.camsoda;
|
||||||
|
|
||||||
import static ctbrec.Model.State.*;
|
import com.iheartradio.m3u8.*;
|
||||||
import static ctbrec.io.HttpConstants.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.iheartradio.m3u8.Encoding;
|
|
||||||
import com.iheartradio.m3u8.Format;
|
|
||||||
import com.iheartradio.m3u8.ParseException;
|
|
||||||
import com.iheartradio.m3u8.ParsingMode;
|
|
||||||
import com.iheartradio.m3u8.PlaylistException;
|
|
||||||
import com.iheartradio.m3u8.PlaylistParser;
|
|
||||||
import com.iheartradio.m3u8.data.MasterPlaylist;
|
import com.iheartradio.m3u8.data.MasterPlaylist;
|
||||||
import com.iheartradio.m3u8.data.Playlist;
|
import com.iheartradio.m3u8.data.Playlist;
|
||||||
import com.iheartradio.m3u8.data.PlaylistData;
|
import com.iheartradio.m3u8.data.PlaylistData;
|
||||||
import com.iheartradio.m3u8.data.StreamInfo;
|
import com.iheartradio.m3u8.data.StreamInfo;
|
||||||
|
|
||||||
import ctbrec.AbstractModel;
|
import ctbrec.AbstractModel;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
|
@ -38,6 +13,18 @@ import okhttp3.FormBody;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import static ctbrec.Model.State.*;
|
||||||
|
import static ctbrec.io.HttpConstants.*;
|
||||||
|
|
||||||
public class CamsodaModel extends AbstractModel {
|
public class CamsodaModel extends AbstractModel {
|
||||||
|
|
||||||
|
@ -50,7 +37,7 @@ public class CamsodaModel extends AbstractModel {
|
||||||
private transient String gender;
|
private transient String gender;
|
||||||
|
|
||||||
private float sortOrder = 0;
|
private float sortOrder = 0;
|
||||||
private Random random = new Random();
|
private final Random random = new Random();
|
||||||
int[] resolution = new int[2];
|
int[] resolution = new int[2];
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,8 +64,7 @@ public class CamsodaModel extends AbstractModel {
|
||||||
StringBuilder url = new StringBuilder("https://");
|
StringBuilder url = new StringBuilder("https://");
|
||||||
url.append(edgeServer).append('/');
|
url.append(edgeServer).append('/');
|
||||||
url.append(streamName);
|
url.append(streamName);
|
||||||
url.append("_h264_aac");
|
url.append("_v1");
|
||||||
url.append(streamName.contains("-flu") ? "_720p" : "_480p");
|
|
||||||
url.append("/index.m3u8");
|
url.append("/index.m3u8");
|
||||||
if (!isPublic(streamName)) {
|
if (!isPublic(streamName)) {
|
||||||
url.append("?token=").append(token);
|
url.append("?token=").append(token);
|
||||||
|
@ -131,7 +117,8 @@ public class CamsodaModel extends AbstractModel {
|
||||||
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
||||||
Playlist playlist = parser.parse();
|
Playlist playlist = parser.parse();
|
||||||
MasterPlaylist master = playlist.getMasterPlaylist();
|
MasterPlaylist master = playlist.getMasterPlaylist();
|
||||||
PlaylistData playlistData = master.getPlaylists().get(0);
|
streamSources = new ArrayList<>();
|
||||||
|
for (PlaylistData playlistData : master.getPlaylists()) {
|
||||||
StreamSource streamsource = new StreamSource();
|
StreamSource streamsource = new StreamSource();
|
||||||
int cutOffAt = Math.max(playlistUrl.indexOf("index.m3u8"), playlistUrl.indexOf("playlist.m3u8"));
|
int cutOffAt = Math.max(playlistUrl.indexOf("index.m3u8"), playlistUrl.indexOf("playlist.m3u8"));
|
||||||
String segmentPlaylistUrl = playlistUrl.substring(0, cutOffAt) + playlistData.getUri();
|
String segmentPlaylistUrl = playlistUrl.substring(0, cutOffAt) + playlistData.getUri();
|
||||||
|
@ -146,8 +133,8 @@ public class CamsodaModel extends AbstractModel {
|
||||||
streamsource.width = 0;
|
streamsource.width = 0;
|
||||||
streamsource.height = 0;
|
streamsource.height = 0;
|
||||||
}
|
}
|
||||||
streamSources = new ArrayList<>();
|
|
||||||
streamSources.add(streamsource);
|
streamSources.add(streamsource);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.trace("Response: {}", response.body().string());
|
LOG.trace("Response: {}", response.body().string());
|
||||||
throw new HttpException(playlistUrl, response.code(), response.message());
|
throw new HttpException(playlistUrl, response.code(), response.message());
|
||||||
|
@ -184,31 +171,22 @@ public class CamsodaModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnlineStateByStatus(String status) {
|
public void setOnlineStateByStatus(String status) {
|
||||||
switch(status) {
|
switch (status) {
|
||||||
case "online":
|
case "online" -> onlineState = ONLINE;
|
||||||
onlineState = ONLINE;
|
case "offline" -> onlineState = OFFLINE;
|
||||||
break;
|
case "connected" -> onlineState = AWAY;
|
||||||
case "offline":
|
case "private" -> onlineState = PRIVATE;
|
||||||
onlineState = OFFLINE;
|
case "limited" -> onlineState = GROUP;
|
||||||
break;
|
default -> {
|
||||||
case "connected":
|
|
||||||
onlineState = AWAY;
|
|
||||||
break;
|
|
||||||
case "private":
|
|
||||||
onlineState = PRIVATE;
|
|
||||||
break;
|
|
||||||
case "limited":
|
|
||||||
onlineState = GROUP;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG.debug("Unknown show type {}", status);
|
LOG.debug("Unknown show type {}", status);
|
||||||
onlineState = UNKNOWN;
|
onlineState = UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
||||||
if(ignoreCache || onlineState == UNKNOWN) {
|
if (ignoreCache || onlineState == UNKNOWN) {
|
||||||
loadModel();
|
loadModel();
|
||||||
}
|
}
|
||||||
return onlineState == ONLINE;
|
return onlineState == ONLINE;
|
||||||
|
@ -216,10 +194,10 @@ public class CamsodaModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
|
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
|
||||||
if(failFast) {
|
if (failFast) {
|
||||||
return onlineState;
|
return onlineState;
|
||||||
} else {
|
} else {
|
||||||
if(onlineState == UNKNOWN) {
|
if (onlineState == UNKNOWN) {
|
||||||
loadModel();
|
loadModel();
|
||||||
}
|
}
|
||||||
return onlineState;
|
return onlineState;
|
||||||
|
@ -239,10 +217,10 @@ public class CamsodaModel extends AbstractModel {
|
||||||
try {
|
try {
|
||||||
List<StreamSource> sources = getStreamSources();
|
List<StreamSource> sources = getStreamSources();
|
||||||
if (sources.isEmpty()) {
|
if (sources.isEmpty()) {
|
||||||
return new int[] { 0, 0 };
|
return new int[]{0, 0};
|
||||||
} else {
|
} else {
|
||||||
StreamSource src = sources.get(0);
|
StreamSource src = sources.get(0);
|
||||||
resolution = new int[] { src.width, src.height };
|
resolution = new int[]{src.width, src.height};
|
||||||
return resolution;
|
return resolution;
|
||||||
}
|
}
|
||||||
} catch (IOException | ParseException | PlaylistException e) {
|
} catch (IOException | ParseException | PlaylistException e) {
|
||||||
|
@ -282,7 +260,7 @@ public class CamsodaModel extends AbstractModel {
|
||||||
public boolean follow() throws IOException {
|
public boolean follow() throws IOException {
|
||||||
String url = Camsoda.BASE_URI + "/api/v1/follow/" + getName();
|
String url = Camsoda.BASE_URI + "/api/v1/follow/" + getName();
|
||||||
LOG.debug("Sending follow request {}", url);
|
LOG.debug("Sending follow request {}", url);
|
||||||
String csrfToken = ((CamsodaHttpClient)site.getHttpClient()).getCsrfToken();
|
String csrfToken = ((CamsodaHttpClient) site.getHttpClient()).getCsrfToken();
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(RequestBody.create(new byte[0]))
|
.post(RequestBody.create(new byte[0]))
|
||||||
|
@ -305,7 +283,7 @@ public class CamsodaModel extends AbstractModel {
|
||||||
public boolean unfollow() throws IOException {
|
public boolean unfollow() throws IOException {
|
||||||
String url = Camsoda.BASE_URI + "/api/v1/unfollow/" + getName();
|
String url = Camsoda.BASE_URI + "/api/v1/unfollow/" + getName();
|
||||||
LOG.debug("Sending unfollow request {}", url);
|
LOG.debug("Sending unfollow request {}", url);
|
||||||
String csrfToken = ((CamsodaHttpClient)site.getHttpClient()).getCsrfToken();
|
String csrfToken = ((CamsodaHttpClient) site.getHttpClient()).getCsrfToken();
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(RequestBody.create(new byte[0]))
|
.post(RequestBody.create(new byte[0]))
|
||||||
|
|
Loading…
Reference in New Issue