Skip to content

Commit

Permalink
Merge pull request #149 from themodfatherinc/xmltv-tag-additions
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid authored May 18, 2024
2 parents 55cbae3 + ae9c3b1 commit 047f832
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
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

0 comments on commit 047f832

Please sign in to comment.