From d09cfbdb77fabd483374d20f62d2a51f748b23e1 Mon Sep 17 00:00:00 2001 From: FongMi Date: Thu, 27 Oct 2022 16:25:58 +0800 Subject: [PATCH] Update to 1.3.9 --- app/build.gradle | 4 +- .../com/fongmi/android/tv/api/LiveParser.java | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/fongmi/android/tv/api/LiveParser.java diff --git a/app/build.gradle b/app/build.gradle index 31dc87f67..fb8f7705d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.fongmi.android.tv" minSdk 21 targetSdk 33 - versionCode 38 - versionName "1.3.8" + versionCode 39 + versionName "1.3.9" resValue "string", "url", "" ndk { abiFilters "armeabi-v7a" } } diff --git a/app/src/main/java/com/fongmi/android/tv/api/LiveParser.java b/app/src/main/java/com/fongmi/android/tv/api/LiveParser.java new file mode 100644 index 000000000..297f87814 --- /dev/null +++ b/app/src/main/java/com/fongmi/android/tv/api/LiveParser.java @@ -0,0 +1,59 @@ +package com.fongmi.android.tv.api; + +import com.fongmi.android.tv.bean.Channel; +import com.fongmi.android.tv.bean.Group; +import com.fongmi.android.tv.bean.Live; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class LiveParser { + + private static final Pattern GROUP = Pattern.compile(".*group-title=\"(.?|.+?)\".*", Pattern.CASE_INSENSITIVE); + private static final Pattern LOGO = Pattern.compile(".*tvg-logo=\"(.?|.+?)\".*", Pattern.CASE_INSENSITIVE); + private static final Pattern NAME = Pattern.compile(".*,(.+?)$", Pattern.CASE_INSENSITIVE); + + private static String extract(String line, Pattern pattern) { + Matcher matcher = pattern.matcher(line); + if (matcher.matches()) return matcher.group(1); + return ""; + } + + public static void start(Live live, String text) { + int number = 0; + if (text.startsWith("#EXTM3U")) m3u(live, text); else txt(live, text); + for (Group group : live.getGroups()) { + for (Channel channel : group.getChannel()) { + channel.setNumber(++number); + } + } + } + + private static void m3u(Live live, String text) { + Channel channel = new Channel(""); + for (String line : text.split("\n")) { + if (line.startsWith("#EXTINF:")) { + Group group = live.find(new Group(extract(line, GROUP))); + channel = group.find(new Channel(extract(line, NAME))); + channel.setLogo(extract(line, LOGO)); + } else if (line.contains("://")) { + channel.getUrls().add(line); + } + } + } + + private static void txt(Live live, String text) { + for (String line : text.split("\n")) { + String[] split = line.split(","); + if (split.length < 2) continue; + if (line.contains("#genre#")) { + live.getGroups().add(new Group(split[0])); + } + if (split[1].contains("://")) { + Group group = live.getGroups().get(live.getGroups().size() - 1); + Channel channel = group.find(new Channel(split[0])); + channel.addUrls(split[1].split("#")); + } + } + } +}