diff --git a/app/src/main/java/com/gapps/videonoapi/ui/base/BaseActivity.kt b/app/src/main/java/com/gapps/videonoapi/ui/base/BaseActivity.kt index c10bdba..485b652 100644 --- a/app/src/main/java/com/gapps/videonoapi/ui/base/BaseActivity.kt +++ b/app/src/main/java/com/gapps/videonoapi/ui/base/BaseActivity.kt @@ -5,6 +5,7 @@ import android.net.Uri import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat import com.gapps.library.api.models.video.VideoPreviewModel import com.gapps.library.ui.bottom_menu.BottomVideoController import com.gapps.videonoapi.R @@ -32,15 +33,30 @@ abstract class BaseActivity : AppCompatActivity() { setSize(model.width, model.height) setTitle(title) setVideoUrl(initUrl) - setBackgroundColor(R.color.colorBackground) - setTextColor(R.color.colorHostName) - setTitleColor(R.color.colorVideoTitle) + setBackgroundColor(ContextCompat.getColor(this@BaseActivity, R.color.colorBackground)) + setTextColor(ContextCompat.getColor(this@BaseActivity, R.color.colorHostName)) + setTitleColor(ContextCompat.getColor(this@BaseActivity, R.color.colorVideoTitle)) setLeftButtonText(R.string.vna_close) setRightButtonText(R.string.vna_open_in) - setRightButtonTextColor(R.color.colorVideoTitle) - setLeftButtonTextColor(R.color.colorVideoTitle) + setRightButtonTextColor( + ContextCompat.getColor( + this@BaseActivity, + R.color.colorVideoTitle + ) + ) + setLeftButtonTextColor( + ContextCompat.getColor( + this@BaseActivity, + R.color.colorVideoTitle + ) + ) setCenterButtonIcon(R.drawable.ic_vna_content_copy) - setCenterButtonIconTint(R.color.colorVideoTitle) + setCenterButtonIconTint( + ContextCompat.getColor( + this@BaseActivity, + R.color.colorVideoTitle + ) + ) setProgressView(TextView(this@BaseActivity).apply { text = "Loading"; setTextColor(-1) }) diff --git a/app/src/main/java/com/gapps/videonoapi/ui/main/MainActivity.kt b/app/src/main/java/com/gapps/videonoapi/ui/main/MainActivity.kt index 5b0eca3..ff512ce 100644 --- a/app/src/main/java/com/gapps/videonoapi/ui/main/MainActivity.kt +++ b/app/src/main/java/com/gapps/videonoapi/ui/main/MainActivity.kt @@ -31,7 +31,7 @@ class MainActivity : BaseActivity() { "https://streamable.com/s0phr", "https://vimeo.com/259411563", "https://rutube.ru/video/d70e62b44b8893e98e3e90a6e2c9fcd4/?pl_type=source&pl_id=18265", - "https://www.facebook.com/kinodizi/videos/965220097161488", + "https://www.facebook.com/watch?v=795751214848051", "https://www.dailymotion.com/video/x5sxbmb", "https://dave.wistia.com/medias/0k5h1g1chs/", "https://vzaar.com/videos/401431", diff --git a/app/src/main/java/com/gapps/videonoapi/ui/main/adapters/VideoAdapter.kt b/app/src/main/java/com/gapps/videonoapi/ui/main/adapters/VideoAdapter.kt index 689ea51..52a9210 100644 --- a/app/src/main/java/com/gapps/videonoapi/ui/main/adapters/VideoAdapter.kt +++ b/app/src/main/java/com/gapps/videonoapi/ui/main/adapters/VideoAdapter.kt @@ -11,6 +11,8 @@ import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import coil.load import com.gapps.library.api.VideoService +import com.gapps.library.api.models.api.* +import com.gapps.library.api.models.api.builder.EmbeddingRequest import com.gapps.library.api.models.video.VideoPreviewModel import com.gapps.videonoapi.R import com.gapps.videonoapi.utils.extensions.collapse @@ -91,7 +93,7 @@ class VideoAdapter( if (loadedDataItem == null) { videoService.loadVideoPreview( - url = item, + request = createRequestBuilder(item), onSuccess = { video -> loadedData.put(bindingAdapterPosition, video) loadedDataItem = video @@ -177,21 +179,21 @@ class VideoAdapter( type ?: return val icon = when (type) { - "YouTube" -> R.drawable.youtube - "YouTube Music" -> R.drawable.youtube_music - "Vimeo" -> R.drawable.vimeo - "Rutube" -> R.drawable.rutube - "Facebook" -> R.drawable.ic_fb - "Dailymotion" -> R.drawable.dailymotion - "Wistia" -> R.drawable.ic_wistia - "Vzaar" -> R.drawable.ic_vzaar - "Hulu" -> R.drawable.hulu - "Ustream" -> R.drawable.ibm - "Ted Talks" -> R.drawable.ted_talks - "Coub" -> R.drawable.ic_coub - "Ultimedia" -> R.drawable.ultimedia - "Streamable" -> R.drawable.streamable - "Loom" -> R.drawable.loom + YOUTUBE_HOST_NAME -> R.drawable.youtube + YOUTUBE_MUSIC_HOST_NAME -> R.drawable.youtube_music + VIMEO_HOST_NAME -> R.drawable.vimeo + RUTUBE_HOST_NAME -> R.drawable.rutube + FACEBOOK_HOST_NAME -> R.drawable.ic_fb + DAILYMOTION_HOST_NAME -> R.drawable.dailymotion + WISTIA_HOST_NAME -> R.drawable.ic_wistia + VZAAR_HOST_NAME -> R.drawable.ic_vzaar + HULU_HOST_NAME -> R.drawable.hulu + USTREAM_HOST_NAME -> R.drawable.ibm + TED_TALKS_HOST_NAME -> R.drawable.ted_talks + COUB_HOST_NAME -> R.drawable.ic_coub + ULTIMEDIA_HOST_NAME -> R.drawable.ultimedia + STREAMABLE_HOST_NAME -> R.drawable.streamable + LOOM_HOST_NAME -> R.drawable.loom else -> R.drawable.ic_video } @@ -202,4 +204,14 @@ class VideoAdapter( interface Listener { fun onItemClick(item: VideoPreviewModel) } +} + +fun createRequestBuilder(url: String) = EmbeddingRequest.build { + setUrl(url) + headers { + host(FACEBOOK_HOST_NAME) { + add("access_token", "2940857442908969|0733ab34586cc8a92080dc1b1d1e6971") + addAll(mapOf()) + } + } } \ No newline at end of file diff --git a/embedded_video_lib/build.gradle b/embedded_video_lib/build.gradle index 8dc2857..e63a75c 100644 --- a/embedded_video_lib/build.gradle +++ b/embedded_video_lib/build.gradle @@ -27,12 +27,10 @@ android { } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - //AndroidX - implementation 'androidx.appcompat:appcompat:1.4.1' - implementation 'com.google.android.material:material:1.5.0' - implementation 'androidx.core:core-ktx:1.7.0' + api 'androidx.appcompat:appcompat:1.4.1' + api 'com.google.android.material:material:1.5.0' + api 'androidx.core:core-ktx:1.7.0' //Gson api 'com.google.code.gson:gson:2.8.7' diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/VideoLoadHelper.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/VideoLoadHelper.kt index e4363d8..a62fcd8 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/VideoLoadHelper.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/VideoLoadHelper.kt @@ -41,6 +41,7 @@ internal class VideoLoadHelper( ) { val videoInfoModel = requestModel.videoInfoModel val originalUrl = requestModel.originalUrl + val headers = requestModel.requestHeaders if (videoInfoModel == null) { onError(originalUrl, ERROR_1) @@ -73,7 +74,7 @@ internal class VideoLoadHelper( } val jsonBody = withContext(Dispatchers.IO) { - makeCallGetBody(client, finalUrl) + makeCallGetBody(client, finalUrl, headers) } if (isLogEnabled) { @@ -112,9 +113,19 @@ internal class VideoLoadHelper( } } - private fun makeCallGetBody(client: OkHttpClient, url: String): JsonElement? = + private fun makeCallGetBody( + client: OkHttpClient, + url: String, + headers: Map + ): JsonElement? = runBlocking { - val response = client.newCall(Request.Builder().url(url).build()).execute() + val requestBuilder = Request.Builder().url(url) + + headers.entries.forEach { header -> + requestBuilder.addHeader(header.key, header.value) + } + + val response = client.newCall(requestBuilder.build()).execute() val stringBody = response.body?.string() ?: return@runBlocking null val jsonObject = parseString(stringBody) diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/VideoService.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/VideoService.kt index df50060..37539ba 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/VideoService.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/VideoService.kt @@ -41,6 +41,9 @@ class VideoService private constructor( StreamableVideoInfoModel() ) + val videoPatterns + get() = videoInfoModelsList.map { it.pattern } + inline fun build(block: Builder.() -> Unit) = Builder().apply(block).build() } diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/CoubVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/CoubVideoInfoModel.kt index 691400c..10b60d1 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/CoubVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/CoubVideoInfoModel.kt @@ -11,7 +11,7 @@ open class CoubVideoInfoModel : VideoInfoModel() { //https://regex101.com/r/ZoQVLa/1 override val pattern: String - get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?coub\\.com\\/(?:embed|view|api)\\/([_a-zA-Z0-9]+)[^,;\\s]*" + get() = COUB_PATTERN override val idPattern: String get() = pattern @@ -20,7 +20,7 @@ open class CoubVideoInfoModel : VideoInfoModel() { get() = CoubResponse::class.java override val hostingName: String - get() = "Coub" + get() = COUB_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { incomingUrl ?: return null diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/DailymotionVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/DailymotionVideoInfoModel.kt index ed75ea2..1785c64 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/DailymotionVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/DailymotionVideoInfoModel.kt @@ -9,15 +9,14 @@ open class DailymotionVideoInfoModel : VideoInfoModel() { get() = "https://www.dailymotion.com" override val pattern: String - get() = "(?:http[s]?://)?(?:www\\.)?(?:(?:dailymotion\\.com(?:/embed)?/video)|dai\\.ly)/([a-zA-Z0-9]+)[^,;\\s]*" - + get() = DAILYMOTION_PATTERN override val idPattern: String get() = pattern override val type: Class = DailymotionResponse::class.java override val hostingName: String - get() = "Dailymotion" + get() = DAILYMOTION_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { incomingUrl ?: return null diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/FacebookVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/FacebookVideoInfoModel.kt index 0c2076e..5650da2 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/FacebookVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/FacebookVideoInfoModel.kt @@ -1,27 +1,26 @@ package com.gapps.library.api.models.api -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.facebook.FacebookResponse open class FacebookVideoInfoModel : VideoInfoModel() { override val baseUrl: String - get() = "https://apps.facebook.com" + get() = "https://graph.facebook.com/v15.0/" - //Pattern: https://regex101.com/r/98Nfkr/5 + //Pattern: https://regex101.com/r/98Nfkr/6 override val pattern: String - get() = "(?:http[s]?://)?(?:www.|web.|m.)?(?:facebook|fb)?.com/(?:(?:video.php|watch?/)?\\?v=|.+/videos(?:/.+)?/)(\\d+)[^,;\\s]*" + get() = FACEBOOK_PATTERN override val idPattern: String get() = pattern override val type: Class get() = FacebookResponse::class.java override val hostingName: String - get() = "Facebook" + get() = FACEBOOK_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { val id = parseVideoId(incomingUrl) - return "$baseUrl/plugins/video/oembed.$FORMAT_JSON?$URL=https://www.facebook.com/facebook/videos/$id" + return "$baseUrl/oembed_page?$URL=https://www.facebook.com/facebook/videos/$id" } override fun getPlayLink(videoId: String): String { diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HostConstants.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HostConstants.kt new file mode 100644 index 0000000..668a320 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HostConstants.kt @@ -0,0 +1,19 @@ +@file:JvmName("HostConstants") +package com.gapps.library.api.models.api + +const val COUB_HOST_NAME ="Coub" +const val DAILYMOTION_HOST_NAME = "Dailymotion" +const val FACEBOOK_HOST_NAME ="Facebook" +const val HULU_HOST_NAME = "Hulu" +const val LOOM_HOST_NAME = "Loom" +const val RUTUBE_HOST_NAME = "Rutube" +const val STREAMABLE_HOST_NAME = "Streamable" +const val TED_TALKS_HOST_NAME = "Ted Talks" +const val TIKTOK_HOST_NAME = "TikTok" +const val ULTIMEDIA_HOST_NAME = "Ultimedia" +const val USTREAM_HOST_NAME = "Ustream" +const val VIMEO_HOST_NAME = "Vimeo" +const val VZAAR_HOST_NAME = "Vzaar" +const val WISTIA_HOST_NAME = "Wistia" +const val YOUTUBE_MUSIC_HOST_NAME = "Youtube Music" +const val YOUTUBE_HOST_NAME = "YouTube" \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HuluVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HuluVideoInfoModel.kt index e41d63a..540f296 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HuluVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/HuluVideoInfoModel.kt @@ -12,13 +12,13 @@ open class HuluVideoInfoModel : VideoInfoModel() { //https://regex101.com/r/LORZgZ/2 override val pattern: String - get() = "(?:http[s]?:\\/\\/)?(?:www.)?hulu\\.(?:(?:com\\/\\S*(?:w(?:atch)?|eid)(?:\\/|=)?)|(?:tv\\/))?([a-zA-Z0-9]+)[^,;\\s]*" + get() = HULU_PATTERN override val idPattern: String get() = pattern override val type: Class get() = HuluResponse::class.java override val hostingName: String - get() = "Hulu" + get() = HULU_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { val id = parseVideoId(incomingUrl) diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/LoomVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/LoomVideoInfoModel.kt index 8455d74..1606cec 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/LoomVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/LoomVideoInfoModel.kt @@ -13,13 +13,13 @@ open class LoomVideoInfoModel : VideoInfoModel() { //https://regex101.com/r/0TwCJy/1 override val pattern: String - get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?(?:use)?loom\\.com\\/(?:share|default|api)\\/([_a-zA-Z0-9]+)\\S*" + get() = LOOM_PATTERN override val idPattern: String get() = pattern override val type: Class get() = LoomResponse::class.java override val hostingName: String - get() = "Loom" + get() = LOOM_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { return "$baseUrl/v1/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl" diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RegexCollection.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RegexCollection.kt new file mode 100644 index 0000000..5b66ef4 --- /dev/null +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RegexCollection.kt @@ -0,0 +1,18 @@ +package com.gapps.library.api.models.api + +const val COUB_PATTERN = "(?:http[s]?:\\/\\/)?(?:www)?\\.?coub\\.com\\/(?:embed|view|api)\\/([_a-zA-Z0-9]+)[^,;\\s]*" +const val DAILYMOTION_PATTERN = "(?:http[s]?://)?(?:www\\.)?(?:(?:dailymotion\\.com(?:/embed)?/video)|dai\\.ly)/([a-zA-Z0-9]+)[^,;\\s]*" +const val FACEBOOK_PATTERN = "(?:http[s]?:\\/\\/)?(?:www.|web.|m.)?(?:facebook|fb)?.com\\/(?:(?:video.php|watch)?\\?v=|.+\\/videos(?:\\/.+)?\\/)(\\d+)(?:\\S+)?" +const val HULU_PATTERN = "(?:http[s]?:\\/\\/)?(?:www.)?hulu\\.(?:(?:com\\/\\S*(?:w(?:atch)?|eid)(?:\\/|=)?)|(?:tv\\/))?([a-zA-Z0-9]+)[^,;\\s]*" +const val LOOM_PATTERN = "(?:http[s]?:\\/\\/)?(?:www)?\\.?(?:use)?loom\\.com\\/(?:share|default|api)\\/([_a-zA-Z0-9]+)\\S*" +const val RUTUBE_PATTERN = "(?:http[s]?://)(?:w{3})?(?:player\\.)?rutube\\.ru/video/(?:embed/)?([A-Za-z0-9]+)[^,\\s]*" +const val STREAMABLE_PATTERN = "(?:http[s]?:\\/\\/)?(?:www)?\\.?streamable\\.com\\/([_a-zA-Z0-9]+)\\S*" +const val TED_TALKS_PATTERN = "(?:http[s]?:\\/\\/)?(?:www|embed)?\\.?ted\\.com\\/talks\\/([_a-zA-Z0-9]+)[^,;\\s]*" +const val TIKTOK_PATTERN = "(?:http[s]?:\\/\\/)(?:www.)?(?:m.)?youtu(?:be|.be)?(?:\\.com)?(?:(?:\\w*.?:\\/\\/)?\\w*.?\\w*-?.?\\w*\\/(?:embed|e|v|watch|.*\\/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?\\/?)([\\w\\d_-]{11})[^,;\\s]*" +const val ULTIMEDIA_PATTERN = "(?:http[s]?:\\/\\/)?(?:www)?\\.?ultimedia\\.com\\/(?:deliver|default|api)\\/.*\\/([_a-zA-Z0-9]+)\\S*" +const val USTREAM_PATTERN = "(?:http[s]?:\\/\\/)?(?:www\\.)?ustream.(?:com|tv)\\/(?:recorded|embed|channel)\\/?(?:([0-9]+)|(\\S+))[^,;\\s]*" +const val VIMEO_PATTERN = "(?:http[s]?://)(?:w{3})?(?:player\\.)?vimeo\\.com/(?:[a-z]*/)*([0-9]{6,11})[^,;\\s]*" +const val VZAAR_PATTERN = "(?:http[s]?://)?(?:.+)?vzaar.com/?(?:videos/)?([0-9]+)[^,;\\s]*" +const val WISTIA_PATTERN = "(?:http[s]?:\\/\\/)?(?:.+)?(?:wistia\\.(?:com|net)|wi\\.st)\\/(?:medias|embed|series)\\/(?:iframe\\/?)?(?:\\S+\\?\\S*wvideoid=)?([a-zA-Z0-9]+)[^,;\\s]*" +const val YOUTUBE_MUSIC_PATTERN = "(?:http[s]?:\\/\\/)(?:www.)?(?:m.)?music.youtu(?:be|.be)?(?:\\.com)?(?:(?:\\w*.?:\\/\\/)?\\w*.?\\w*-?.?\\w*\\/(?:embed|e|v|watch|.*\\/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?\\/?)([\\w\\d_-]{11})[^,;\\s]*" +const val YOUTUBE_PATTERN = "(?:http[s]?:\\/\\/)(?:www.)?(?:m.)?youtu(?:be|.be)?(?:\\.com)?(?:(?:\\w*.?:\\/\\/)?\\w*.?\\w*-?.?\\w*\\/(?:embed|e|v|watch|.*\\/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?\\/?)([\\w\\d_-]{11})[^,;\\s]*" \ No newline at end of file diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RutubeVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RutubeVideoInfoModel.kt index 684df5f..5a53bc5 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RutubeVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/RutubeVideoInfoModel.kt @@ -10,13 +10,13 @@ open class RutubeVideoInfoModel : VideoInfoModel() { override val baseUrl: String get() = "http://rutube.ru" override val pattern: String - get() = "(?:http[s]?://)(?:w{3})?(?:player\\.)?rutube\\.ru/video/(?:embed/)?([A-Za-z0-9]+)[^,\\s]*" + get() = RUTUBE_PATTERN override val idPattern: String get() = pattern override val type: Class get() = RutubeResponse::class.java override val hostingName: String - get() = "Rutube" + get() = RUTUBE_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { val id = parseVideoId(incomingUrl) ?: return null diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/StreamableVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/StreamableVideoInfoModel.kt index 66a2f8b..87adf8b 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/StreamableVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/StreamableVideoInfoModel.kt @@ -8,13 +8,13 @@ class StreamableVideoInfoModel : VideoInfoModel() { override val baseUrl: String get() = "https://api.streamable.com" override val pattern: String - get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?streamable\\.com\\/([_a-zA-Z0-9]+)\\S*" + get() = STREAMABLE_PATTERN override val idPattern: String get() = pattern override val type: Class get() = StreamableResponse::class.java override val hostingName: String - get() = "Streamable" + get() = STREAMABLE_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { return "$baseUrl/oembed.json?$URL=$incomingUrl" diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TedTalksVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TedTalksVideoInfoModel.kt index c4eb859..f670dfe 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TedTalksVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TedTalksVideoInfoModel.kt @@ -9,13 +9,13 @@ open class TedTalksVideoInfoModel : VideoInfoModel() { override val baseUrl: String get() = "https://www.ted.com" override val pattern: String - get() = "(?:http[s]?:\\/\\/)?(?:www|embed)?\\.?ted\\.com\\/talks\\/([_a-zA-Z0-9]+)[^,;\\s]*" + get() = TED_TALKS_PATTERN override val idPattern: String get() = pattern override val type: Class get() = TedTalksResponse::class.java override val hostingName: String - get() = "Ted Talks" + get() = TED_TALKS_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { return "$baseUrl/services/v1/oembed.$FORMAT_JSON?$URL=$incomingUrl" diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TikTokVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TikTokVideoInfoModel.kt index 3f833fb..ccc0a25 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TikTokVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/TikTokVideoInfoModel.kt @@ -13,13 +13,13 @@ open class TikTokVideoInfoModel : VideoInfoModel() { //https://regex101.com/r/nJzgG0/1 override val pattern: String - get() = "(?:http[s]?:\\/\\/)(?:www.)?(?:m.)?youtu(?:be|.be)?(?:\\.com)?(?:(?:\\w*.?:\\/\\/)?\\w*.?\\w*-?.?\\w*\\/(?:embed|e|v|watch|.*\\/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?\\/?)([\\w\\d_-]{11})[^,;\\s]*" + get() = TIKTOK_PATTERN override val idPattern: String get() = pattern override val type: Class get() = TikTokResponse::class.java override val hostingName: String - get() = "YouTube" + get() = TIKTOK_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { val id = parseVideoId(incomingUrl) diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UltimediaVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UltimediaVideoInfoModel.kt index 4be9922..2c52406 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UltimediaVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UltimediaVideoInfoModel.kt @@ -12,13 +12,13 @@ class UltimediaVideoInfoModel : VideoInfoModel() { //https://regex101.com/r/2AsrOc/1 override val pattern: String - get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?ultimedia\\.com\\/(?:deliver|default|api)\\/.*\\/([_a-zA-Z0-9]+)\\S*" + get() = ULTIMEDIA_PATTERN override val idPattern: String get() = pattern override val type: Class get() = UltimediaResponse::class.java override val hostingName: String - get() = "Ultimedia" + get() = ULTIMEDIA_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { return "$baseUrl/api/search/oembed?$FORMAT=$FORMAT_JSON&$URL=$incomingUrl" diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UstreamVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UstreamVideoInfoModel.kt index f78bb80..79b41fa 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UstreamVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/UstreamVideoInfoModel.kt @@ -11,13 +11,13 @@ open class UstreamVideoInfoModel : VideoInfoModel() { //https://regex101.com/r/E0PMAV/2 override val pattern: String - get() = "(?:http[s]?:\\/\\/)?(?:www\\.)?ustream.(?:com|tv)\\/(?:recorded|embed|channel)\\/?(?:([0-9]+)|(\\S+))[^,;\\s]*" + get() = USTREAM_PATTERN override val idPattern: String get() = pattern override val type: Class get() = UstreamResponse::class.java override val hostingName: String - get() = "Ustream" + get() = USTREAM_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { incomingUrl ?: return null diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VimeoVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VimeoVideoInfoModel.kt index 2d48ef0..b22e1a8 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VimeoVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VimeoVideoInfoModel.kt @@ -8,13 +8,13 @@ open class VimeoVideoInfoModel : VideoInfoModel() { override val baseUrl: String get() = "http://vimeo.com" override val pattern: String - get() = "(?:http[s]?://)(?:w{3})?(?:player\\.)?vimeo\\.com/(?:[a-z]*/)*([0-9]{6,11})[^,;\\s]*" + get() = VIMEO_PATTERN override val idPattern: String get() = pattern override val type: Class get() = VimeoResponse::class.java override val hostingName: String - get() = "Vimeo" + get() = VIMEO_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { val id = parseVideoId(incomingUrl) ?: return null diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VzaarVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VzaarVideoInfoModel.kt index d2bbcac..80e1781 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VzaarVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/VzaarVideoInfoModel.kt @@ -8,13 +8,13 @@ open class VzaarVideoInfoModel : VideoInfoModel() { override val baseUrl: String get() = "https://app.vzaar.com" override val pattern: String - get() = "(?:http[s]?://)?(?:.+)?vzaar.com/?(?:videos/)?([0-9]+)[^,;\\s]*" + get() = VZAAR_PATTERN override val idPattern: String get() = pattern override val type: Class get() = VzaarResponse::class.java override val hostingName: String - get() = "Vzaar" + get() = VZAAR_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { val id = parseVideoId(incomingUrl) ?: return null diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/WistiaVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/WistiaVideoInfoModel.kt index 76eb188..70eb912 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/WistiaVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/WistiaVideoInfoModel.kt @@ -8,13 +8,13 @@ open class WistiaVideoInfoModel : VideoInfoModel() { override val baseUrl: String get() = "https://fast.wistia.net" override val pattern: String - get() = "(?:http[s]?:\\/\\/)?(?:.+)?(?:wistia\\.(?:com|net)|wi\\.st)\\/(?:medias|embed|series)\\/(?:iframe\\/?)?(?:\\S+\\?\\S*wvideoid=)?([a-zA-Z0-9]+)[^,;\\s]*" + get() = WISTIA_PATTERN override val idPattern: String get() = pattern override val type: Class get() = WistiaResponse::class.java override val hostingName: String - get() = "Wistia" + get() = WISTIA_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { incomingUrl ?: return null diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeMusicVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeMusicVideoInfoModel.kt index 1377f06..a84f484 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeMusicVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeMusicVideoInfoModel.kt @@ -10,13 +10,13 @@ open class YoutubeMusicVideoInfoModel : VideoInfoModel() { override val baseUrl: String get() = "https://www.youtube.com" override val pattern: String - get() = "(?:http[s]?:\\/\\/)(?:www.)?(?:m.)?music.youtu(?:be|.be)?(?:\\.com)?(?:(?:\\w*.?:\\/\\/)?\\w*.?\\w*-?.?\\w*\\/(?:embed|e|v|watch|.*\\/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?\\/?)([\\w\\d_-]{11})[^,;\\s]*" + get() = YOUTUBE_MUSIC_PATTERN override val idPattern: String get() = pattern override val type: Class get() = YoutubeResponse::class.java override val hostingName: String - get() = "YouTube Music" + get() = YOUTUBE_MUSIC_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { val id = parseVideoId(incomingUrl) diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeVideoInfoModel.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeVideoInfoModel.kt index ddb7d06..924e5e6 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeVideoInfoModel.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/YoutubeVideoInfoModel.kt @@ -12,13 +12,13 @@ open class YoutubeVideoInfoModel : VideoInfoModel() { //https://regex101.com/r/nJzgG0/1 override val pattern: String - get() = "(?:http[s]?:\\/\\/)(?:www.)?(?:m.)?youtu(?:be|.be)?(?:\\.com)?(?:(?:\\w*.?:\\/\\/)?\\w*.?\\w*-?.?\\w*\\/(?:embed|e|v|watch|.*\\/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?\\/?)([\\w\\d_-]{11})[^,;\\s]*" + get() = YOUTUBE_PATTERN override val idPattern: String get() = pattern override val type: Class get() = YoutubeResponse::class.java override val hostingName: String - get() = "YouTube" + get() = YOUTUBE_HOST_NAME override fun getInfoUrl(incomingUrl: String?): String? { val id = parseVideoId(incomingUrl) diff --git a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/builder/EmbeddingRequestBuilder.kt b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/builder/EmbeddingRequestBuilder.kt index 109a461..fccb3a1 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/builder/EmbeddingRequestBuilder.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/api/models/api/builder/EmbeddingRequestBuilder.kt @@ -3,20 +3,101 @@ package com.gapps.library.api.models.api.builder import com.gapps.library.api.models.api.base.VideoInfoModel class EmbeddingRequest private constructor( - val originalUrl: String, - var videoInfoModel: VideoInfoModel<*>? = null + var originalUrl: String = "", + var videoInfoModel: VideoInfoModel<*>? = null, + private var headers: Headers = emptyMap() ) { + companion object { + inline fun build(block: Builder.() -> Unit) = + Builder().apply(block).build() + } + + val requestHeaders: Map + get() { + val headersMap = mutableMapOf() + + val hostName = videoInfoModel?.hostingName + + hostName?.let { headers[it] }?.run { + headersMap.putAll(this) + } + + headers[Builder.HostBuilder.DEFAULT]?.run { + headersMap.putAll(this) + } + + return headersMap + } + + @EmbeddingRequestBuilderDsl class Builder { - private var url: String? = null - private var videoInfoModel: VideoInfoModel<*>? = null + private val request: EmbeddingRequest = EmbeddingRequest() + private val hostBuilder = HostBuilder() - fun setUrl(url: String) = apply { this.url = url } + fun setUrl(url: String) = apply { request.originalUrl = url } fun setVideoInfoModel(videoInfoModel: VideoInfoModel<*>) = - apply { this.videoInfoModel = videoInfoModel } + apply { request.videoInfoModel = videoInfoModel } + + fun headers(headersBuilder: HostBuilder.() -> Unit) = apply { + this.hostBuilder.apply(headersBuilder) + } fun build(): EmbeddingRequest { - return EmbeddingRequest(url!!) + return request.apply { + headers = hostBuilder.headers + } + } + + @HostBuilderDsl + @EmbeddingRequestBuilderDsl + class HostBuilder { + companion object { + const val DEFAULT = "default" + } + + private val builders = mutableMapOf() + + val headers: Headers + get() = builders.map { it.key to it.value.headers }.toMap() + + fun host(hostName: String, builder: HeadersBuilder.() -> Unit) = apply { + val builderForHost = getHeadersBuilder(hostName) + + builderForHost.apply(builder) + } + + fun add(key: String, value: String) = apply { + getHeadersBuilder(DEFAULT).add(key, value) + } + + fun addAll(headers: Map) = apply { + getHeadersBuilder(DEFAULT).addAll(headers) + } + + private fun getHeadersBuilder(hostName: String) = + builders[hostName] ?: HeadersBuilder() + } + + @HostBuilderDsl + class HeadersBuilder { + val headers = mutableMapOf() + + fun add(key: String, value: String) = apply { + this.headers[key] = value + } + + fun addAll(headers: Map) = apply { + this.headers.putAll(headers) + } } } -} \ No newline at end of file +} + +typealias Headers = Map> + +@DslMarker +annotation class HostBuilderDsl + +@DslMarker +annotation class EmbeddingRequestBuilderDsl diff --git a/embedded_video_lib/src/main/java/com/gapps/library/ui/bottom_menu/BottomVideoController.kt b/embedded_video_lib/src/main/java/com/gapps/library/ui/bottom_menu/BottomVideoController.kt index 1a52fcb..d97e353 100644 --- a/embedded_video_lib/src/main/java/com/gapps/library/ui/bottom_menu/BottomVideoController.kt +++ b/embedded_video_lib/src/main/java/com/gapps/library/ui/bottom_menu/BottomVideoController.kt @@ -2,10 +2,7 @@ package com.gapps.library.ui.bottom_menu import android.annotation.SuppressLint import android.content.Context -import android.graphics.Bitmap -import android.graphics.BitmapFactory -import android.graphics.PorterDuff -import android.graphics.PorterDuffColorFilter +import android.graphics.* import android.os.Build import android.util.Log import android.view.LayoutInflater @@ -19,7 +16,7 @@ import android.webkit.WebViewClient import android.widget.FrameLayout import android.widget.LinearLayout import android.widget.TextView -import androidx.annotation.ColorRes +import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.appcompat.widget.AppCompatImageButton @@ -35,9 +32,9 @@ import com.gapps.library.utils.getWidth class BottomVideoController private constructor( private val context: Context?, private val listener: Listener?, - @ColorRes private val titleColor: Int, - @ColorRes private val textColor: Int, - @ColorRes private val backgroundColor: Int, + @ColorInt private val titleColor: Int, + @ColorInt private val textColor: Int, + @ColorInt private val backgroundColor: Int, private val url: String?, private val titleText: String?, private val hostText: String?, @@ -48,9 +45,9 @@ class BottomVideoController private constructor( @DrawableRes private val centerButtonIcon: Int, @StringRes private val leftButtonText: Int, @StringRes private val rightButtonText: Int, - @ColorRes private val leftButtonTextColor: Int, - @ColorRes private val rightButtonTextColor: Int, - @ColorRes private val centerButtonIconTint: Int + @ColorInt private val leftButtonTextColor: Int, + @ColorInt private val rightButtonTextColor: Int, + @ColorInt private val centerButtonIconTint: Int ) { companion object { var isVisible = false @@ -110,19 +107,17 @@ class BottomVideoController private constructor( controlPanel.visibility = if (isBottomControlPanelVisible) View.VISIBLE else View.GONE title.apply { - this.setTextColor(ContextCompat.getColor(this.context, titleColor)) + this.setTextColor(titleColor) this.text = titleText } - val textColorInt = ContextCompat.getColor(this.context, textColor) - videoServiceType.apply { - this.setTextColor(textColorInt) + this.setTextColor(textColor) this.text = hostText } leftButton.apply { - this.setTextColor(ContextCompat.getColor(context, leftButtonTextColor)) + this.setTextColor(leftButtonTextColor) this.setText(leftButtonText) this.setOnClickListener { @@ -131,7 +126,7 @@ class BottomVideoController private constructor( } rightButton.apply { - this.setTextColor(ContextCompat.getColor(context, rightButtonTextColor)) + this.setTextColor(rightButtonTextColor) this.setText(rightButtonText) this.setOnClickListener { @@ -144,7 +139,7 @@ class BottomVideoController private constructor( centerButton.apply { this.setImageResource(centerButtonIcon) this.setColorFilter( - ContextCompat.getColor(context, centerButtonIconTint), + centerButtonIconTint, PorterDuff.Mode.SRC_IN ) @@ -154,10 +149,10 @@ class BottomVideoController private constructor( } menuContainer.apply { - this.setBackgroundColor(ContextCompat.getColor(this.context, backgroundColor)) + this.setBackgroundColor(backgroundColor) } - val outlineColor = ColorUtils.setAlphaComponent(textColorInt, (255 * .1).toInt()) + val outlineColor = ColorUtils.setAlphaComponent(textColor, (255 * .1).toInt()) controlPanelOutline.background.colorFilter = PorterDuffColorFilter(outlineColor, PorterDuff.Mode.SRC_IN) @@ -178,7 +173,7 @@ class BottomVideoController private constructor( } videoView.apply { - setBackgroundColor(ContextCompat.getColor(this.context, backgroundColor)) + setBackgroundColor(backgroundColor) layoutParams.apply { this.width = videoViewWidth @@ -265,16 +260,16 @@ class BottomVideoController private constructor( var listener: Listener? = null private set - @ColorRes - var titleColor = R.color.vna_color_video_title_text + @ColorInt + var titleColor = 0x1d1d26 private set - @ColorRes - var textColor = R.color.vna_color_video_title_text + @ColorInt + var textColor = Color.parseColor("#80000000") private set - @ColorRes - var backgroundColor = android.R.color.white + @ColorInt + var backgroundColor = Color.WHITE private set var isBottomControlPanelVisible: Boolean = true @@ -302,16 +297,16 @@ class BottomVideoController private constructor( var centerButtonIcon = R.drawable.ic_vna_content_copy private set - @ColorRes - var centerButtonIconTint = R.color.vna_color_video_title_text + @ColorInt + var centerButtonIconTint = 0x1d1d26 private set - @ColorRes - var rightButtonTextColor = R.color.vna_color_video_title_text + @ColorInt + var rightButtonTextColor = 0x1d1d26 private set - @ColorRes - var leftButtonTextColor = R.color.vna_color_video_title_text + @ColorInt + var leftButtonTextColor = 0x1d1d26 private set @StringRes @@ -334,16 +329,16 @@ class BottomVideoController private constructor( fun setListener(listener: Listener) = apply { this.listener = listener } //Theme - fun setTitleColor(@ColorRes color: Int) = apply { this.titleColor = color } - fun setTextColor(@ColorRes color: Int) = apply { this.textColor = color } - fun setLeftButtonTextColor(@ColorRes color: Int) = + fun setTitleColor(@ColorInt color: Int) = apply { this.titleColor = color } + fun setTextColor(@ColorInt color: Int) = apply { this.textColor = color } + fun setLeftButtonTextColor(@ColorInt color: Int) = apply { this.leftButtonTextColor = color } - fun setRightButtonTextColor(@ColorRes color: Int) = + fun setRightButtonTextColor(@ColorInt color: Int) = apply { this.rightButtonTextColor = color } - fun setBackgroundColor(@ColorRes color: Int) = apply { this.backgroundColor = color } - fun setCenterButtonIconTint(@ColorRes color: Int) = + fun setBackgroundColor(@ColorInt color: Int) = apply { this.backgroundColor = color } + fun setCenterButtonIconTint(@ColorInt color: Int) = apply { this.centerButtonIconTint = color } fun setCenterButtonIcon(@DrawableRes resource: Int) =