|
|
|
|
@ -12,6 +12,9 @@ import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
public class Catchup { |
|
|
|
|
|
|
|
|
|
private static final Pattern TOKEN_PATTERN = Pattern.compile("(\\$?\\{[^}]*\\})"); |
|
|
|
|
private static final Pattern TAG_PATTERN = Pattern.compile("\\{([^}]+)\\}"); |
|
|
|
|
|
|
|
|
|
@SerializedName("type") |
|
|
|
|
private String type; |
|
|
|
|
@SerializedName("days") |
|
|
|
|
@ -91,10 +94,6 @@ public class Catchup { |
|
|
|
|
return getSource().isEmpty(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isAppend() { |
|
|
|
|
return getType().equals("append"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isDefault() { |
|
|
|
|
return getType().equals("default"); |
|
|
|
|
} |
|
|
|
|
@ -108,17 +107,23 @@ public class Catchup { |
|
|
|
|
|
|
|
|
|
public String format(String url, EpgData data) { |
|
|
|
|
String result = getSource(); |
|
|
|
|
Matcher matcher = Pattern.compile("(\\$?\\{[^}]*\\})").matcher(result); |
|
|
|
|
Matcher matcher = TOKEN_PATTERN.matcher(result); |
|
|
|
|
while (matcher.find()) result = result.replace(matcher.group(1), format(matcher.group(1), data.getStartTime(), data.getEndTime())); |
|
|
|
|
return isDefault() ? result : append(url, result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String formatTime(long millis, String fmt) { |
|
|
|
|
if (fmt.equals("timestamp")) return String.valueOf(millis / 1000); |
|
|
|
|
return new SimpleDateFormat(fmt, Locale.getDefault()).format(millis); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String format(String group, long start, long end) { |
|
|
|
|
Matcher matcher = Pattern.compile("\\{([^}]+)\\}").matcher(group); |
|
|
|
|
Matcher matcher = TAG_PATTERN.matcher(group); |
|
|
|
|
if (!matcher.find()) return ""; |
|
|
|
|
String tag = matcher.group(1); |
|
|
|
|
if (tag.startsWith("(b")) return new SimpleDateFormat(tag.split("\\)")[1], Locale.getDefault()).format(start); |
|
|
|
|
if (tag.startsWith("(e")) return new SimpleDateFormat(tag.split("\\)")[1], Locale.getDefault()).format(end); |
|
|
|
|
int paren = tag.indexOf(')'); |
|
|
|
|
if (tag.startsWith("(b") && paren >= 0) return formatTime(start, tag.substring(paren + 1)); |
|
|
|
|
if (tag.startsWith("(e") && paren >= 0) return formatTime(end, tag.substring(paren + 1)); |
|
|
|
|
if (tag.startsWith("utcend:")) return String.valueOf(end / 1000); |
|
|
|
|
if (tag.startsWith("utc:")) return String.valueOf(start / 1000); |
|
|
|
|
return ""; |
|
|
|
|
|