Skip to content

Commit

Permalink
Merge pull request CatVodTVOfficial#47 from haha459862/main
Browse files Browse the repository at this point in the history
直播功能修改
  • Loading branch information
catvod authored Jun 25, 2022
2 parents a85ee4f + a78e2e4 commit a706ccc
Show file tree
Hide file tree
Showing 11 changed files with 426 additions and 208 deletions.
10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions .idea/runConfigurations.xml

This file was deleted.

78 changes: 48 additions & 30 deletions app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.github.catvod.crawler.JarLoader;
import com.github.catvod.crawler.Spider;
import com.github.tvbox.osc.bean.ChannelGroup;
import com.github.tvbox.osc.base.App;
import com.github.tvbox.osc.bean.IJKCode;
import com.github.tvbox.osc.bean.LiveChannel;
Expand All @@ -20,6 +21,7 @@
import com.github.tvbox.osc.util.HawkConfig;
import com.github.tvbox.osc.util.MD5;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.lzy.okgo.OkGo;
Expand Down Expand Up @@ -50,7 +52,7 @@ public class ApiConfig {
private List<SourceBean> sourceBeanList;
private SourceBean mHomeSource;
private ParseBean mDefaultParse;
private List<LiveChannel> channelList;
private List<ChannelGroup> channelGroupList;
private List<ParseBean> parseBeanList;
private List<String> vipParseFlags;
private List<IJKCode> ijkCodes;
Expand All @@ -63,7 +65,7 @@ public class ApiConfig {

private ApiConfig() {
sourceBeanList = new ArrayList<>();
channelList = new ArrayList<>();
channelGroupList = new ArrayList<>();
parseBeanList = new ArrayList<>();
}

Expand Down Expand Up @@ -274,34 +276,29 @@ private void parseJson(String apiUrl, String jsonStr) {
}
// 直播源
try {
int lcIdx = 0;
for (JsonElement opt : infoJson.get("lives").getAsJsonArray()) {
for (JsonElement optChl : ((JsonObject) opt).get("channels").getAsJsonArray()) {
JsonObject obj = (JsonObject) optChl;
LiveChannel lc = new LiveChannel();
lc.setName(obj.get("name").getAsString().trim());
ArrayList<String> urls = DefaultConfig.safeJsonStringList(obj, "urls");
if (urls.size() > 0) {
String url = urls.get(0);
if (url.startsWith("proxy://")) {
String fix = url.replace("proxy://", "http://0.0.0.0/?");
String extUrl = Uri.parse(fix).getQueryParameter("ext");
if (extUrl != null && !extUrl.isEmpty()) {
String extUrlFix = new String(Base64.decode(extUrl, Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8");
if (extUrlFix.startsWith("clan://")) {
extUrlFix = clanContentFix(clanToAddress(apiUrl), extUrlFix);
extUrlFix = Base64.encodeToString(extUrlFix.getBytes("UTF-8"), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP);
fix = url.replace(extUrl, extUrlFix);
urls.set(0, fix);
}
}
}
String lives = infoJson.get("lives").getAsJsonArray().toString();
int index = lives.indexOf("proxy://");
if (index != -1) {
int endIndex = lives.lastIndexOf("\"");
String url = lives.substring(index, endIndex);
url = DefaultConfig.checkReplaceProxy(url);

//clan
String extUrl = Uri.parse(url).getQueryParameter("ext");
if (extUrl != null && !extUrl.isEmpty()) {
String extUrlFix = new String(Base64.decode(extUrl, Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8");
if (extUrlFix.startsWith("clan://")) {
extUrlFix = clanContentFix(clanToAddress(apiUrl), extUrlFix);
extUrlFix = Base64.encodeToString(extUrlFix.getBytes("UTF-8"), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP);
url = url.replace(extUrl, extUrlFix);
}
lc.setUrls(urls);
// 暂时不考虑分组问题
lc.setChannelNum(lcIdx++);
channelList.add(lc);
}
ChannelGroup channelGroup = new ChannelGroup();
channelGroup.setGroupName(url);
channelGroupList.add(channelGroup);
}
else{
loadLives(infoJson.get("lives").getAsJsonArray());
}
} catch (Throwable th) {
th.printStackTrace();
Expand Down Expand Up @@ -341,6 +338,27 @@ private void parseJson(String apiUrl, String jsonStr) {
}
}

public void loadLives(JsonArray livesArray)
{
int groupIndex = 0;
int channelIndex = 0;
for (JsonElement groupElement : livesArray) {
ChannelGroup channelGroup = new ChannelGroup();
channelGroup.setGroupNum(groupIndex++);
channelGroup.setGroupName(((JsonObject) groupElement).get("Group").getAsString().trim());
for (JsonElement channelElement : ((JsonObject) groupElement).get("channels").getAsJsonArray()) {
JsonObject obj = (JsonObject) channelElement;
LiveChannel liveChannel = new LiveChannel();
liveChannel.setChannelName(obj.get("name").getAsString().trim());
liveChannel.setChannelNum(channelIndex++);
ArrayList<String> urls = DefaultConfig.safeJsonStringList(obj, "urls");
liveChannel.setUrls(urls);
channelGroup.getLiveChannels().add(liveChannel);
}
channelGroupList.add(channelGroup);
}
}

public String getSpider() {
return spider;
}
Expand Down Expand Up @@ -418,8 +436,8 @@ public SourceBean getHomeSourceBean() {
return mHomeSource == null ? emptyHome : mHomeSource;
}

public List<LiveChannel> getChannelList() {
return channelList;
public List<ChannelGroup> getChannelGroupList() {
return channelGroupList;
}

public List<IJKCode> getIjkCodes() {
Expand Down
49 changes: 49 additions & 0 deletions app/src/main/java/com/github/tvbox/osc/bean/ChannelGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.github.tvbox.osc.bean;

import java.util.ArrayList;

public class ChannelGroup {
/**
* num : 1
* name : 央视频道
* password : 频道密码
*/
private int groupNum;
private String groupName;
private String groupPassword;
private ArrayList<LiveChannel> liveChannels;
private boolean isDefault;


public int getGroupNum() {
return groupNum;
}

public void setGroupNum(int groupNum) {
this.groupNum = groupNum;
}

public String getGroupName() {
return groupName;
}

public void setGroupName(String groupName) {
this.groupName = groupName;
}

public ArrayList<LiveChannel> getLiveChannels() {
return liveChannels;
}

public void setLiveChannels(ArrayList<LiveChannel> liveChannels) {
this.liveChannels = liveChannels;
}

public boolean isDefault() {
return isDefault;
}

public void setDefault(boolean aDefault) {
isDefault = aDefault;
}
}
10 changes: 5 additions & 5 deletions app/src/main/java/com/github/tvbox/osc/bean/LiveChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LiveChannel {
*/

private int channelNum;
private String name;
private String channelName;
private ArrayList<String> urls;
private boolean isDefault;
public int sourceIdx = 0;
Expand All @@ -29,12 +29,12 @@ public int getChannelNum() {
return channelNum;
}

public void setName(String name) {
this.name = name;
public void setChannelName(String channelName) {
this.channelName = channelName;
}

public String getName() {
return name;
public String getChannelName() {
return channelName;
}

public String getUrls() {
Expand Down
Loading

0 comments on commit a706ccc

Please sign in to comment.