Skip to content

Commit

Permalink
feat: add ability to parse KODIPROPs for m3u parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Jan 20, 2024
1 parent a04176d commit 072fd02
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 120 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/com/m3u/core/util/Likable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package com.m3u.core.util

// TODO: use ksp to generate code.
interface Likable<T> {
infix fun like(another: T): Boolean = this == another
}
Expand Down
123 changes: 123 additions & 0 deletions data/schemas/com.m3u.data.database.M3UDatabase/6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"formatVersion": 1,
"database": {
"version": 6,
"identityHash": "25b63cd54c82e28bac3d2a5ed49cdc43",
"entities": [
{
"tableName": "streams",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`url` TEXT NOT NULL, `group` TEXT NOT NULL, `title` TEXT NOT NULL, `cover` TEXT, `playlistUrl` TEXT NOT NULL, `license_type` TEXT DEFAULT NULL, `license_key` TEXT DEFAULT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `favourite` INTEGER NOT NULL, `banned` INTEGER NOT NULL, `seen` INTEGER NOT NULL DEFAULT 0)",
"fields": [
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "group",
"columnName": "group",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "cover",
"columnName": "cover",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "playlistUrl",
"columnName": "playlistUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "licenseType",
"columnName": "license_type",
"affinity": "TEXT",
"notNull": false,
"defaultValue": "NULL"
},
{
"fieldPath": "licenseKey",
"columnName": "license_key",
"affinity": "TEXT",
"notNull": false,
"defaultValue": "NULL"
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "favourite",
"columnName": "favourite",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "banned",
"columnName": "banned",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "seen",
"columnName": "seen",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "playlists",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `url` TEXT NOT NULL, PRIMARY KEY(`url`))",
"fields": [
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"url"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '25b63cd54c82e28bac3d2a5ed49cdc43')"
]
}
}
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 @@ -10,15 +10,16 @@ import com.m3u.data.database.model.Stream

@Database(
entities = [Stream::class, Playlist::class],
version = 5,
version = 6,
exportSchema = true,
autoMigrations = [
AutoMigration(
from = 3,
to = 4,
spec = DatabaseMigrations.AutoMigration3To4::class
),
AutoMigration(from = 4, to = 5)
AutoMigration(from = 4, to = 5),
AutoMigration(from = 5, to = 6)
]
)
abstract class M3UDatabase : RoomDatabase() {
Expand Down
9 changes: 7 additions & 2 deletions data/src/main/java/com/m3u/data/database/model/Stream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ data class Stream(
val cover: String? = null,
@ColumnInfo(name = "playlistUrl")
val playlistUrl: String,
@ColumnInfo(name = "license_type", defaultValue = "NULL")
val licenseType: String? = null,
@ColumnInfo(name = "license_key", defaultValue = "NULL")
val licenseKey: String? = null,
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
val id: Int = 0,
Expand All @@ -28,9 +32,10 @@ data class Stream(
@ColumnInfo(name = "banned")
val banned: Boolean = false,
@ColumnInfo(name = "seen", defaultValue = "0")
val seen: Long = 0L
val seen: Long = 0L,
) : Likable<Stream> {
override infix fun like(another: Stream): Boolean =
this.url == another.url && this.playlistUrl == another.playlistUrl && this.cover == another.cover
&& this.group == another.group && this.title == another.title
&& this.group == another.group && this.title == another.title && this.licenseType == another.licenseType
&& this.licenseKey == another.licenseKey
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import com.m3u.data.database.dao.StreamDao
import com.m3u.data.database.model.Playlist
import com.m3u.data.database.model.PlaylistWithStreams
import com.m3u.data.database.model.Stream
import com.m3u.data.repository.PlaylistRepository
import com.m3u.data.repository.parser.M3UPlaylistParser
import com.m3u.data.repository.parser.model.toStream
import com.m3u.data.repository.PlaylistRepository
import com.m3u.i18n.R.string
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
Expand All @@ -46,7 +46,7 @@ class PlaylistRepositoryImpl @Inject constructor(
private val streamDao: StreamDao,
@Logger.Message private val logger: Logger,
private val client: OkHttpClient,
@M3UPlaylistParser.BjoernPetersen private val parser: M3UPlaylistParser,
@M3UPlaylistParser.Default private val parser: M3UPlaylistParser,
@ApplicationContext private val context: Context
) : PlaylistRepository {

Expand Down
Loading

0 comments on commit 072fd02

Please sign in to comment.