Parsing SHOUTcast 7.html metadata on Android

安稳与你 提交于 2019-12-02 03:44:30

Heres Pulsarman325's working solution, tidied up, with a little extra stuff i had to add to get it to work (try/catch and variable initialisations)

String url = "http://molestia.ponify.me:8062";

URL url2=null;

try
{
    url2 = new URL(url + "/7.html");

}

catch (MalformedURLException e1)
{
    e1.printStackTrace();
}

URLConnection con=null;

try
{
    con = url2.openConnection();
}

catch (IOException e1)
{
  e1.printStackTrace();

}

con.setRequestProperty("User-Agent", "Mozilla/5.0");

Reader r = null;

try
{
    r = new InputStreamReader(con.getInputStream());
}

catch (IOException e)
{
  e.printStackTrace(); 
}

StringBuilder buf = new StringBuilder();

int ch=0;

while (true)
{
    try
    {
        ch = r.read(); 
    }

    catch (IOException e)
    {
      e.printStackTrace();  
    }

    if (ch < 0)
      break;

    buf.append((char) ch);

}

String str = buf.toString();

String trackinfo = str.split(",")[6].split("</body>")[0];

Log.d("HTML", trackinfo);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!