Skip to content

Commit

Permalink
PluginUrlUtilsTest: add tests for to{Default,Invidious}YouTubePluginUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
peat-psuwit committed Feb 17, 2024
1 parent 81a8fdb commit 3b30f67
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions app/src/test/java/org/xbmc/kore/utils/PluginUrlUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,48 @@ public void toPluginUrlVimeo() throws Exception {
String pluginUrlUnlisted = PluginUrlUtils.toVimeoPluginUrl(playUriUnlisted);
assertEquals("plugin://plugin.video.vimeo/play/?video_id=1234:hash", pluginUrlUnlisted);
}

@Test
public void toDefaultYouTubePluginUrl() throws Exception {
// Some test cases come from youtube-dl/yt-dlp.

Uri playUriNormal = Uri.parse("https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9");
String pluginUriNormal = PluginUrlUtils.toDefaultYouTubePluginUrl(playUriNormal);
assertEquals("plugin://plugin.video.youtube/play/?video_id=BaW_jenozKc", pluginUriNormal);

Uri playUriWithPlaylist = Uri.parse("https://www.youtube.com/watch?v=LHpQExw47xg&list=PLfMKdAHATthHKCZ-WMjC7-Ks-9UxrxocQ");
String pluginUriWithPlaylist = PluginUrlUtils.toDefaultYouTubePluginUrl(playUriWithPlaylist);
assertEquals(
"plugin://plugin.video.youtube/play/?video_id=LHpQExw47xg&playlist_id=PLfMKdAHATthHKCZ-WMjC7-Ks-9UxrxocQ&order=default",
pluginUriWithPlaylist);

Uri playUriLive = Uri.parse("https://www.youtube.com/live/qVv6vCqciTM");
String pluginUriLive = PluginUrlUtils.toDefaultYouTubePluginUrl(playUriLive);
assertEquals("plugin://plugin.video.youtube/play/?video_id=qVv6vCqciTM", pluginUriLive);

Uri playUriShorts = Uri.parse("https://www.youtube.com/shorts/BGQWPY4IigY");
String pluginUriShorts = PluginUrlUtils.toDefaultYouTubePluginUrl(playUriShorts);
assertEquals("plugin://plugin.video.youtube/play/?video_id=BGQWPY4IigY", pluginUriShorts);
}

@Test
public void toInvidiousYouTubePluginUrl() throws Exception {
Uri playUriNormal = Uri.parse("https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9");
String pluginUriNormal = PluginUrlUtils.toInvidiousYouTubePluginUrl(playUriNormal);
assertEquals("plugin://plugin.video.invidious/?action=play_video&video_id=BaW_jenozKc", pluginUriNormal);

Uri playUriWithPlaylist = Uri.parse("https://www.youtube.com/watch?v=LHpQExw47xg&list=PLfMKdAHATthHKCZ-WMjC7-Ks-9UxrxocQ");
String pluginUriWithPlaylist = PluginUrlUtils.toInvidiousYouTubePluginUrl(playUriWithPlaylist);
assertEquals(
"plugin://plugin.video.invidious/?action=play_video&video_id=LHpQExw47xg",
pluginUriWithPlaylist);

Uri playUriLive = Uri.parse("https://www.youtube.com/live/qVv6vCqciTM");
String pluginUriLive = PluginUrlUtils.toInvidiousYouTubePluginUrl(playUriLive);
assertEquals("plugin://plugin.video.invidious/?action=play_video&video_id=qVv6vCqciTM", pluginUriLive);

Uri playUriShorts = Uri.parse("https://www.youtube.com/shorts/BGQWPY4IigY");
String pluginUriShorts = PluginUrlUtils.toInvidiousYouTubePluginUrl(playUriShorts);
assertEquals("plugin://plugin.video.invidious/?action=play_video&video_id=BGQWPY4IigY", pluginUriShorts);
}
}

0 comments on commit 3b30f67

Please sign in to comment.