Advertisement
ingamedeo

VidtoMP3 API Java

Jan 11th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.39 KB | None | 0 0
  1.             /*
  2.                           Code Below uses vidtomp3 remote api to convert video to MP3!
  3.                                           MP3 Download function ;)
  4.              */
  5.             ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
  6.             postParameters.add(new BasicNameValuePair("mediaurl", url)); //Post Request mediaurl as parameter ;)
  7.  
  8.             String response = null;
  9.  
  10.             returnString = null;
  11.  
  12.             //execute request and get response ;)
  13.             try {
  14.                 response = CustomHttpClient.executeHttpPost(
  15.                         "http://www.vidtomp3.com/cc/conversioncloud.php",  // vidtomp3 remove server api
  16.                         postParameters);
  17.  
  18.                 String result = response.toString(); //This should be removed. To need to convert to string.
  19.                 returnString = result.substring(result.indexOf("statusurl")+12, result.length()-4); //Returns the statusurl (It's a sort of JSON...but not parsing right way)
  20.                 returnString = returnString.replace("\\", ""); //This removes backslashes from the url ;))
  21.                 Log.i("log_tag", returnString); //Logs statusurl returned by the api
  22.  
  23.             }
  24.             catch (Exception e) {
  25.                     Log.e("log_tag","Error while connecting to vidtomp3 api! " + e.toString());
  26.             }
  27.  
  28.             try { //Connects to statusurl..should get an XML document..anyway..I'm not parsing it ;)
  29.                 DefaultHttpClient httpClient = new DefaultHttpClient();
  30.                 HttpGet httpGet = new HttpGet(returnString);
  31.  
  32.                 HttpResponse httpResponse = httpClient.execute(httpGet);
  33.                 HttpEntity httpEntity = httpResponse.getEntity();
  34.                 String output = EntityUtils.toString(httpEntity);
  35.  
  36.                 mp3url = output.substring(output.indexOf("<downloadurl><![CDATA[")+22, output.indexOf("/]]></downloadurl>")); //Extract mp3 download URL from XML file
  37.                 Log.i("log_tag",mp3url); //This should return mp3 download url ;)
  38.                 title = output.substring(output.indexOf("<file><![CDATA[")+15, output.indexOf("]]></file>")-4); //Extract title from XML file (without .mp3)
  39.                 Log.i("log_tag",title); //This should return video title ;)
  40.                 status = output.substring(output.indexOf("<status step=")+14, output.indexOf("/>")-1); //Extract status from XML file
  41.                 Log.i("log_tag", "Status: " + status); //This should return video download status ;)
  42.                 downloadsize = output.substring(output.indexOf("<filesize><![CDATA[")+19, output.indexOf("]]></filesize>")); //Extractdownload size from XML file
  43.                 Log.i("log_tag", "Download Size: " + downloadsize); //This should return mp3 download size ;)
  44.  
  45.                 if (status.equals("finished")) {
  46.                     Log.i("log_tag", "File ready to download ;)");
  47.                 }
  48.  
  49.             } catch (ClientProtocolException e) {
  50.                 e.printStackTrace();
  51.                 Log.i("log_tag", "There is a problem with your download ;(");
  52.             } catch (IOException e) {
  53.                 e.printStackTrace();
  54.                 Log.i("log_tag", "There is a problem with your download ;(");
  55.             } catch (Exception e) {
  56.                 e.printStackTrace();
  57.                 Log.i("log_tag", "There is a problem with your download ;(");
  58.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement