Catch hidden extension of Uri

1

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

However, some websites 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, however Downloader takes mimetype as php and saves the video in php extension, this is the code snippet that I use to get the extension:

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

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

So how to solve this problem?

    
asked by anonymous 16.01.2018 / 14:15

1 answer

0

Use of the ways to capture the link is by accessing the page with the class URLConnection and then returning 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());
    }
  }
}
    
16.01.2018 / 14:30