@Override public String getChannels(String serverUrl, boolean premium) throws ClientProtocolException, UnsupportedEncodingException, IOException { String playLIst = null; CloseableHttpClient httpClient = HttpClientBuilder.create().build(); // CloseableHttpClient httpClient = HttpClients.custom().setRoutePlanner(routePlanner).build(); HttpResponse login = httpClient.execute(getVideoStarLogin()); EntityUtils.consume(login.getEntity()); if (login.getStatusLine().getStatusCode() == 302) { HttpResponse getChannel = httpClient.execute(getChannelsRequest(login)); if (getChannel.getStatusLine().getStatusCode() == 200) { VideoStarChannelRequest channels = jsonService.parseVideoStarChannels(EntityUtils.toString(getChannel.getEntity())); if (channels != null && channels.getStatus().equals("ok")) { return prepareChannelList(channels, serverUrl, premium); // return channelsString; } else if (channels != null && channels.getStatus().equals("error")) { // TODO } else { // TODO } } } return playLIst; }
public String prepareChannelList( VideoStarChannelRequest channels, String serverUrl, boolean premium) { if (channels.getChannels() != null && channels.getChannels().size() > 0) { StringBuilder m3u8 = new StringBuilder("#EXTM3U\n"); int counter = 1; for (VideoStarSingleChannel singleChannel : channels.getChannels()) { if (singleChannel.getAccess_status().equals("free")) { addSingleChannel(m3u8, singleChannel, counter, serverUrl); } else if (premium) { addSingleChannel(m3u8, singleChannel, counter, serverUrl); } } return m3u8.toString(); } return null; }