Skip to content

Commit

Permalink
Bug fixes and other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
TalbotGooday committed Jan 15, 2020
1 parent 38c01bd commit 53265ee
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/com/gapps/videonoapi/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class MainActivity : AppCompatActivity() {
"https://www.facebook.com/UFC/videos/410056389868335/",
"https://www.dailymotion.com/video/x5sxbmb",
"https://dave.wistia.com/medias/0k5h1g1chs/",
"https://vzaar.com/videos/401431",
"https://www.youtube.com/watch?v=Gqr14W91mdcjsjd"
"https://vzaar.com/videos/401431"
)

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
18 changes: 9 additions & 9 deletions library/src/main/java/com/gapps/library/api/Const.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.gapps.library.api

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


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

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class VideoService(
val result = try {
fromJson(jsonBody, type).toPreview(originalUrl)
} catch (e: Exception) {
VideoPreviewModel.error(e.localizedMessage)
VideoPreviewModel.error(originalUrl, e.localizedMessage)
}

withContext(Dispatchers.Main) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gapps.library.api.models.video.youtube

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

return YOUTUBE_PATTERN_ID.toRegex().find(url)?.groups?.get(1)?.value
return YOUTUBE_PATTERN.toRegex().find(url)?.groups?.get(1)?.value
}
}

0 comments on commit 53265ee

Please sign in to comment.