fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.net.*;
  7. import java.util.regex.*;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. URI u = URI.create(
  15. "http://w...content-available-to-author-only...e.com/watch?v=u8nQa1cJyX8&a=GxdCwVVULXctT2lYDEPllDR0LRTutYfW");
  16. String yid;
  17. switch (u.getHost())
  18. {
  19. case "youtube.com":
  20. case "www.youtube.com":
  21. yid = Pattern.compile("&")
  22. .splitAsStream(u.getRawQuery())
  23. .filter((s) -> s.startsWith("v="))
  24. .map((s) -> s.substring(2))
  25. .findFirst().orElse(null);
  26. break;
  27.  
  28. case "youtu.be":
  29. yid = u.getPath().substring(1);
  30. break;
  31.  
  32. default:
  33. yid = null;
  34. }
  35. if (yid != null)
  36. System.out.println(yid);
  37. }
  38. }
Success #stdin #stdout 0.12s 4386816KB
stdin
Standard input is empty
stdout
u8nQa1cJyX8