Skip to content

Commit

Permalink
Streamable added
Browse files Browse the repository at this point in the history
  • Loading branch information
TalbotGooday committed Sep 8, 2020
1 parent b825eaf commit 3ba82a1
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 100 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.1'

implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2'

//Gson
implementation 'com.google.code.gson:gson:2.8.6'
implementation(project(':library'))

implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class VideoAdapter(private val context: Context, private val videoService: Video
"Ted Talks" -> R.drawable.ted_talks
"Coub" -> R.drawable.ic_coub
"Ultimedia" -> R.drawable.ultimedia
"Streamable" -> R.drawable.streamable
else -> R.drawable.ic_video
}

Expand Down
Binary file added app/src/main/res/drawable-xxhdpi/streamable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.4.0'

repositories {
google()
Expand Down
10 changes: 5 additions & 5 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
buildToolsVersion "29.0.3"

defaultConfig {
minSdkVersion 19
Expand Down Expand Up @@ -33,18 +33,18 @@ dependencies {
//AndroidX
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.3.0'

//Gson
implementation 'com.google.code.gson:gson:2.8.6'
//Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7'

//Retrofit
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.squareup.okhttp3:okhttp:4.7.2'

//Test
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
29 changes: 16 additions & 13 deletions library/src/main/java/com/gapps/library/api/VideoLoadHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class VideoLoadHelper(

private val databaseContext = job + Dispatchers.IO

private var gson = GsonBuilder()
private val gson = GsonBuilder()
.setLenient()
.setPrettyPrinting()
.create()
Expand Down Expand Up @@ -82,8 +82,13 @@ internal class VideoLoadHelper(
return@launch
}

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

onSuccess.invoke(result)

Expand All @@ -102,17 +107,15 @@ internal class VideoLoadHelper(
}
}

private suspend fun makeCallGetBody(client: OkHttpClient, url: String): JsonElement? {
return withContext(Dispatchers.IO) {
val response = client.newCall(Request.Builder().url(url).build()).execute()
val stringBody = response.body()?.string() ?: return@withContext null
val jsonObject = parseString(stringBody)
private suspend fun makeCallGetBody(client: OkHttpClient, url: String) = withContext(Dispatchers.IO) {
val response = client.newCall(Request.Builder().url(url).build()).execute()
val stringBody = response.body?.string() ?: return@withContext null
val jsonObject = parseString(stringBody)

return@withContext if (jsonObject.isJsonArray) {
jsonObject.asJsonArray[0]
} else {
jsonObject
}
return@withContext if (jsonObject.isJsonArray) {
jsonObject.asJsonArray[0]
} else {
jsonObject
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.gapps.library.api.models.video.streamable.StreamableResponse
class StreamableVideoInfoModel:VideoInfoModel<StreamableResponse>() {
override val baseUrl: String
get() = "https://api.streamable.com"
//https://regex101.com/r/2AsrOc/1
override val pattern: String
get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?streamable\\.com\\/([_a-zA-Z0-9]+)\\S*"
override val idPattern: String
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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.tiktok.TikTokResponse
import com.gapps.library.api.models.video.youtube.YoutubeResponse

open class TikTokVideoInfoModel : VideoInfoModel<TikTokResponse>() {
override val baseUrl: String
get() = "https://www.tiktok.com"
//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]*"
override val idPattern: String
get() = pattern
override val type: Class<TikTokResponse>
get() = TikTokResponse::class.java
override val hostingName: String
get() = "YouTube"

override fun getInfoUrl(incomingUrl: String?): String? {
val id = parseVideoId(incomingUrl)

return "$baseUrl/oembed?$FORMAT=$FORMAT_JSON&$URL=https://www.youtube.com/watch?v=$id"
}

override fun getPlayLink(videoId: String): String {
return "https://www.youtube.com/embed/${videoId}?autoplay=1&vq=small"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.gapps.library.api.models.video.tiktok


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 TikTokResponse(
@SerializedName("version")
val version: String = "",
@SerializedName("type")
val type: String = "",
@SerializedName("title")
val title: String = "",
@SerializedName("author_url")
val authorUrl: String = "",
@SerializedName("author_name")
val authorName: String = "",
@SerializedName("width")
val width: String = "",
@SerializedName("height")
val height: String = "",
@SerializedName("html")
val html: String = "",
@SerializedName("thumbnail_width")
val thumbnailWidth: Int = 0,
@SerializedName("thumbnail_height")
val thumbnailHeight: Int = 0,
@SerializedName("thumbnail_url")
val thumbnailUrl: String = "",
@SerializedName("provider_url")
val providerUrl: String = "",
@SerializedName("provider_name")
val providerName: String = ""
) : BaseVideoResponse {
override fun toPreview(url: String?, linkToPlay: String, hostingName: String, videoId: String): VideoPreviewModel {
return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply {
this.thumbnailUrl = this@TikTokResponse.thumbnailUrl
this.videoTitle = this@TikTokResponse.authorName
this.width = this@TikTokResponse.width.toInt()
this.height = this@TikTokResponse.height.toInt()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ 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()
}
}
@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()
}
}
}
14 changes: 6 additions & 8 deletions library/src/main/java/com/gapps/library/cache/DatabaseWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import android.database.sqlite.SQLiteOpenHelper
import android.util.Log

class DatabaseWrapper(context: Context?) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
companion object {
private const val TAG = "DatabaseWrapper"
private const val DATABASE_NAME = "vna.db"
private const val DATABASE_VERSION = 1
}

/**
* Called if the database named DATABASE_NAME doesn't exist in order to create it.
*/
override fun onCreate(sqLiteDatabase: SQLiteDatabase) {
Log.i(TAG, "Creating database [$DATABASE_NAME v.$DATABASE_VERSION]...\n$SQL_CREATE_TABLE")
sqLiteDatabase.execSQL(SQL_CREATE_TABLE)

// sqLiteDatabase.close()
}

/**
Expand All @@ -24,10 +28,4 @@ class DatabaseWrapper(context: Context?) : SQLiteOpenHelper(context, DATABASE_NA
sqLiteDatabase.execSQL(SQL_DROP_TABLE)
onCreate(sqLiteDatabase)
}

companion object {
private const val TAG = "DatabaseWrapper"
private const val DATABASE_NAME = "vna.db"
private const val DATABASE_VERSION = 1
}
}
Loading

0 comments on commit 3ba82a1

Please sign in to comment.