Skip to content

Commit

Permalink
Add tests for validating youtube video link regex
Browse files Browse the repository at this point in the history
* Get bitmap from PDF

* Bitmap of PDF

* Delete deploymentTargetDropDown.xml

* Delete gradle.xml

* Delete misc.xml

* Bitmap of PDF

* Bitmap of PDF

* Updated

* Update runConfigurations.xml

* Update runConfigurations.xml

* Update runConfigurations.xml

* Changes done

* Get Youtube video thumbnail

* Youtube video thumbnail

* Delete gradle.xml

* Delete misc.xml

* Youtube video thumbnail

* Update MainActivity.kt

* Update activity_main.xml

* Update Previewer.kt

* Update strings.xml

* Update build.gradle

* Changes done

* Remove gradle.xml & runConfigurations.xml from changelog

* Changes in comments and tried using URL

* Add suspend function for fetching thumbnail

* Return null instead of throwing exception

Co-authored-by: arpit <[email protected]>

* Reformat files

Co-authored-by: Raina Jain <[email protected]>
Co-authored-by: arpit <[email protected]>

* Add support for generating video thumbnail

* Added glide dependency

* Added support for generating video thumbnail

* added necessary imports

* Bitmap of PDF

* Delete deploymentTargetDropDown.xml

* Delete gradle.xml

* Delete misc.xml

* Bitmap of PDF

* Bitmap of PDF

* Updated

* Update runConfigurations.xml

* Update runConfigurations.xml

* Update runConfigurations.xml

* Changes done

* Added Demo code to get video from storage and show its thumbnail

* removed blank line

* removed .asBitmap()

* removed Previewer.init() call from MainActivity.kt

* Implemented viewBinding

* Removed unused imports

* renamed getVideoThumbnail function to setVideoThumbnailFromUri

* renamed activityLauncher to activityResultLauncherForVideoUri

* added code to demonstrate creation of thumbnail from Internet Video

* added empty line after declaration

* renamed uriVideo to videoUri

* Removed redundant code

* Added internet permission

* Fixed the typo

* Reformat files

Co-authored-by: ayushigupta931 <[email protected]>
Co-authored-by: Ayushi Gupta <[email protected]>
Co-authored-by: arpit <[email protected]>

* Create separate activities for all functions

* Regex tests for Youtube URLs

* reformat code

* internal functions marked

* delete unnecessary files

* Delete BitmapPDF.kt

* Delete BitmapVideo.kt

* Delete BitmapYoutube.kt

* Delete activity_bitmap_pdf.xml

* Delete activity_bitmap_video.xml

* Delete activity_bitmap_youtube.xml

Co-authored-by: Ayushi Gupta <[email protected]>
Co-authored-by: Raina Jain <[email protected]>
Co-authored-by: arpit <[email protected]>
Co-authored-by: Puranjay Khanijo <[email protected]>
Co-authored-by: ayushigupta931 <[email protected]>
  • Loading branch information
6 people authored Dec 7, 2021
1 parent d808763 commit 48fa4fc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/src/main/java/com/cops/iitbhu/previewer/lib/Previewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object Previewer {
* @param youtubeLink
* @return Image ID
*/
fun youtubeLinkToImageUrl(youtubeLink: String): String? {
internal fun youtubeLinkToImageUrl(youtubeLink: String): String? {
val regex =
"^((?:https?:)?//)?((?:www|m)\\.)?(youtube\\.com|youtu.be|youtube-nocookie.com)(/(?:[\\w\\-]+\\?v=|feature=|watch\\?|e/|embed/|v/)?)([\\w\\-]+)(\\S+)?\$"
return Regex(regex).matchEntire(youtubeLink)?.groupValues?.get(5)
Expand Down Expand Up @@ -126,14 +126,14 @@ object Previewer {

/**
* Generates a bitmap for remote video file
* @param uri Uri of the remote video file as a String
* @return Bitmap of the first frame of the video corresponding to given uri
* @param url Url of the remote video file as a String
* @return Bitmap of the first frame of the video corresponding to given url
*/
suspend fun getThumbnailFromRemoteVideoUri(uri: String): Bitmap? {
suspend fun getThumbnailFromRemoteVideoUri(url: String): Bitmap? {
return withContext(Dispatchers.IO) {
try {
val mMR = MediaMetadataRetriever()
mMR.setDataSource(uri, mapOf())
mMR.setDataSource(url, mapOf())
mMR.frameAtTime
} catch (e: Exception) {
null
Expand Down
45 changes: 41 additions & 4 deletions lib/src/test/java/com/cops/iitbhu/previewer/lib/RegexTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,46 @@ class RegexTest {

@Test
fun checkRegexIsValid() {
val youtubeLink = "https://www.youtube.com/watch?v=Pur_0KroFR8"
val expected = "Pur_0KroFR8"
val actual = Previewer.youtubeLinkToImageUrl(youtubeLink)
assertEquals(expected, actual)
val links = listOf(
"https://www.youtube.com/watch?v=DFYRQ_zQ-gk",
"https://www.youtube.com/watch?v=DFYRQ_zQ-gk&feature=featured",
"https://www.youtube.com/watch?v=DFYRQ_zQ-gk",
"http://www.youtube.com/watch?v=DFYRQ_zQ-gk",
"//www.youtube.com/watch?v=DFYRQ_zQ-gk",
"www.youtube.com/watch?v=DFYRQ_zQ-gk",
"https://youtube.com/watch?v=DFYRQ_zQ-gk",
"http://youtube.com/watch?v=DFYRQ_zQ-gk",
"//youtube.com/watch?v=DFYRQ_zQ-gk",
"youtube.com/watch?v=DFYRQ_zQ-gk",
"https://m.youtube.com/watch?v=DFYRQ_zQ-gk",
"http://m.youtube.com/watch?v=DFYRQ_zQ-gk",
"//m.youtube.com/watch?v=DFYRQ_zQ-gk",
"m.youtube.com/watch?v=DFYRQ_zQ-gk",
"https://www.youtube.com/v/DFYRQ_zQ-gk?fs=1&hl=en_US",
"http://www.youtube.com/v/DFYRQ_zQ-gk?fs=1&hl=en_US",
"//www.youtube.com/v/DFYRQ_zQ-gk?fs=1&hl=en_US",
"www.youtube.com/v/DFYRQ_zQ-gk?fs=1&hl=en_US",
"youtube.com/v/DFYRQ_zQ-gk?fs=1&hl=en_US",
"https://www.youtube.com/embed/DFYRQ_zQ-gk?autoplay=1",
"https://www.youtube.com/embed/DFYRQ_zQ-gk",
"http://www.youtube.com/embed/DFYRQ_zQ-gk",
"//www.youtube.com/embed/DFYRQ_zQ-gk",
"www.youtube.com/embed/DFYRQ_zQ-gk",
"https://youtube.com/embed/DFYRQ_zQ-gk",
"http://youtube.com/embed/DFYRQ_zQ-gk",
"//youtube.com/embed/DFYRQ_zQ-gk",
"youtube.com/embed/DFYRQ_zQ-gk",
"https://youtu.be/DFYRQ_zQ-gk?t=120",
"https://youtu.be/DFYRQ_zQ-gk",
"http://youtu.be/DFYRQ_zQ-gk",
"//youtu.be/DFYRQ_zQ-gk",
"youtu.be/DFYRQ_zQ-gk",
"https://www.youtube.com/HamdiKickProduction?v=DFYRQ_zQ-gk",
)
val expected = "DFYRQ_zQ-gk"
links.forEach { link ->
val actual = Previewer.youtubeLinkToImageUrl(link)
assertEquals(expected, actual)
}
}
}

0 comments on commit 48fa4fc

Please sign in to comment.