Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<new /> <live /> and <previously-shown /> tags added to parser/DB #149

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions data/src/main/java/com/m3u/data/database/M3UDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.m3u.data.database.model.Stream

@Database(
entities = [Stream::class, Playlist::class, Episode::class, Programme::class, ColorScheme::class],
version = 16,
version = 17,
exportSchema = true,
autoMigrations = [
AutoMigration(
Expand All @@ -42,7 +42,8 @@ import com.m3u.data.database.model.Stream
from = 14,
to = 16,
spec = DatabaseMigrations.AutoMigrate14To16::class
)
),
AutoMigration(from = 16, to = 17),
]
)
@TypeConverters(Converters::class)
Expand Down
6 changes: 6 additions & 0 deletions data/src/main/java/com/m3u/data/database/model/Programme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ data class Programme(
val title: String,
@ColumnInfo(name = "description")
val description: String,
@ColumnInfo(name = "new", defaultValue = "0")
val isNew: Boolean,
@ColumnInfo(name = "live", defaultValue = "0")
val isLive: Boolean,
@ColumnInfo(name = "previous_start", defaultValue = "NULL")
val previouslyShownStart: String? = null,
@ColumnInfo(name = "icon")
val icon: String? = null,
@ColumnInfo(name = "categories")
Expand Down
6 changes: 6 additions & 0 deletions data/src/main/java/com/m3u/data/parser/epg/EpgData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ data class EpgProgramme(
val title: String? = null,
val desc: String? = null,
val icon: String? = null,
val isNew: Boolean = false,
val isLive: Boolean = false,
val previouslyShownStart: String? = null,
val categories: List<String>
) {
companion object {
Expand Down Expand Up @@ -58,6 +61,9 @@ fun EpgProgramme.toProgramme(
title = title.orEmpty(),
description = desc.orEmpty(),
icon = icon,
isNew = isNew,
isLive = isLive,
previouslyShownStart = previouslyShownStart,
categories = categories,
channelId = channel
)
29 changes: 28 additions & 1 deletion data/src/main/java/com/m3u/data/parser/epg/EpgParserImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,19 @@ class EpgParserImpl @Inject constructor(
var desc: String? = null
val categories = mutableListOf<String>()
var icon: String? = null
var isNew = false // Initialize isNew flag
var isLive = false
var previouslyShownStart: String? = null // Initialize previouslyShown variable
while (next() != XmlPullParser.END_TAG) {
if (eventType != XmlPullParser.START_TAG) continue
when (name) {
"title" -> title = readTitle()
"desc" -> desc = readDesc()
"category" -> categories += readCategory()
"icon" -> icon = readIcon()
"new" -> isNew = readNew() // Update isNewTag flag
"live" -> isLive = readLive() // Update isNewTag flag
"previously-shown" -> previouslyShownStart = readPreviouslyShown()
else -> skip()
}
}
Expand All @@ -112,7 +118,10 @@ class EpgParserImpl @Inject constructor(
title = title,
desc = desc,
icon = icon,
categories = categories
categories = categories,
isNew = isNew,
isLive = isLive,
previouslyShownStart = previouslyShownStart
)
}

Expand Down Expand Up @@ -170,6 +179,24 @@ class EpgParserImpl @Inject constructor(
return category
}

private fun XmlPullParser.readNew(): Boolean {
require(XmlPullParser.END_TAG, ns, "new")
return true
}

private fun XmlPullParser.readLive(): Boolean {
require(XmlPullParser.END_TAG, ns, "live")
return true
}

private fun XmlPullParser.readPreviouslyShown(): String? {
require(XmlPullParser.START_TAG, ns, "previously-shown")
val start = getAttributeValue(null, "start")
nextTag()
require(XmlPullParser.END_TAG, ns, "previously-shown")
return start
}

private fun XmlPullParser.readText(): String {
var result = ""
if (next() == XmlPullParser.TEXT) {
Expand Down
Loading