diff --git a/app/src/main/java/com/gapps/videonoapi/MainActivity.kt b/app/src/main/java/com/gapps/videonoapi/MainActivity.kt index 9c6134d..88e3006 100644 --- a/app/src/main/java/com/gapps/videonoapi/MainActivity.kt +++ b/app/src/main/java/com/gapps/videonoapi/MainActivity.kt @@ -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?) { diff --git a/library/src/main/java/com/gapps/library/api/Const.kt b/library/src/main/java/com/gapps/library/api/Const.kt index df7b599..0123787 100644 --- a/library/src/main/java/com/gapps/library/api/Const.kt +++ b/library/src/main/java/com/gapps/library/api/Const.kt @@ -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" @@ -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" } diff --git a/library/src/main/java/com/gapps/library/api/VideoService.kt b/library/src/main/java/com/gapps/library/api/VideoService.kt index e2c5400..3c3d24a 100644 --- a/library/src/main/java/com/gapps/library/api/VideoService.kt +++ b/library/src/main/java/com/gapps/library/api/VideoService.kt @@ -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) { diff --git a/library/src/main/java/com/gapps/library/api/models/video/youtube/ResponseYoutube.kt b/library/src/main/java/com/gapps/library/api/models/video/youtube/ResponseYoutube.kt index 9818305..f1c7ef7 100644 --- a/library/src/main/java/com/gapps/library/api/models/video/youtube/ResponseYoutube.kt +++ b/library/src/main/java/com/gapps/library/api/models/video/youtube/ResponseYoutube.kt @@ -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 @@ -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 } } \ No newline at end of file