IPTV-Android
IPTV-Android copied to clipboard
Better Playlist Parsing
The playlist parsing is missing several channels and throwing errors. This should be a pull request, but here it goes:
PlaylistActivity.java:
private String parse_tvg(String line, String tvg_type){
List<String> matchList = new ArrayList<String>();
try {
Pattern regex = Pattern.compile(tvg_type+"=\"(.*?)\"", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.MULTILINE);
Matcher regexMatcher = regex.matcher(line);
while (regexMatcher.find()) {
matchList.add(regexMatcher.group());
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
if ( matchList.isEmpty() ){
return "";
}else {
return matchList.get(0);
}
};
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
loading.dismiss();
stream = stream.replace("#EXTM3U", "");
String[] linesArray = stream.split("#EXTINF:-1");
linesArray = Arrays.copyOfRange(linesArray, 1, linesArray.length);
JSONArray ar = new JSONArray();
for (String currLine : linesArray) {
Log.e("IPTV", currLine);
JSONObject ob = new JSONObject();
try {
String[] channel = currLine.split("\n");
String url = channel[1];
String name = channel[0 ].split(",")[1];
String logo = parse_tvg(currLine, "tvg-logo");
ob.put("url", url);
ob.put("name", name);
ob.put("logo", logo);
ar.put(ob);
} catch (Exception fdfd) {
Log.e("Google", "Error: " + fdfd.fillInStackTrace());
}
}
goJson = ar.toString();
sharedPrefManager.saveSPString(SharedPrefManager.SP_CHANNELS, goJson);
Intent intent = new Intent(mcon, ChannelsActivity.class);
intent.putExtra("title", allData.get(key).getTitle());
startActivity(intent);
}