2019-04-28 22:43:52 +02:00
|
|
|
package org.schabi.newpipe.database.stream.model
|
|
|
|
|
2020-05-01 20:13:01 +02:00
|
|
|
import androidx.room.ColumnInfo
|
|
|
|
import androidx.room.Entity
|
|
|
|
import androidx.room.Ignore
|
|
|
|
import androidx.room.Index
|
|
|
|
import androidx.room.PrimaryKey
|
2020-05-01 20:13:21 +02:00
|
|
|
import java.io.Serializable
|
2020-10-18 08:16:55 +02:00
|
|
|
import java.time.OffsetDateTime
|
2019-04-28 22:43:52 +02:00
|
|
|
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_SERVICE_ID
|
|
|
|
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_TABLE
|
|
|
|
import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_URL
|
|
|
|
import org.schabi.newpipe.extractor.localization.DateWrapper
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfo
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType
|
|
|
|
import org.schabi.newpipe.player.playqueue.PlayQueueItem
|
|
|
|
|
|
|
|
@Entity(tableName = STREAM_TABLE,
|
|
|
|
indices = [
|
|
|
|
Index(value = [STREAM_SERVICE_ID, STREAM_URL], unique = true)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
data class StreamEntity(
|
2020-05-01 20:13:21 +02:00
|
|
|
@PrimaryKey(autoGenerate = true)
|
|
|
|
@ColumnInfo(name = STREAM_ID)
|
|
|
|
var uid: Long = 0,
|
2019-04-28 22:43:52 +02:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_SERVICE_ID)
|
|
|
|
var serviceId: Int,
|
2019-04-28 22:43:52 +02:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_URL)
|
|
|
|
var url: String,
|
2019-04-28 22:43:52 +02:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_TITLE)
|
|
|
|
var title: String,
|
2019-04-28 22:43:52 +02:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_TYPE)
|
|
|
|
var streamType: StreamType,
|
2019-04-28 22:43:52 +02:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_DURATION)
|
|
|
|
var duration: Long,
|
2019-04-28 22:43:52 +02:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_UPLOADER)
|
|
|
|
var uploader: String,
|
2019-04-28 22:43:52 +02:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_THUMBNAIL_URL)
|
|
|
|
var thumbnailUrl: String? = null,
|
2019-04-28 22:43:52 +02:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_VIEWS)
|
|
|
|
var viewCount: Long? = null,
|
2019-04-28 22:43:52 +02:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_TEXTUAL_UPLOAD_DATE)
|
|
|
|
var textualUploadDate: String? = null,
|
2019-04-28 22:43:52 +02:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_UPLOAD_DATE)
|
2020-10-18 08:16:55 +02:00
|
|
|
var uploadDate: OffsetDateTime? = null,
|
2019-12-16 08:36:04 +01:00
|
|
|
|
2020-05-01 20:13:21 +02:00
|
|
|
@ColumnInfo(name = STREAM_IS_UPLOAD_DATE_APPROXIMATION)
|
|
|
|
var isUploadDateApproximation: Boolean? = null
|
2019-04-28 22:43:52 +02:00
|
|
|
) : Serializable {
|
|
|
|
@Ignore
|
|
|
|
constructor(item: StreamInfoItem) : this(
|
|
|
|
serviceId = item.serviceId, url = item.url, title = item.name,
|
|
|
|
streamType = item.streamType, duration = item.duration, uploader = item.uploaderName,
|
|
|
|
thumbnailUrl = item.thumbnailUrl, viewCount = item.viewCount,
|
2020-10-18 08:16:55 +02:00
|
|
|
textualUploadDate = item.textualUploadDate, uploadDate = item.uploadDate?.offsetDateTime(),
|
2019-12-16 08:36:04 +01:00
|
|
|
isUploadDateApproximation = item.uploadDate?.isApproximation
|
2019-04-28 22:43:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
@Ignore
|
|
|
|
constructor(info: StreamInfo) : this(
|
|
|
|
serviceId = info.serviceId, url = info.url, title = info.name,
|
|
|
|
streamType = info.streamType, duration = info.duration, uploader = info.uploaderName,
|
|
|
|
thumbnailUrl = info.thumbnailUrl, viewCount = info.viewCount,
|
2020-10-18 08:16:55 +02:00
|
|
|
textualUploadDate = info.textualUploadDate, uploadDate = info.uploadDate?.offsetDateTime(),
|
2019-12-16 08:36:04 +01:00
|
|
|
isUploadDateApproximation = info.uploadDate?.isApproximation
|
2019-04-28 22:43:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
@Ignore
|
|
|
|
constructor(item: PlayQueueItem) : this(
|
|
|
|
serviceId = item.serviceId, url = item.url, title = item.title,
|
|
|
|
streamType = item.streamType, duration = item.duration, uploader = item.uploader,
|
|
|
|
thumbnailUrl = item.thumbnailUrl
|
|
|
|
)
|
|
|
|
|
|
|
|
fun toStreamInfoItem(): StreamInfoItem {
|
|
|
|
val item = StreamInfoItem(serviceId, url, title, streamType)
|
|
|
|
item.duration = duration
|
|
|
|
item.uploaderName = uploader
|
|
|
|
item.thumbnailUrl = thumbnailUrl
|
|
|
|
|
|
|
|
if (viewCount != null) item.viewCount = viewCount as Long
|
|
|
|
item.textualUploadDate = textualUploadDate
|
2019-12-16 08:36:04 +01:00
|
|
|
item.uploadDate = uploadDate?.let {
|
2020-10-18 08:16:55 +02:00
|
|
|
DateWrapper(it, isUploadDateApproximation ?: false)
|
2019-12-16 08:36:04 +01:00
|
|
|
}
|
2019-04-28 22:43:52 +02:00
|
|
|
|
|
|
|
return item
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val STREAM_TABLE = "streams"
|
|
|
|
const val STREAM_ID = "uid"
|
|
|
|
const val STREAM_SERVICE_ID = "service_id"
|
|
|
|
const val STREAM_URL = "url"
|
|
|
|
const val STREAM_TITLE = "title"
|
|
|
|
const val STREAM_TYPE = "stream_type"
|
|
|
|
const val STREAM_DURATION = "duration"
|
|
|
|
const val STREAM_UPLOADER = "uploader"
|
|
|
|
const val STREAM_THUMBNAIL_URL = "thumbnail_url"
|
|
|
|
|
|
|
|
const val STREAM_VIEWS = "view_count"
|
|
|
|
const val STREAM_TEXTUAL_UPLOAD_DATE = "textual_upload_date"
|
|
|
|
const val STREAM_UPLOAD_DATE = "upload_date"
|
2019-12-16 08:36:04 +01:00
|
|
|
const val STREAM_IS_UPLOAD_DATE_APPROXIMATION = "is_upload_date_approximation"
|
2019-04-28 22:43:52 +02:00
|
|
|
}
|
|
|
|
}
|