1 | !7 |
2 | |
3 | // package main.java.com.thezujev.theyoutubepld.logic; |
4 | |
5 | import java.io.BufferedReader; |
6 | import java.io.IOException; |
7 | import java.io.InputStream; |
8 | import java.io.InputStreamReader; |
9 | import java.util.HashMap; |
10 | import java.util.Map; |
11 | import org.apache.http.HttpEntity; |
12 | import org.apache.http.HttpResponse; |
13 | import org.apache.http.HttpVersion; |
14 | import org.apache.http.client.ClientProtocolException; |
15 | import org.apache.http.client.methods.HttpGet; |
16 | import org.apache.http.impl.client.DefaultHttpClient; |
17 | import org.apache.http.params.HttpParams; |
18 | import org.apache.http.params.HttpProtocolParams; |
19 | import org.apache.http.params.SyncBasicHttpParams; |
20 | import org.json.JSONArray; |
21 | import org.json.JSONException; |
22 | import org.json.JSONObject; |
23 | /** |
24 | * @author azujev |
25 | * |
26 | */ |
27 | public class YouTubeMP3 {
|
28 | public static String[] getLink(String url) throws ClientProtocolException, IOException {
|
29 | boolean passCode = false; |
30 | String h = ""; |
31 | String title = ""; |
32 | String result = ""; |
33 | String[] returnVal = {"",""};
|
34 | Map<String, String> jsonTable; |
35 | DefaultHttpClient httpClient = new DefaultHttpClient(); |
36 | HttpGet httpInitialGet = new HttpGet("http://www.youtube-mp3.org/api/pushItem/?item=http%3A//www.youtube.com/watch%3Fv%3D" + url + "&xy=_");
|
37 | httpInitialGet.addHeader("Accept-Location", "*");
|
38 | httpInitialGet.addHeader("Referrer", "http://www.youtube-mp3.org");
|
39 | HttpParams params = new SyncBasicHttpParams(); |
40 | HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); |
41 | HttpProtocolParams.setUserAgent(params, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1"); |
42 | httpInitialGet.setParams(params); |
43 | HttpResponse firstResponse = httpClient.execute(httpInitialGet); |
44 | |
45 | try {
|
46 | if (firstResponse.getStatusLine().toString().contains("200")) {
|
47 | passCode = true; |
48 | } |
49 | } finally {
|
50 | httpInitialGet.releaseConnection(); |
51 | } |
52 | |
53 | if (passCode) {
|
54 | while (true) {
|
55 | HttpGet httpStatusGet = new HttpGet("http://www.youtube-mp3.org/api/itemInfo/?video_id=" + url + "&adloc=");
|
56 | httpStatusGet.addHeader("Accept-Location", "*");
|
57 | httpStatusGet.addHeader("Referrer", "http://www.youtube-mp3.org");
|
58 | httpStatusGet.setParams(params); |
59 | HttpResponse secondResponse = httpClient.execute(httpStatusGet); |
60 | HttpEntity secondEntity = secondResponse.getEntity(); |
61 | InputStream is = secondEntity.getContent(); |
62 | try {
|
63 | BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); |
64 | StringBuilder sb = new StringBuilder(); |
65 | String line = null; |
66 | while ((line = reader.readLine()) != null) {
|
67 | sb.append(line + "\n"); |
68 | } |
69 | is.close(); |
70 | result = sb.toString(); |
71 | } catch (Exception e) {
|
72 | e.printStackTrace(); |
73 | } |
74 | |
75 | httpStatusGet.releaseConnection(); |
76 | result = result.replaceAll("\\}.*", "}");
|
77 | result = result.replaceAll(".*?\\{", "{");
|
78 | try {
|
79 | JSONObject jsonData = new JSONObject(result); |
80 | JSONArray jsonArray = jsonData.names(); |
81 | JSONArray valArray = jsonData.toJSONArray(jsonArray); |
82 | jsonTable = new HashMap<String, String>(jsonArray.length()); |
83 | for (int i = 0; i < jsonArray.length(); i++) {
|
84 | jsonTable.put(jsonArray.get(i).toString(), valArray.get(i).toString()); |
85 | } |
86 | if (jsonTable.get("status").equals("serving")) {
|
87 | h = jsonTable.get("h");
|
88 | title = jsonTable.get("title");
|
89 | break; |
90 | } |
91 | } catch (JSONException e) {
|
92 | // TODO Auto-generated catch block |
93 | e.printStackTrace(); |
94 | } |
95 | |
96 | } |
97 | returnVal[0] = "http://www.youtube-mp3.org/get?video_id=" + url + "&h=" + h; |
98 | returnVal[1] = title; |
99 | return returnVal; |
100 | } else {
|
101 | //TODO: Error, vid not downloadable |
102 | } |
103 | return null; |
104 | } |
105 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1006499 |
| Snippet name: | youtube-mp3.org test [dev.] |
| Eternal ID of this version: | #1006499/1 |
| Text MD5: | 94b15dbb49a86f26c9d1a9ad9efd372e |
| Author: | stefan |
| Category: | javax / networking |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-01-11 13:40:47 |
| Source code size: | 4565 bytes / 105 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 923 / 918 |
| Referenced in: | [show references] |