Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Code Below uses vidtomp3 remote api to convert video to MP3!
- MP3 Download function ;)
- */
- ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
- postParameters.add(new BasicNameValuePair("mediaurl", url)); //Post Request mediaurl as parameter ;)
- String response = null;
- returnString = null;
- //execute request and get response ;)
- try {
- response = CustomHttpClient.executeHttpPost(
- "http://www.vidtomp3.com/cc/conversioncloud.php", // vidtomp3 remove server api
- postParameters);
- String result = response.toString(); //This should be removed. To need to convert to string.
- returnString = result.substring(result.indexOf("statusurl")+12, result.length()-4); //Returns the statusurl (It's a sort of JSON...but not parsing right way)
- returnString = returnString.replace("\\", ""); //This removes backslashes from the url ;))
- Log.i("log_tag", returnString); //Logs statusurl returned by the api
- }
- catch (Exception e) {
- Log.e("log_tag","Error while connecting to vidtomp3 api! " + e.toString());
- }
- try { //Connects to statusurl..should get an XML document..anyway..I'm not parsing it ;)
- DefaultHttpClient httpClient = new DefaultHttpClient();
- HttpGet httpGet = new HttpGet(returnString);
- HttpResponse httpResponse = httpClient.execute(httpGet);
- HttpEntity httpEntity = httpResponse.getEntity();
- String output = EntityUtils.toString(httpEntity);
- mp3url = output.substring(output.indexOf("<downloadurl><![CDATA[")+22, output.indexOf("/]]></downloadurl>")); //Extract mp3 download URL from XML file
- Log.i("log_tag",mp3url); //This should return mp3 download url ;)
- title = output.substring(output.indexOf("<file><![CDATA[")+15, output.indexOf("]]></file>")-4); //Extract title from XML file (without .mp3)
- Log.i("log_tag",title); //This should return video title ;)
- status = output.substring(output.indexOf("<status step=")+14, output.indexOf("/>")-1); //Extract status from XML file
- Log.i("log_tag", "Status: " + status); //This should return video download status ;)
- downloadsize = output.substring(output.indexOf("<filesize><![CDATA[")+19, output.indexOf("]]></filesize>")); //Extractdownload size from XML file
- Log.i("log_tag", "Download Size: " + downloadsize); //This should return mp3 download size ;)
- if (status.equals("finished")) {
- Log.i("log_tag", "File ready to download ;)");
- }
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- Log.i("log_tag", "There is a problem with your download ;(");
- } catch (IOException e) {
- e.printStackTrace();
- Log.i("log_tag", "There is a problem with your download ;(");
- } catch (Exception e) {
- e.printStackTrace();
- Log.i("log_tag", "There is a problem with your download ;(");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement