I rolled up the working method (for video in youtube) in which I process the user's link (I pull out the ID and substitute it in the template link form):

private String onUserInput(String input) { Uri uri = Uri.parse(input); String videoID = uri.getQueryParameter("v"); if (TextUtils.isEmpty(videoID)) { String[] str = input.split("/"); videoID = str[str.length - 1]; } url = "http://img.youtube.com/vi/" + videoID + "/0.jpg"; Log.d("url", url + " " + controlList.get(23).getImageUploads().size()); adapterForm.notifyDataSetChanged(); return url; } 

Help to correctly update the method for the link in vimeo:

 https://vimeo.com/api/v2/video/183364240.json 

As I understand it, you need to also parse the data from the link, since .json And already after I pull out the link, it will be possible to access any image size (thumbnail_small, thumbnail_medium, thumbnail_large), like about here:

 https://i.vimeocdn.com/video/595198868_100x75.jpg 

I tried to update the method as follows, but even before I read about JSON:

 private void useLinkInput(String input, EVideo video) { Uri uri = Uri.parse(input); String videoID = uri.getQueryParameter("v"); if (TextUtils.isEmpty(videoID)) { String[] str = input.split("/"); videoID = str[str.length - 1]; } if (video == EVideo.YOUTUBE) { source = "http://img.youtube.com/vi/"; } else { source = "http://VIMEO.CN"; } url = source + videoID + "/0.jpg"; Log.d("url", url); } 

Variables declared so:

 public enum EVideo { YOUTUBE, VIMEO } 

I'm not sure that the attempt is " counted " because problems arise with the json operation itself, how is it possible to push it into our code?

  • You need from the line https://vimeo.com/api/v2/video/183364240.json to get the number 183364240 ? - post_zeew
  • @post_zeew well, sort of. and then add this number (ID) to my url, but already to vimeo.com/api/v2/video , in addition to the method in question, i.e. I think the second if just to add or something like that. - Morozov
  • Please show examples of input and output in both cases. - post_zeew
  • @post_zeew for the method described in the question using any type of link from youtube. - Morozov
  • This is not an answer. However, as you wish. - post_zeew

1 answer 1

The String getLink(String oldLink) converts:

  1. https://www.youtube.com/watch?v=ehMGQqeV7qM&feature=youtu.be at http://img.youtube.com/vi/ehMGQqeV7qM/0.jpg ;
  2. https://vimeo.com/183171690 at https://vimeo.com/api/v2/video/183171690.json .

Actually, the code:

 private String getLink(String oldLink) { Uri uri = Uri.parse(oldLink); String host = uri.getHost().startsWith("www.") ? uri.getHost().substring(4) : uri.getHost(); switch (host) { case "youtube.com": return "http://img.youtube.com/vi/" + uri.getQueryParameter("v") + "/0.jpg"; case "vimeo.com" : return "https://vimeo.com/api/v2/video" + uri.getPath() + ".json"; default: return oldLink; } } 

And the processing of incorrect source data - themselves.

  • Unfortunately, this option is not suitable, the fact is that the link with vimeo contains .json. As I understand it, you need to first parse the file, and then just add, correct me if it is not right. - Morozov