Skip to content

Commit 53265ee

Browse files
committed
Bug fixes and other improvements
1 parent 38c01bd commit 53265ee

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

app/src/main/java/com/gapps/videonoapi/MainActivity.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class MainActivity : AppCompatActivity() {
3131
"https://www.facebook.com/UFC/videos/410056389868335/",
3232
"https://www.dailymotion.com/video/x5sxbmb",
3333
"https://dave.wistia.com/medias/0k5h1g1chs/",
34-
"https://vzaar.com/videos/401431",
35-
"https://www.youtube.com/watch?v=Gqr14W91mdcjsjd"
34+
"https://vzaar.com/videos/401431"
3635
)
3736

3837
override fun onCreate(savedInstanceState: Bundle?) {

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.gapps.library.api
22

3-
const val YOUTUBE_PATTERN = "(http(s)?:\\/\\/)?((w){3}.)?(m.)?(music.)?youtu(be|.be)?(\\.com)?\\/.*"
4-
const val YOUTUBE_PATTERN_ID = "(?:(?:\\w*.?://)?\\w*.?\\w*-?.?\\w*/(?:embed|e|v|watch|.*/)?\\??(?:feature=\\w*\\.?\\w*)?&?(?:v=)?/?)([\\w\\d_-]+).*"
5-
const val VIMEO_PATTERN = "(?:http[s]?:\\/\\/)(?:w{3})?(?:player\\.)?vimeo\\.com\\/(?:[a-z]*\\/)*([0-9]{6,11})[?]?.*"
6-
const val RUTUBE_PATTERN = "(?:http[s]?:\\/\\/)(?:w{3})?(?:player\\.)?rutube\\.ru\\/video\\/(?:embed\\/)?([A-Za-z0-9]+)[\\/]?(\\?.+)?"
7-
const val FACEBOOK_PATTERN = "(?:http[s]?:\\/\\/)?(?:www.|web.|m.)?(?:facebook|fb)?.com\\/(?:(?:video.php|watch?\\/)?\\?v=|.+\\/videos(?:\\/.+)?\\/)(\\d+)\\S*"
8-
const val DAILYMOTION_PATTERN = "(?:http[s]?:\\/\\/)?(?:\\/\\/)?(?:www\\.)?(?:(?:dailymotion\\.com(?:\\/embed)?\\/video)|dai\\.ly)\\/([a-zA-Z0-9]+)(?:_[\\w_-]+)?"
3+
const val YOUTUBE_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}).*"
4+
const val VIMEO_PATTERN = "(?:http[s]?://)(?:w{3})?(?:player\\.)?vimeo\\.com/(?:[a-z]*/)*([0-9]{6,11})[?]?.*"
5+
const val RUTUBE_PATTERN = "(?:http[s]?://)(?:w{3})?(?:player\\.)?rutube\\.ru/video/(?:embed/)?([A-Za-z0-9]+)[/]?(\\?.+)?"
6+
const val FACEBOOK_PATTERN = "(?:http[s]?://)?(?:www.|web.|m.)?(?:facebook|fb)?.com/(?:(?:video.php|watch?/)?\\?v=|.+/videos(?:/.+)?/)(\\d+)\\S*"
7+
const val DAILYMOTION_PATTERN = "(?:http[s]?://)?(?:www\\.)?(?:(?:dailymotion\\.com(?:/embed)?/video)|dai\\.ly)/([a-zA-Z0-9]+)(?:_[\\w_-]+)?"
98
const val WISTIA_PATTERN = "(?:http[s]?:\\/\\/)?(?:.+)?(?:wistia\\.(?:com|net)|wi\\.st)\\/(?:medias|embed|series)\\/(?:iframe\\/?)?(?:\\S+\\?\\S*wvideoid=)?([a-zA-Z0-9]+)\\S*"
10-
const val VZAAR_PATTERN = "(?:http[s]?:\\/\\/)?(?:.+)?vzaar.com\\/?(?:videos\\/)?([a-zA-Z0-9]+)\\S*"
9+
const val VZAAR_PATTERN = "(?:http[s]?://)?(?:.+)?vzaar.com/?(?:videos/)?([a-zA-Z0-9]+)\\S*"
1110
const val OEMBED_INFO = "/oembed"
1211
const val VIMEO_INFO = "/api/v2/video/"
1312
const val FACEBOOK_INFO = "/plugins/video/oembed"
@@ -26,9 +25,10 @@ const val FORMAT = "format"
2625
const val FORMAT_JSON = "json"
2726
const val URL = "url"
2827

29-
3028
fun String.getYoutubeInfoUrl(): String {
31-
return "$YOUTUBE_BASE_URL$OEMBED_INFO?$FORMAT=$FORMAT_JSON&$URL=$this"
29+
val id = YOUTUBE_PATTERN.toRegex().find(this)?.groups?.get(1)?.value
30+
val url = "https://www.youtube.com/watch?v=$id"
31+
return "$YOUTUBE_BASE_URL$OEMBED_INFO?$FORMAT=$FORMAT_JSON&$URL=$url"
3232

3333
}
3434

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class VideoService(
128128
val result = try {
129129
fromJson(jsonBody, type).toPreview(originalUrl)
130130
} catch (e: Exception) {
131-
VideoPreviewModel.error(e.localizedMessage)
131+
VideoPreviewModel.error(originalUrl, e.localizedMessage)
132132
}
133133

134134
withContext(Dispatchers.Main) {

library/src/main/java/com/gapps/library/api/models/video/youtube/ResponseYoutube.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.gapps.library.api.models.video.youtube
22

3-
import com.gapps.library.api.YOUTUBE_PATTERN_ID
3+
import com.gapps.library.api.YOUTUBE_PATTERN
44
import com.gapps.library.api.models.video.VideoPreviewModel
55
import com.gapps.library.api.models.video.base.BaseVideoResponse
66
import com.google.gson.annotations.SerializedName
@@ -66,6 +66,6 @@ class ResponseYoutube: BaseVideoResponse {
6666
override fun getVideoId(url: String?): String? {
6767
url ?: return null
6868

69-
return YOUTUBE_PATTERN_ID.toRegex().find(url)?.groups?.get(1)?.value
69+
return YOUTUBE_PATTERN.toRegex().find(url)?.groups?.get(1)?.value
7070
}
7171
}

0 commit comments

Comments
 (0)