| 17 | import java.util.Map; |
| 18 | |
| 19 | public class XtreamCode extends Spider { |
| 20 | |
| 21 | private List<Group> groups; |
| 22 | private Config config; |
| 23 | |
| 24 | @Override |
| 25 | public void init(Context context, String extend) { |
| 26 | config = Config.objectFrom(extend); |
| 27 | groups = new ArrayList<>(); |
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | public String liveContent(String url) { |
| 32 | config.setUrl(url); |
| 33 | setChannel(); |
| 34 | setNumber(); |
| 35 | return new Gson().toJson(groups); |
| 36 | } |
| 37 | |
| 38 | private void setChannel() { |
| 39 | List<XCategory> categoryList = getCategoryList(config); |
| 40 | List<XStream> streamList = getStreamList(config); |
| 41 | Map<String, String> categoryMap = new HashMap<>(); |
| 42 | for (XCategory category : categoryList) { |
| 43 | categoryMap.put(category.getCategoryId(), category.getCategoryName()); |
| 44 | } |
| 45 | for (XStream stream : streamList) { |
| 46 | if (!categoryMap.containsKey(stream.getCategoryId())) continue; |
| 47 | Group group = Group.find(groups, Group.create(categoryMap.get(stream.getCategoryId()))); |
| 48 | Channel channel = group.find(Channel.create(stream.getName())); |
| 49 | if (!stream.getStreamIcon().isEmpty()) channel.setLogo(stream.getStreamIcon()); |
| 50 | if (!stream.getEpgChannelId().isEmpty()) channel.setTvgName(stream.getEpgChannelId()); |
| 51 | channel.getUrls().addAll(stream.getPlayUrl(config)); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | private void setNumber() { |
| 56 | int number = 0; |
| 57 | for (Group group : groups) { |
| 58 | for (Channel channel : group.getChannel()) { |
| 59 | if (channel.getNumber().isEmpty()) channel.setNumber(++number); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | private String getApiUrl(Config config, String action) { |
| 65 | return config.getUrl().newBuilder().addQueryParameter("action", action).build().toString(); |
| 66 | } |
| 67 | |
| 68 | private List<XCategory> getLiveCategoryList(Config config) { |
| 69 | return XCategory.arrayFrom(OkHttp.string(getApiUrl(config, "get_live_categories"))); |
| 70 | } |
| 71 | |
| 72 | private List<XStream> getLiveStreamList(Config config) { |
| 73 | return XStream.arrayFrom(OkHttp.string(getApiUrl(config, "get_live_streams"))); |
| 74 | } |
| 75 | |
| 76 | private List<XCategory> getVodCategoryList(Config config) { |
nothing calls this directly
no outgoing calls
no test coverage detected