Skip to content

Commit

Permalink
Merge pull request CatVodTVOfficial#127 from haha459862/main
Browse files Browse the repository at this point in the history
直播增加设置功能
  • Loading branch information
lite-cucumber authored Jul 7, 2022
2 parents 9e4a99d + 8024e5d commit 45daa84
Show file tree
Hide file tree
Showing 27 changed files with 1,796 additions and 1,337 deletions.
68 changes: 43 additions & 25 deletions app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.github.catvod.crawler.JarLoader;
import com.github.catvod.crawler.Spider;
import com.github.tvbox.osc.base.App;
import com.github.tvbox.osc.bean.ChannelGroup;
import com.github.tvbox.osc.bean.LiveChannelGroup;
import com.github.tvbox.osc.bean.IJKCode;
import com.github.tvbox.osc.bean.LiveChannel;
import com.github.tvbox.osc.bean.LiveChannelItem;
import com.github.tvbox.osc.bean.ParseBean;
import com.github.tvbox.osc.bean.SourceBean;
import com.github.tvbox.osc.server.ControlManager;
Expand Down Expand Up @@ -50,7 +50,7 @@ public class ApiConfig {
private LinkedHashMap<String, SourceBean> sourceBeanList;
private SourceBean mHomeSource;
private ParseBean mDefaultParse;
private List<ChannelGroup> channelGroupList;
private List<LiveChannelGroup> liveChannelGroupList;
private List<ParseBean> parseBeanList;
private List<String> vipParseFlags;
private List<IJKCode> ijkCodes;
Expand All @@ -63,7 +63,7 @@ public class ApiConfig {

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

Expand Down Expand Up @@ -279,7 +279,7 @@ private void parseJson(String apiUrl, String jsonStr) {
setDefaultParse(parseBeanList.get(0));
}
// 直播源
channelGroupList.clear(); //修复从后台切换重复加载频道列表
liveChannelGroupList.clear(); //修复从后台切换重复加载频道列表
try {
String lives = infoJson.get("lives").getAsJsonArray().toString();
int index = lives.indexOf("proxy://");
Expand All @@ -298,9 +298,9 @@ private void parseJson(String apiUrl, String jsonStr) {
url = url.replace(extUrl, extUrlFix);
}
}
ChannelGroup channelGroup = new ChannelGroup();
channelGroup.setGroupName(url);
channelGroupList.add(channelGroup);
LiveChannelGroup liveChannelGroup = new LiveChannelGroup();
liveChannelGroup.setGroupName(url);
liveChannelGroupList.add(liveChannelGroup);
} else {
loadLives(infoJson.get("lives").getAsJsonArray());
}
Expand Down Expand Up @@ -343,23 +343,46 @@ private void parseJson(String apiUrl, String jsonStr) {
}

public void loadLives(JsonArray livesArray) {
liveChannelGroupList.clear();
int groupIndex = 0;
int channelIndex = 0;
int channelNum = 0;
for (JsonElement groupElement : livesArray) {
ChannelGroup channelGroup = new ChannelGroup();
channelGroup.setLiveChannels(new ArrayList<LiveChannel>());
channelGroup.setGroupNum(groupIndex++);
channelGroup.setGroupName(((JsonObject) groupElement).get("group").getAsString().trim());
LiveChannelGroup liveChannelGroup = new LiveChannelGroup();
liveChannelGroup.setLiveChannels(new ArrayList<LiveChannelItem>());
liveChannelGroup.setGroupIndex(groupIndex++);
String groupName = ((JsonObject) groupElement).get("group").getAsString().trim();
String[] splitGroupName = groupName.split("_", 2);
liveChannelGroup.setGroupName(splitGroupName[0]);
if (splitGroupName.length > 1)
liveChannelGroup.setGroupPassword(splitGroupName[1]);
else
liveChannelGroup.setGroupPassword("");
channelIndex = 0;
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++);
LiveChannelItem liveChannelItem = new LiveChannelItem();
liveChannelItem.setChannelName(obj.get("name").getAsString().trim());
liveChannelItem.setChannelIndex(channelIndex++);
liveChannelItem.setChannelNum(++channelNum);
ArrayList<String> urls = DefaultConfig.safeJsonStringList(obj, "urls");
liveChannel.setChannelUrls(urls);
channelGroup.getLiveChannels().add(liveChannel);
ArrayList<String> sourceNames = new ArrayList<>();
ArrayList<String> sourceUrls = new ArrayList<>();
int sourceIndex = 1;
for (String url : urls) {
String[] splitText = url.split("\\$", 2);
sourceUrls.add(splitText[0]);
if (splitText.length > 1)
sourceNames.add(splitText[1]);
else
sourceNames.add("源" + Integer.toString(sourceIndex));
sourceIndex++;
}
liveChannelItem.setChannelSourceNames(sourceNames);
liveChannelItem.setChannelUrls(sourceUrls);
liveChannelGroup.getLiveChannels().add(liveChannelItem);
}
channelGroupList.add(channelGroup);
liveChannelGroupList.add(liveChannelGroup);
}
}

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

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

public void setChannelGroupList(List<ChannelGroup> list) {
channelGroupList.clear();
channelGroupList.addAll(list);
public List<LiveChannelGroup> getChannelGroupList() {
return liveChannelGroupList;
}

public List<IJKCode> getIjkCodes() {
Expand Down
58 changes: 0 additions & 58 deletions app/src/main/java/com/github/tvbox/osc/bean/ChannelGroup.java

This file was deleted.

47 changes: 47 additions & 0 deletions app/src/main/java/com/github/tvbox/osc/bean/LiveChannelGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.github.tvbox.osc.bean;

import java.util.ArrayList;

public class LiveChannelGroup {
/**
* groupIndex : 分组索引号
* groupName : 分组名称
* password : 分组密码
*/
private int groupIndex;
private String groupName;
private String groupPassword;
private ArrayList<LiveChannelItem> liveChannelItems;

public int getGroupIndex() {
return groupIndex;
}

public void setGroupIndex(int groupIndex) {
this.groupIndex = groupIndex;
}

public String getGroupName() {
return groupName;
}

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

public ArrayList<LiveChannelItem> getLiveChannels() {
return liveChannelItems;
}

public void setLiveChannels(ArrayList<LiveChannelItem> liveChannelItems) {
this.liveChannelItems = liveChannelItems;
}

public String getGroupPassword() {
return groupPassword;
}

public void setGroupPassword(String groupPassword) {
this.groupPassword = groupPassword;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,31 @@
* @date :2021/1/12
* @description:
*/
public class LiveChannel {
public class LiveChannelItem {
/**
* channelNum : 1
* channelName : CCTV-1 综合
* channelUrl : http://117.148.187.37/PLTV/88888888/224/3221226154/index.m3u8
* channelLogo : https://upload.wikimedia.org/wikipedia/zh/6/65/CCTV-1_Logo.png
* channelIndex : 频道索引号
* channelNum : 频道名称
* channelSourceNames : 频道源名称
* channelUrls : 频道源地址
* sourceIndex : 频道源索引
* sourceNum : 频道源总数
*/

private int channelIndex;
private int channelNum;
private String channelName;
private ArrayList<String> channelSourceNames;
private ArrayList<String> channelUrls;
private boolean isSelected = false;
private boolean isFocused = false;
public int sourceIndex = 0;
public int sourceNum = 0;

public void setChannelIndex(int channelIndex) {
this.channelIndex = channelIndex;
}

public int getChannelIndex() {
return channelIndex;
}

public void setChannelNum(int channelNum) {
this.channelNum = channelNum;
}
Expand All @@ -39,7 +48,9 @@ public String getChannelName() {
return channelName;
}

public ArrayList<String> getChannelUrls() { return channelUrls; }
public ArrayList<String> getChannelUrls() {
return channelUrls;
}

public void setChannelUrls(ArrayList<String> channelUrls) {
this.channelUrls = channelUrls;
Expand All @@ -54,6 +65,10 @@ public void nextSource() {
if (sourceIndex == sourceNum) sourceIndex = 0;
}

public void setSourceIndex(int sourceIndex) {
this.sourceIndex = sourceIndex;
}

public int getSourceIndex() {
return sourceIndex;
}
Expand All @@ -62,21 +77,19 @@ public String getUrl() {
return channelUrls.get(sourceIndex);
}

public boolean isSelected() {
return isSelected;
public int getSourceNum() {
return sourceNum;
}

public void setSelected(boolean b) {
isSelected = b;
public ArrayList<String> getChannelSourceNames() {
return channelSourceNames;
}

public int getSourceNum() { return sourceNum; }

public boolean isFocused() {
return isFocused;
public void setChannelSourceNames(ArrayList<String> channelSourceNames) {
this.channelSourceNames = channelSourceNames;
}

public void setFocused(boolean focused) {
isFocused = focused;
public String getSourceName() {
return channelSourceNames.get(sourceIndex);
}
}
Loading

0 comments on commit 45daa84

Please sign in to comment.