Skip to content

Commit 3ba82a1

Browse files
committed
Streamable added
1 parent b825eaf commit 3ba82a1

File tree

14 files changed

+193
-100
lines changed

14 files changed

+193
-100
lines changed

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ android {
2727
dependencies {
2828
implementation fileTree(dir: 'libs', include: ['*.jar'])
2929
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
30-
implementation 'androidx.appcompat:appcompat:1.1.0'
31-
implementation 'androidx.core:core-ktx:1.2.0'
30+
implementation 'androidx.appcompat:appcompat:1.2.0'
31+
implementation 'androidx.core:core-ktx:1.3.1'
3232

33-
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
34-
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
33+
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
34+
implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2'
3535

3636
//Gson
3737
implementation 'com.google.code.gson:gson:2.8.6'
3838
implementation(project(':library'))
3939

4040
implementation 'androidx.recyclerview:recyclerview:1.1.0'
4141
implementation 'com.squareup.picasso:picasso:2.71828'
42-
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
42+
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
4343
}

app/src/main/java/com/gapps/videonoapi/ui/main/adapters/VideoAdapter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class VideoAdapter(private val context: Context, private val videoService: Video
173173
"Ted Talks" -> R.drawable.ted_talks
174174
"Coub" -> R.drawable.ic_coub
175175
"Ultimedia" -> R.drawable.ultimedia
176+
"Streamable" -> R.drawable.streamable
176177
else -> R.drawable.ic_video
177178
}
178179

21.9 KB
Loading

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.61'
4+
ext.kotlin_version = '1.4.0'
55

66
repositories {
77
google()

library/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44
android {
55
compileSdkVersion 29
6-
buildToolsVersion "29.0.2"
6+
buildToolsVersion "29.0.3"
77

88
defaultConfig {
99
minSdkVersion 19
@@ -33,18 +33,18 @@ dependencies {
3333
//AndroidX
3434
implementation 'androidx.appcompat:appcompat:1.1.0'
3535
implementation 'com.google.android.material:material:1.1.0'
36-
implementation 'androidx.core:core-ktx:1.2.0'
36+
implementation 'androidx.core:core-ktx:1.3.0'
3737

3838
//Gson
3939
implementation 'com.google.code.gson:gson:2.8.6'
4040
//Coroutines
41-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2'
41+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7'
4242

4343
//Retrofit
44-
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
44+
implementation 'com.squareup.okhttp3:okhttp:4.7.2'
4545

4646
//Test
47-
testImplementation 'junit:junit:4.12'
47+
testImplementation 'junit:junit:4.13'
4848
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
4949
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
5050
}

library/src/main/java/com/gapps/library/api/VideoLoadHelper.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal class VideoLoadHelper(
3030

3131
private val databaseContext = job + Dispatchers.IO
3232

33-
private var gson = GsonBuilder()
33+
private val gson = GsonBuilder()
3434
.setLenient()
3535
.setPrettyPrinting()
3636
.create()
@@ -82,8 +82,13 @@ internal class VideoLoadHelper(
8282
return@launch
8383
}
8484

85-
val result = (gson.fromJson(jsonBody, videoInfoModel.type) as BaseVideoResponse)
86-
.toPreview(originalUrl, playLink, videoInfoModel.hostingName, videoId)
85+
val result = fromJson(jsonBody, videoInfoModel.type)
86+
.toPreview(
87+
url = originalUrl,
88+
linkToPlay = playLink,
89+
hostingName = videoInfoModel.hostingName,
90+
videoId = videoId
91+
)
8792

8893
onSuccess.invoke(result)
8994

@@ -102,17 +107,15 @@ internal class VideoLoadHelper(
102107
}
103108
}
104109

105-
private suspend fun makeCallGetBody(client: OkHttpClient, url: String): JsonElement? {
106-
return withContext(Dispatchers.IO) {
107-
val response = client.newCall(Request.Builder().url(url).build()).execute()
108-
val stringBody = response.body()?.string() ?: return@withContext null
109-
val jsonObject = parseString(stringBody)
110+
private suspend fun makeCallGetBody(client: OkHttpClient, url: String) = withContext(Dispatchers.IO) {
111+
val response = client.newCall(Request.Builder().url(url).build()).execute()
112+
val stringBody = response.body?.string() ?: return@withContext null
113+
val jsonObject = parseString(stringBody)
110114

111-
return@withContext if (jsonObject.isJsonArray) {
112-
jsonObject.asJsonArray[0]
113-
} else {
114-
jsonObject
115-
}
115+
return@withContext if (jsonObject.isJsonArray) {
116+
jsonObject.asJsonArray[0]
117+
} else {
118+
jsonObject
116119
}
117120
}
118121

library/src/main/java/com/gapps/library/api/models/api/StreamableVideoInfoModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import com.gapps.library.api.models.video.streamable.StreamableResponse
77
class StreamableVideoInfoModel:VideoInfoModel<StreamableResponse>() {
88
override val baseUrl: String
99
get() = "https://api.streamable.com"
10-
//https://regex101.com/r/2AsrOc/1
1110
override val pattern: String
1211
get() = "(?:http[s]?:\\/\\/)?(?:www)?\\.?streamable\\.com\\/([_a-zA-Z0-9]+)\\S*"
1312
override val idPattern: String
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.gapps.library.api.models.api
2+
3+
import com.gapps.library.api.FORMAT
4+
import com.gapps.library.api.FORMAT_JSON
5+
import com.gapps.library.api.URL
6+
import com.gapps.library.api.models.api.base.VideoInfoModel
7+
import com.gapps.library.api.models.video.tiktok.TikTokResponse
8+
import com.gapps.library.api.models.video.youtube.YoutubeResponse
9+
10+
open class TikTokVideoInfoModel : VideoInfoModel<TikTokResponse>() {
11+
override val baseUrl: String
12+
get() = "https://www.tiktok.com"
13+
//https://regex101.com/r/nJzgG0/1
14+
override val pattern: String
15+
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]*"
16+
override val idPattern: String
17+
get() = pattern
18+
override val type: Class<TikTokResponse>
19+
get() = TikTokResponse::class.java
20+
override val hostingName: String
21+
get() = "YouTube"
22+
23+
override fun getInfoUrl(incomingUrl: String?): String? {
24+
val id = parseVideoId(incomingUrl)
25+
26+
return "$baseUrl/oembed?$FORMAT=$FORMAT_JSON&$URL=https://www.youtube.com/watch?v=$id"
27+
}
28+
29+
override fun getPlayLink(videoId: String): String {
30+
return "https://www.youtube.com/embed/${videoId}?autoplay=1&vq=small"
31+
}
32+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.gapps.library.api.models.video.tiktok
2+
3+
4+
import com.gapps.library.api.models.video.VideoPreviewModel
5+
import com.gapps.library.api.models.video.base.BaseVideoResponse
6+
import com.google.gson.annotations.SerializedName
7+
8+
data class TikTokResponse(
9+
@SerializedName("version")
10+
val version: String = "",
11+
@SerializedName("type")
12+
val type: String = "",
13+
@SerializedName("title")
14+
val title: String = "",
15+
@SerializedName("author_url")
16+
val authorUrl: String = "",
17+
@SerializedName("author_name")
18+
val authorName: String = "",
19+
@SerializedName("width")
20+
val width: String = "",
21+
@SerializedName("height")
22+
val height: String = "",
23+
@SerializedName("html")
24+
val html: String = "",
25+
@SerializedName("thumbnail_width")
26+
val thumbnailWidth: Int = 0,
27+
@SerializedName("thumbnail_height")
28+
val thumbnailHeight: Int = 0,
29+
@SerializedName("thumbnail_url")
30+
val thumbnailUrl: String = "",
31+
@SerializedName("provider_url")
32+
val providerUrl: String = "",
33+
@SerializedName("provider_name")
34+
val providerName: String = ""
35+
) : BaseVideoResponse {
36+
override fun toPreview(url: String?, linkToPlay: String, hostingName: String, videoId: String): VideoPreviewModel {
37+
return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply {
38+
this.thumbnailUrl = this@TikTokResponse.thumbnailUrl
39+
this.videoTitle = this@TikTokResponse.authorName
40+
this.width = this@TikTokResponse.width.toInt()
41+
this.height = this@TikTokResponse.height.toInt()
42+
}
43+
}
44+
45+
}

library/src/main/java/com/gapps/library/api/models/video/ultimedia/UltimediaResponse.kt

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,39 @@ import com.gapps.library.api.models.video.base.BaseVideoResponse
66
import com.google.gson.annotations.SerializedName
77

88
data class UltimediaResponse(
9-
@SerializedName("version")
10-
val version: String = "",
11-
@SerializedName("type")
12-
val type: String = "",
13-
@SerializedName("title")
14-
val title: String = "",
15-
@SerializedName("description")
16-
val description: String = "",
17-
@SerializedName("html")
18-
val html: String = "",
19-
@SerializedName("width")
20-
val width: String = "",
21-
@SerializedName("height")
22-
val height: String = "",
23-
@SerializedName("thumbnail_url")
24-
val thumbnailUrl: String = "",
25-
@SerializedName("thumbnail_width")
26-
val thumbnailWidth: String = "",
27-
@SerializedName("thumbnail_height")
28-
val thumbnailHeight: String = "",
29-
@SerializedName("provider_name")
30-
val providerName: String = "",
31-
@SerializedName("provider_url")
32-
val providerUrl: String = "",
33-
@SerializedName("author_name")
34-
val authorName: String = ""
35-
): BaseVideoResponse{
36-
override fun toPreview(url: String?, linkToPlay: String, hostingName: String, videoId: String): VideoPreviewModel {
37-
return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply {
38-
this.thumbnailUrl = this@UltimediaResponse.thumbnailUrl
39-
this.videoTitle = this@UltimediaResponse.authorName
40-
this.width = this@UltimediaResponse.width.toInt()
41-
this.height = this@UltimediaResponse.height.toInt()
42-
}
43-
}
9+
@SerializedName("version")
10+
val version: String = "",
11+
@SerializedName("type")
12+
val type: String = "",
13+
@SerializedName("title")
14+
val title: String = "",
15+
@SerializedName("description")
16+
val description: String = "",
17+
@SerializedName("html")
18+
val html: String = "",
19+
@SerializedName("width")
20+
val width: String = "",
21+
@SerializedName("height")
22+
val height: String = "",
23+
@SerializedName("thumbnail_url")
24+
val thumbnailUrl: String = "",
25+
@SerializedName("thumbnail_width")
26+
val thumbnailWidth: String = "",
27+
@SerializedName("thumbnail_height")
28+
val thumbnailHeight: String = "",
29+
@SerializedName("provider_name")
30+
val providerName: String = "",
31+
@SerializedName("provider_url")
32+
val providerUrl: String = "",
33+
@SerializedName("author_name")
34+
val authorName: String = ""
35+
) : BaseVideoResponse {
36+
override fun toPreview(url: String?, linkToPlay: String, hostingName: String, videoId: String): VideoPreviewModel {
37+
return VideoPreviewModel(url, linkToPlay, hostingName, videoId).apply {
38+
this.thumbnailUrl = this@UltimediaResponse.thumbnailUrl
39+
this.videoTitle = this@UltimediaResponse.authorName
40+
this.width = this@UltimediaResponse.width.toInt()
41+
this.height = this@UltimediaResponse.height.toInt()
42+
}
43+
}
4444
}

0 commit comments

Comments
 (0)