diff options
| author | Yukai (Donald) Shan <xxpinapelzxx@gmail.com> | 2022-12-07 10:03:23 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-07 10:03:23 -0800 |
| commit | 4749216320da6d8adac202f468c759db18a8b735 (patch) | |
| tree | 7ffb866ec622f6abfd88cf53f063c3a4cce499db /utility/URLChecker.java | |
| parent | a1e8ba6d27f5d9496c3d389861c963d0a5e51295 (diff) | |
Add files via upload
Diffstat (limited to 'utility/URLChecker.java')
| -rw-r--r-- | utility/URLChecker.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/utility/URLChecker.java b/utility/URLChecker.java new file mode 100644 index 0000000..ffea53b --- /dev/null +++ b/utility/URLChecker.java @@ -0,0 +1,31 @@ +package utility;
+
+public class URLChecker {
+ public boolean isURL(String term){
+ return term.matches("^(http|https)://.*");
+ }
+ public String getURLType(String url) {
+ if (url.matches("^((?:https?:)?\\/\\/)?((?:www|m)\\.)?((?:youtube(-nocookie)?\\.com|youtu.be))(\\/(?:[\\w\\-]+\\?v=|embed\\/|v\\/)?)([\\w\\-]+)(\\S+)?$")) {
+ return "yt"; //Youtube
+ } else if (url.matches("^(https?:\\/\\/)?(www.)?(m\\.)?soundcloud\\.com\\/[\\w\\-\\.]+(\\/)+[\\w\\-\\.]+/?$")) {
+ return "snd";
+ } else if (url.matches("^(?:https?:\\/\\/)?(?:www\\.|go\\.)?twitch\\.tv\\/([a-z0-9_]+)($|\\?)")) {
+ return "twitch";
+ } else if (url.split("\\?si=")[0].matches("^(https?://)?(www.)?(open.)?spotify.com/(user/[a-zA-Z0-9]+|artist/[a-zA-Z0-9]+|album/[a-zA-Z0-9]+|track/[a-zA-Z0-9]+|playlist/[a-zA-Z0-9]+)$")) {
+ return url.split("\\?si=")[0].matches("^(https?://)?(www.)?(open.)?spotify.com/playlist/[a-zA-Z0-9]+$") ? "spotify-playlist" : "spotify";
+ }
+ return "unknown";
+
+ }
+
+ public String getSpotifyTrackID(String uri){
+ String[] uriParts = uri.split("\\?si=");
+ return uriParts[0].replaceAll("https://open.spotify.com/track/","");
+
+ }
+ public String getSpotifyPlaylistID(String url){
+ String[] uriParts = url.split("\\?si=");
+ return uriParts[0].replaceAll("https://open.spotify.com/playlist/","");
+
+ }
+}
|
