Last active
July 28, 2020 09:28
-
-
Save hiking93/5b253d8ceea2978a7cfd7a8b6d60e6a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.google.common.truth.Truth.assertThat | |
| import org.junit.Test | |
| class EmbedResolverTest { | |
| @Test | |
| fun `resolve youtube video regular`() { | |
| val url = "https://www.youtube.com/watch?v=7jzSXyEln9o&feature=youtu.be" | |
| assertThat(EmbedResolver.resolve(url)?.url) | |
| .isEqualTo("https://www.youtube.com/embed/7jzSXyEln9o?feature=youtu.be") | |
| } | |
| @Test | |
| fun `resolve youtube video mobile`() { | |
| val url = "https://m.youtube.com/watch?v=7jzSXyEln9o&feature=youtu.be" | |
| assertThat(EmbedResolver.resolve(url)?.url) | |
| .isEqualTo("https://www.youtube.com/embed/7jzSXyEln9o?feature=youtu.be") | |
| } | |
| @Test | |
| fun `resolve youtube video short`() { | |
| val url = "https://youtu.be/7jzSXyEln9o" | |
| assertThat(EmbedResolver.resolve(url)?.url) | |
| .isEqualTo("https://www.youtube.com/embed/7jzSXyEln9o") | |
| } | |
| @Test | |
| fun `resolve youtube video with playlist and time code`() { | |
| val url = | |
| "https://www.youtube.com/watch?v=5icOQOONOiQ&list=PL_mdITDph7YjdClTzHJJwBv07ws_W7w9Z&index=5&t=410s" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo( | |
| "https://www.youtube.com/embed/5icOQOONOiQ" + | |
| "?list=PL_mdITDph7YjdClTzHJJwBv07ws_W7w9Z&index=5&t=410s" | |
| ) | |
| } | |
| @Test | |
| fun `resolve youtube video embedded`() { | |
| val url = "https://www.youtube-nocookie.com/embed/sRrqF8eXs38" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo(url) | |
| } | |
| @Test | |
| fun `resolve youtube playlist`() { | |
| val url = "https://www.youtube.com/playlist?list=PLx0sYbCqOb8TBPRdmBHs5Iftvv9TPboYG" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo( | |
| "https://www.youtube.com/embed/videoseries?list=PLx0sYbCqOb8TBPRdmBHs5Iftvv9TPboYG" | |
| ) | |
| } | |
| @Test | |
| fun `resolve youtube playlist embedded`() { | |
| val url = | |
| "https://www.youtube.com/embed/videoseries?list=PLx0sYbCqOb8TBPRdmBHs5Iftvv9TPboYG" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo(url) | |
| } | |
| @Test | |
| fun `resolve youtube user`() { | |
| val url = "https://www.youtube.com/user/embed/neqd9vMpnG8" | |
| assertThat(EmbedResolver.resolve(url)?.url).isNull() | |
| } | |
| @Test | |
| fun `resolve twitch stream`() { | |
| val url = "https://www.twitch.tv/blusewilly_retry" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo( | |
| "https://player.twitch.tv/?channel=blusewilly_retry&parent=dcard.tw" | |
| ) | |
| } | |
| @Test | |
| fun `resolve twitch stream embedded`() { | |
| val url = "https://player.twitch.tv/?channel=blusewilly_retry&parent=dcard.tw" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo(url) | |
| } | |
| @Test | |
| fun `resolve twitch video`() { | |
| val url = "https://www.twitch.tv/videos/579853689" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo( | |
| "https://player.twitch.tv/?video=579853689&parent=dcard.tw" | |
| ) | |
| } | |
| @Test | |
| fun `resolve twitch video user`() { | |
| val url = "http://www.twitch.tv/carterchen1025/v/642264467?sr=a&t=0s" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo( | |
| "https://player.twitch.tv/?video=642264467&parent=dcard.tw" | |
| ) | |
| } | |
| @Test | |
| fun `resolve twitch video embedded`() { | |
| val url = "https://player.twitch.tv/?video=579853689&parent=dcard.tw" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo(url) | |
| } | |
| @Test | |
| fun `resolve twitch clip`() { | |
| val url = "https://clips.twitch.tv/IncredulousAbstemiousFennelImGlitch" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo( | |
| "https://clips.twitch.tv/embed?clip=IncredulousAbstemiousFennelImGlitch&parent=dcard.tw" | |
| ) | |
| } | |
| @Test | |
| fun `resolve twitch clip embedded`() { | |
| val url = "https://clips.twitch.tv/IncredulousAbstemiousFennelImGlitch" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo( | |
| "https://clips.twitch.tv/embed?clip=IncredulousAbstemiousFennelImGlitch&parent=dcard.tw" | |
| ) | |
| } | |
| @Test | |
| fun `resolve giphy`() { | |
| val url = "https://giphy.com/gifs/nyan-cat-sIIhZliB2McAo" | |
| assertThat(EmbedResolver.resolve(url)?.url) | |
| .isEqualTo("https://giphy.com/embed/sIIhZliB2McAo") | |
| } | |
| @Test | |
| fun `resolve giphy media`() { | |
| val url = "https://media.giphy.com/media/GZdyiv2aeZ3tS/giphy.gif" | |
| assertThat(EmbedResolver.resolve(url)?.url) | |
| .isEqualTo("https://giphy.com/embed/GZdyiv2aeZ3tS") | |
| } | |
| @Test | |
| fun `resolve giphy html5`() { | |
| val url = "https://giphy.com/gifs/GZdyiv2aeZ3tS/html5" | |
| assertThat(EmbedResolver.resolve(url)?.url) | |
| .isEqualTo("https://giphy.com/embed/GZdyiv2aeZ3tS") | |
| } | |
| @Test | |
| fun `resolve giphy embedded`() { | |
| val url = "https://giphy.com/embed/sIIhZliB2McAo" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo(url) | |
| } | |
| @Test | |
| fun `resolve gfycat`() { | |
| val url = "https://gfycat.com/temptingplayfulkitty-marvel-cinematic-universe-avengers" | |
| assertThat(EmbedResolver.resolve(url)?.url) | |
| .isEqualTo("https://gfycat.com/ifr/temptingplayfulkitty") | |
| } | |
| @Test | |
| fun `resolve gfycat embedded`() { | |
| val url = "https://gfycat.com/ifr/temptingplayfulkitty" | |
| assertThat(EmbedResolver.resolve(url)?.url).isEqualTo(url) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment