mirror of https://github.com/FongMi/TV.git
parent
6319140b4d
commit
f9d413b42c
@ -1,85 +0,0 @@ |
||||
package com.fongmi.android.tv.api; |
||||
|
||||
import android.net.Uri; |
||||
|
||||
import com.fongmi.android.tv.bean.Live; |
||||
import com.fongmi.android.tv.bean.XCategory; |
||||
import com.fongmi.android.tv.bean.XInfo; |
||||
import com.fongmi.android.tv.bean.XStream; |
||||
import com.github.catvod.net.OkHttp; |
||||
|
||||
import java.util.List; |
||||
|
||||
import okhttp3.HttpUrl; |
||||
|
||||
public class XtreamParser { |
||||
|
||||
public static HttpUrl.Builder getBuilder(Live live) { |
||||
HttpUrl url = HttpUrl.parse(live.getUrl()); |
||||
return new HttpUrl.Builder().scheme(url.scheme()).host(url.host()).port(url.port()); |
||||
} |
||||
|
||||
public static boolean isVerify(Uri uri) { |
||||
return uri.getPath() != null && uri.getQueryParameter("username") != null && uri.getQueryParameter("password") != null && (uri.getPath().contains("player_api.php") || uri.getPath().contains("get.php")); |
||||
} |
||||
|
||||
public static boolean isApiUrl(String url) { |
||||
return isApiUrl(Uri.parse(url)); |
||||
} |
||||
|
||||
public static boolean isApiUrl(Uri uri) { |
||||
return uri.getPath() != null && uri.getQueryParameter("username") != null && uri.getQueryParameter("password") != null && uri.getPath().contains("player_api.php"); |
||||
} |
||||
|
||||
public static boolean isGetUrl(String url) { |
||||
return isGetUrl(Uri.parse(url)); |
||||
} |
||||
|
||||
public static boolean isGetUrl(Uri uri) { |
||||
return uri.getPath() != null && uri.getQueryParameter("username") != null && uri.getQueryParameter("password") != null && uri.getPath().contains("get.php"); |
||||
} |
||||
|
||||
public static String getEpgUrl(Live live) { |
||||
return getBuilder(live).addPathSegment("xmltv.php").addQueryParameter("username", live.getUsername()).addQueryParameter("password", live.getPassword()).build().toString(); |
||||
} |
||||
|
||||
public static String getApiUrl(Live live) { |
||||
return getBuilder(live).addPathSegment("player_api.php").addQueryParameter("username", live.getUsername()).addQueryParameter("password", live.getPassword()).build().toString(); |
||||
} |
||||
|
||||
public static String getApiUrl(Live live, String action) { |
||||
return getBuilder(live).addPathSegment("player_api.php").addQueryParameter("username", live.getUsername()).addQueryParameter("password", live.getPassword()).addQueryParameter("action", action).build().toString(); |
||||
} |
||||
|
||||
public static XInfo getInfo(Live live) { |
||||
return XInfo.objectFrom(OkHttp.string(getApiUrl(live))); |
||||
} |
||||
|
||||
public static List<XCategory> getLiveCategoryList(Live live) { |
||||
return XCategory.arrayFrom(OkHttp.string(getApiUrl(live, "get_live_categories"))); |
||||
} |
||||
|
||||
public static List<XStream> getLiveStreamList(Live live) { |
||||
return XStream.arrayFrom(OkHttp.string(getApiUrl(live, "get_live_streams"))); |
||||
} |
||||
|
||||
public static List<XCategory> getVodCategoryList(Live live) { |
||||
return XCategory.arrayFrom(OkHttp.string(getApiUrl(live, "get_vod_categories"))); |
||||
} |
||||
|
||||
public static List<XStream> getVodStreamList(Live live) { |
||||
return XStream.arrayFrom(OkHttp.string(getApiUrl(live, "get_vod_streams"))); |
||||
} |
||||
|
||||
public static List<XCategory> getCategoryList(Live live) { |
||||
List<XCategory> categoryList = XtreamParser.getLiveCategoryList(live); |
||||
categoryList.addAll(XtreamParser.getVodCategoryList(live)); |
||||
return categoryList; |
||||
} |
||||
|
||||
public static List<XStream> getStreamList(Live live) { |
||||
List<XStream> streamList = XtreamParser.getLiveStreamList(live); |
||||
streamList.addAll(XtreamParser.getVodStreamList(live)); |
||||
return streamList; |
||||
} |
||||
} |
||||
@ -1,33 +0,0 @@ |
||||
package com.fongmi.android.tv.bean; |
||||
|
||||
import android.text.TextUtils; |
||||
|
||||
import com.fongmi.android.tv.App; |
||||
import com.google.gson.annotations.SerializedName; |
||||
import com.google.gson.reflect.TypeToken; |
||||
|
||||
import java.lang.reflect.Type; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
public class XCategory { |
||||
|
||||
@SerializedName("category_id") |
||||
private String categoryId; |
||||
@SerializedName("category_name") |
||||
private String categoryName; |
||||
|
||||
public static List<XCategory> arrayFrom(String str) { |
||||
Type listType = new TypeToken<List<XCategory>>() {}.getType(); |
||||
List<XCategory> items = App.gson().fromJson(str, listType); |
||||
return items == null ? Collections.emptyList() : items; |
||||
} |
||||
|
||||
public String getCategoryId() { |
||||
return TextUtils.isEmpty(categoryId) ? "" : categoryId; |
||||
} |
||||
|
||||
public String getCategoryName() { |
||||
return TextUtils.isEmpty(categoryName) ? "" : categoryName; |
||||
} |
||||
} |
||||
@ -1,53 +0,0 @@ |
||||
package com.fongmi.android.tv.bean; |
||||
|
||||
import android.text.TextUtils; |
||||
|
||||
import com.fongmi.android.tv.App; |
||||
import com.google.gson.annotations.SerializedName; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class XInfo { |
||||
|
||||
@SerializedName("user_info") |
||||
private UserInfo userInfo; |
||||
@SerializedName("server_info") |
||||
private ServerInfo serverInfo; |
||||
|
||||
public static XInfo objectFrom(String str) { |
||||
XInfo item = App.gson().fromJson(str, XInfo.class); |
||||
return item == null ? new XInfo() : item; |
||||
} |
||||
|
||||
public UserInfo getUserInfo() { |
||||
return userInfo == null ? new UserInfo() : userInfo; |
||||
} |
||||
|
||||
public ServerInfo getServerInfo() { |
||||
return serverInfo == null ? new ServerInfo() : serverInfo; |
||||
} |
||||
|
||||
public static class UserInfo { |
||||
|
||||
@SerializedName("allowed_output_formats") |
||||
private List<String> allowedOutputFormats; |
||||
|
||||
public List<String> getAllowedOutputFormats() { |
||||
if (allowedOutputFormats == null) allowedOutputFormats = new ArrayList<>(); |
||||
if (allowedOutputFormats.isEmpty()) allowedOutputFormats.add("ts"); |
||||
allowedOutputFormats.remove("rtmp"); |
||||
return allowedOutputFormats; |
||||
} |
||||
} |
||||
|
||||
public static class ServerInfo { |
||||
|
||||
@SerializedName("timezone") |
||||
private String timezone; |
||||
|
||||
public String getTimezone() { |
||||
return TextUtils.isEmpty(timezone) ? "" : timezone; |
||||
} |
||||
} |
||||
} |
||||
@ -1,73 +0,0 @@ |
||||
package com.fongmi.android.tv.bean; |
||||
|
||||
import android.text.TextUtils; |
||||
|
||||
import com.fongmi.android.tv.App; |
||||
import com.fongmi.android.tv.api.XtreamParser; |
||||
import com.google.gson.annotations.SerializedName; |
||||
import com.google.gson.reflect.TypeToken; |
||||
|
||||
import java.lang.reflect.Type; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
public class XStream { |
||||
|
||||
@SerializedName("name") |
||||
private String name; |
||||
@SerializedName("stream_id") |
||||
private String streamId; |
||||
@SerializedName("stream_type") |
||||
private String streamType; |
||||
@SerializedName("stream_icon") |
||||
private String streamIcon; |
||||
@SerializedName("epg_channel_id") |
||||
private String epgChannelId; |
||||
@SerializedName("category_id") |
||||
private String categoryId; |
||||
@SerializedName("container_extension") |
||||
private String containerExtension; |
||||
|
||||
public static List<XStream> arrayFrom(String str) { |
||||
Type listType = new TypeToken<List<XStream>>() { |
||||
}.getType(); |
||||
List<XStream> items = App.gson().fromJson(str, listType); |
||||
return items == null ? Collections.emptyList() : items; |
||||
} |
||||
|
||||
public String getName() { |
||||
return TextUtils.isEmpty(name) ? "" : name; |
||||
} |
||||
|
||||
public String getStreamId() { |
||||
return TextUtils.isEmpty(streamId) ? "" : streamId; |
||||
} |
||||
|
||||
public String getStreamType() { |
||||
return TextUtils.isEmpty(streamType) ? "" : streamType; |
||||
} |
||||
|
||||
public String getStreamIcon() { |
||||
return TextUtils.isEmpty(streamIcon) ? "" : streamIcon; |
||||
} |
||||
|
||||
public String getEpgChannelId() { |
||||
return TextUtils.isEmpty(epgChannelId) ? "" : epgChannelId; |
||||
} |
||||
|
||||
public String getCategoryId() { |
||||
return TextUtils.isEmpty(categoryId) ? "" : categoryId; |
||||
} |
||||
|
||||
public String getContainerExtension() { |
||||
return TextUtils.isEmpty(containerExtension) ? "" : containerExtension; |
||||
} |
||||
|
||||
public List<String> getPlayUrl(Live live, List<String> formats) { |
||||
List<String> urls = new ArrayList<>(); |
||||
if (!getContainerExtension().isEmpty()) urls.add(XtreamParser.getBuilder(live).addPathSegment(getStreamType()).addPathSegment(live.getUsername()).addPathSegment(live.getPassword()).addPathSegment(getStreamId() + "." + getContainerExtension()).build().toString()); |
||||
else for (String format : formats) urls.add(XtreamParser.getBuilder(live).addPathSegment(getStreamType()).addPathSegment(live.getUsername()).addPathSegment(live.getPassword()).addPathSegment(getStreamId() + "." + format + "$" + format.toUpperCase()).build().toString()); |
||||
return urls; |
||||
} |
||||
} |
||||
@ -1,10 +0,0 @@ |
||||
{ |
||||
"lives": [ |
||||
{ |
||||
"name": "Xtream", |
||||
"url": "http://127.0.0.2:8888", |
||||
"username": "tangsan", |
||||
"password": "tangsan" |
||||
} |
||||
] |
||||
} |
||||
Loading…
Reference in new issue