Grab hidden extension from Uri

Asked

Viewed 280 times

1

I have an app to watch and download videos online, my code detects mimetype by the url to use as the video extension downloaded.

But some sites have the hidden extension, such as this url: http://www.animeplus.org/inc/video.inc.php?&file=NSwzOWE0YWQ5ODhhNWQ4NWEx&token=rm_uJeMTUxNjA4OTM0OQ== Videoview can play the video, but Downloader takes mimetype as php and saves the video in the php extension, this is the code snippet I use to get the extension:

String mimeType =  '.' + MimeTypeMap.getFileExtensionFromUrl(url.toString());

In this case he takes the video extension as he should: https://www.blogger.com/video-play.mp4?contentId=6bc99b4dd120f980

So how to solve this problem?

1 answer

0


Use of the ways to capture the link is by accessing the page with the class Urlconnection and then returning the Header Response: Location . Ex:

import java.net.HttpURLConnection;
import java.net.URL;

public class HelloWorld
{
  public static void main(String[] args)
  {
    try {
        /* Especifica a URL */
        URL url = new URL("http://www.animeplus.org/inc/video.inc.php?&file=NSwzOWE0YWQ5ODhhNWQ4NWEx&token=rm_uJeMTUxNjA4OTM0OQ==");

        /* Abre a conexão */
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        /* Define um User-Agent. É necessário, caso não adicione essa linha, você receberá um erro 403 (Não Autorizado) */
        connection.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");

        /* Aqui você captura o Header da resposta. */
        System.out.println( connection.getHeaderField("Location") );

    } catch (Exception e) {
      System.out.println("Erro: " + e.getMessage());
    }
  }
}
  • But this is java SE

  • Java SE is a development tool for Java Platform. That’s just Java (how is the question tag) and you can run the same code on Android.

  • As I suspected, this is java SE, there must be other ways to do this on android.

  • And there (after all this is Java), just copy the try..catch and execute this code with the AsyncTask. '-'

  • @Samuelives Java is Java, my fi.

  • java is java but there are different Ipps with different behaviors, android and j2me are both made in java but a code made for j2me will not run on android and vice and verça, as well as its code JAVA SE DESTINED TO DESKTOP AND NOT MOBILE, did not turn because it is not the target of the platform as I said before

  • @Samuelives I made an example with Java WHICH ALSO SERVES ON ANDROID dude. Don’t you understand that? It can be negative without problems (black boot is like that). If you would like to read the documentation https://developer.android.com/reference/java/net/URL.html and https://developer.android.com/reference/java/HttpURLConnection.html you will see that the code I posted (part of it) also serves on Android. #ADSUMUS

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.