Skip to content

Commit

Permalink
Fix: Added code to Standardized YouTube link format for issue Saptars…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarunkumarkanakam committed Sep 2, 2024
1 parent ce5a41f commit a3ea4d5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions CLI/src/main/java/main/Drifty_CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,38 @@ public static void main(String[] args) {
if (isInstagram(link)) {
link = formatInstagramLink(link);
}
else if (isYoutube(link)) {
String videoId = null;

try {
URI uri = URI.create(link);
String domain = uri.getHost();

// checking if the domain is youtu.be
if ("youtu.be".equals(domain)) {
String path = uri.getPath();
if (path != null && path.length() > 1) {
videoId = path.substring(1); // removing the leading "/"
}
}
// checking if the domain is youtube.com
else if ("www.youtube.com".equals(domain) || "youtube.com".equals(domain)) {
Map<String, String> queryParams = extractQueryParams(link, "v");
videoId = queryParams.get("v");
}

if (videoId != null) {
// constructing link in youtube.com/watch?v={videoID}
uri = new URI("https", "www.youtube.com", "/watch", "v=" + videoId, null);
link = uri.toString();
} else {
messageBroker.msgLinkError("YouTube video ID not found in the link.");
}

} catch (IllegalArgumentException | URISyntaxException e) {
messageBroker.msgLinkError("Failed to process the YouTube link: " + e.getMessage());
}
}
messageBroker.msgFilenameInfo("Retrieving filename from link...");
fileName = findFilenameInLink(link);
if (!Objects.requireNonNull(fileName).isEmpty()) {
Expand Down

0 comments on commit a3ea4d5

Please sign in to comment.