Skip to content

Commit

Permalink
Ultimedia added
Browse files Browse the repository at this point in the history
  • Loading branch information
TalbotGooday committed Mar 12, 2020
1 parent a4d27ad commit caa62fa
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 34 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/com/gapps/videonoapi/ui/base/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.gapps.library.api.models.video.VideoPreviewModel
import com.gapps.library.ui.bottom_menu.BottomVideoController
import com.gapps.videonoapi.R

abstract class BaseActivity: AppCompatActivity() {
abstract class BaseActivity : AppCompatActivity() {

protected fun showVideo(model: VideoPreviewModel) {
val host = model.videoHosting
Expand All @@ -31,7 +32,16 @@ abstract class BaseActivity: AppCompatActivity() {
setSize(model.width, model.height)
setTitle(title)
setVideoUrl(initUrl)
setProgressView(TextView(this@BaseActivity).apply { text = "Loading" })
setBackgroundColor(R.color.colorBackground)
setTextColor(R.color.colorHostName)
setTitleColor(R.color.colorVideoTitle)
setLeftButtonText(R.string.vna_close)
setRightButtonText(R.string.vna_open_in)
setRightButtonTextColor(R.color.colorVideoTitle)
setLeftButtonTextColor(R.color.colorVideoTitle)
setCenterButtonIcon(R.drawable.ic_vna_content_copy)
setCenterButtonIconTint(R.color.colorVideoTitle)
setProgressView(TextView(this@BaseActivity).apply { text = "Loading"; setTextColor(-1) })
show()
}
}
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/gapps/videonoapi/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class MainActivity : BaseActivity() {
"https://vzaar.com/videos/401431",
"http://www.hulu.com/w/154323",
"https://ustream.tv/channel/6540154",
"https://ustream.tv/recorded/101541339",
"https://www.ted.com/talks/jill_bolte_taylor_my_stroke_of_insight",
"https://coub.com/view/um0um0",
"https://ustream.tv/recorded/101541339",
"https://asdasdasdasd.tv/recorded/101541339",
"https://www.ultimedia.com/default/index/videogeneric/id/pzkk35/"
"https://www.ultimedia.com/default/index/videogeneric/id/pzkk35/",
"https://notAVideoHost.tv/recorded/101541339"
)

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -65,8 +65,8 @@ class MainActivity : BaseActivity() {
videoService = VideoService.build {
with(this@MainActivity)
httpClient(okHttpClient)
enableCache(false)
enableLog(true)
enableCache(true)
enableLog(false)
withCustomVideoInfoModels(UltimediaVideoInfoModel(), MyYoutubeVideoInfoModel())
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="colorBackground">#161627</color>
<color name="colorHostName">#AAAAE2</color>
<color name="colorVideoTitle">#ffffff</color>

</resources>
11 changes: 9 additions & 2 deletions library/src/main/java/com/gapps/library/api/VideoLoadHelper.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gapps.library.api

import android.content.Context
import android.util.Log
import com.gapps.library.api.models.api.base.VideoInfoModel
import com.gapps.library.api.models.video.VideoPreviewModel
import com.gapps.library.api.models.video.base.BaseVideoResponse
Expand All @@ -20,7 +21,8 @@ import kotlin.coroutines.CoroutineContext
internal class VideoLoadHelper(
private val context: Context?,
private val client: OkHttpClient,
private val isCacheEnabled: Boolean
private val isCacheEnabled: Boolean,
val isLogEnabled: Boolean
) : CoroutineScope {
private val job = Job()
override val coroutineContext: CoroutineContext
Expand All @@ -30,6 +32,7 @@ internal class VideoLoadHelper(

private var gson = GsonBuilder()
.setLenient()
.setPrettyPrinting()
.create()

fun getVideoInfo(
Expand Down Expand Up @@ -69,13 +72,17 @@ internal class VideoLoadHelper(
try {
val jsonBody = makeCallGetBody(client, finalUrl)

if (isLogEnabled) {
Log.i(VideoService.TAG, "a response from $originalUrl:\n${gson.toJson(jsonBody)}")
}

if (jsonBody == null) {
onSuccess.invoke(VideoPreviewModel.error(originalUrl, "$ERROR_2 \n---> Response is null"))

return@launch
}

val result = fromJson(jsonBody, videoInfoModel.type)
val result = (gson.fromJson(jsonBody, videoInfoModel.type) as BaseVideoResponse)
.toPreview(originalUrl, playLink, videoInfoModel.hostingName, videoId)

onSuccess.invoke(result)
Expand Down
9 changes: 6 additions & 3 deletions library/src/main/java/com/gapps/library/api/VideoService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class VideoService(
private val customModels: List<VideoInfoModel<out BaseVideoResponse>>
) {
companion object {
const val TAG = "VideoService"

val videoInfoModelsList = mutableListOf(
CoubVideoInfoModel(),
DailymotionVideoInfoModel(),
Expand All @@ -30,7 +32,8 @@ class VideoService(
VzaarVideoInfoModel(),
WistiaVideoInfoModel(),
YoutubeMusicVideoInfoModel(),
YoutubeVideoInfoModel()
YoutubeVideoInfoModel(),
UltimediaVideoInfoModel()
)

inline fun build(block: Builder.() -> Unit) = Builder().apply(block).build()
Expand All @@ -51,15 +54,15 @@ class VideoService(
videoInfoModelsList.addAll(customModels)
}

private val videoHelper = VideoLoadHelper(context, client, isCacheEnabled)
private val videoHelper = VideoLoadHelper(context, client, isCacheEnabled, isLogEnabled)

fun loadVideoPreview(
url: String,
onSuccess: (VideoPreviewModel) -> Unit,
onError: ((String, String) -> Unit)? = null
) {
if (isLogEnabled) {
Log.i("VideoService", "loading url: $url")
Log.i(TAG, "loading url: $url")
}

val callback: (VideoPreviewModel) -> Unit = { model: VideoPreviewModel ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.gapps.library.api.models.api

import com.gapps.library.api.FORMAT
import com.gapps.library.api.FORMAT_JSON
import com.gapps.library.api.URL
import com.gapps.library.api.models.api.base.VideoInfoModel
import com.gapps.library.api.models.video.ultimedia.UltimediaResponse

class UltimediaVideoInfoModel: VideoInfoModel<UltimediaResponse>() {
override val baseUrl: String
get() = "https://www.ultimedia.com"
//https://regex101.com/r/2AsrOc/1
override val pattern: String
get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?ultimedia\\.com\\/(?:deliver|default|api)\\/.*\\/([_a-zA-Z0-9]+)\\S*"
override val idPattern: String
get() = pattern
override val type: Class<UltimediaResponse>
get() = UltimediaResponse::class.java
override val hostingName: String
get() = "Ultimedia"

override fun getInfoUrl(incomingUrl: String?): String? {
return "$baseUrl/api/search/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl"
}

override fun getPlayLink(videoId: String): String {
return "https://www.ultimedia.com/deliver/generic/iframe/src/$videoId/"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.gapps.library.api.models.video.ultimedia


import com.gapps.library.api.models.video.VideoPreviewModel
import com.gapps.library.api.models.video.base.BaseVideoResponse
import com.google.gson.annotations.SerializedName

data class UltimediaResponse(
@SerializedName("version")
val version: String = "",
@SerializedName("type")
val type: String = "",
@SerializedName("title")
val title: String = "",
@SerializedName("description")
val description: String = "",
@SerializedName("html")
val html: String = "",
@SerializedName("width")
val width: String = "",
@SerializedName("height")
val height: String = "",
@SerializedName("thumbnail_url")
val thumbnailUrl: String = "",
@SerializedName("thumbnail_width")
val thumbnailWidth: String = "",
@SerializedName("thumbnail_height")
val thumbnailHeight: String = "",
@SerializedName("provider_name")
val providerName: String = "",
@SerializedName("provider_url")
val providerUrl: String = "",
@SerializedName("author_name")
val authorName: String = ""
): BaseVideoResponse{
override fun toPreview(url: String?, linkToPlay: String, hostingName: String, videoId: String): VideoPreviewModel {
return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply {
this.thumbnailUrl = this@UltimediaResponse.thumbnailUrl
this.videoTitle = this@UltimediaResponse.authorName
this.width = this@UltimediaResponse.width.toInt()
this.height = this@UltimediaResponse.height.toInt()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.gapps.library.utils.toMD5
import java.util.*


private const val TAG = "VideoModelsORM"
private const val TAG = "VideoServiceORM"
private const val TABLE_NAME = "video_model"
private const val COMMA_SEP = ", "

Expand Down
Loading

0 comments on commit caa62fa

Please sign in to comment.