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

add live, new and previously-shown data to db #147

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 4 additions & 3 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, ColorPack::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 All @@ -52,4 +53,4 @@ internal abstract class M3UDatabase : RoomDatabase() {
abstract fun episodeDao(): EpisodeDao
abstract fun programmeDao(): ProgrammeDao
abstract fun colorPackDao(): ColorPackDao
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface ProgrammeDao {

@Query(
"""
SELECT * FROM programmes
SELECT * FROM programmes
WHERE epg_url in (:epgUrls)
AND channel_id = :channelId
AND start <= :time
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 @@ -31,6 +31,12 @@ data class Programme(
val title: String,
@ColumnInfo(name = "description")
val description: String,
@ColumnInfo(name = "new_tag", defaultValue = "0")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"_tag"

val isNew: Boolean,
@ColumnInfo(name = "live_tag", 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 @@ -59,5 +62,8 @@ fun EpgProgramme.toProgramme(
description = desc.orEmpty(),
icon = icon,
categories = categories,
isNew = isNew,
isLive = isLive,
previouslyShownStart = previouslyShownStart,
channelId = channel
)
30 changes: 29 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,25 +94,35 @@ class EpgParserImpl @Inject constructor(
var desc: String? = null
val categories = mutableListOf<String>()
var icon: String? = null
var isNew = false
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()
}
}
require(XmlPullParser.END_TAG, ns, "programme")
//
themodfatherinc marked this conversation as resolved.
Show resolved Hide resolved
return EpgProgramme(
start = start,
stop = stop,
channel = channel,
title = title,
desc = desc,
icon = icon,
categories = categories
categories = categories,
isNew = isNew,
isLive = isLive,
previouslyShownStart = previouslyShownStart
)
}

Expand Down Expand Up @@ -170,6 +180,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