mirror of https://github.com/FongMi/TV.git
parent
acf8a2265b
commit
8b45aefcaf
@ -0,0 +1,38 @@ |
||||
package com.fongmi.android.tv.api; |
||||
|
||||
import com.fongmi.android.tv.bean.Live; |
||||
import com.fongmi.android.tv.bean.XCategory; |
||||
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 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, String action) { |
||||
return getBuilder(live).addPathSegment("player_api.php").addQueryParameter("username", live.getUsername()).addQueryParameter("password", live.getPassword()).addQueryParameter("action", action).build().toString(); |
||||
} |
||||
|
||||
public static String getTsUrl(Live live, String id) { |
||||
return getBuilder(live).addPathSegment("live").addPathSegment(live.getUsername()).addPathSegment(live.getPassword()).addPathSegment(id + ".ts").build().toString(); |
||||
} |
||||
|
||||
public static List<XCategory> getCategoryList(Live live) { |
||||
return XCategory.arrayFrom(OkHttp.string(getApiUrl(live, "get_live_categories"))); |
||||
} |
||||
|
||||
public static List<XStream> getStreamList(Live live) { |
||||
return XStream.arrayFrom(OkHttp.string(getApiUrl(live, "get_live_streams"))); |
||||
} |
||||
} |
||||
@ -0,0 +1,33 @@ |
||||
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; |
||||
} |
||||
} |
||||
@ -0,0 +1,51 @@ |
||||
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 XStream { |
||||
|
||||
@SerializedName("name") |
||||
private String name; |
||||
@SerializedName("stream_id") |
||||
private String streamId; |
||||
@SerializedName("stream_icon") |
||||
private String streamIcon; |
||||
@SerializedName("epg_channel_id") |
||||
private String epgChannelId; |
||||
@SerializedName("category_id") |
||||
private String categoryId; |
||||
|
||||
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 getStreamIcon() { |
||||
return TextUtils.isEmpty(streamIcon) ? "" : streamIcon; |
||||
} |
||||
|
||||
public String getEpgChannelId() { |
||||
return TextUtils.isEmpty(epgChannelId) ? "" : epgChannelId; |
||||
} |
||||
|
||||
public String getCategoryId() { |
||||
return TextUtils.isEmpty(categoryId) ? "" : categoryId; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue