Commit 8885baa7a96c65ae0cc92b8460a89e3406081982

Authored by Imanol-Mikel Barba Sabariego
1 parent cfb7213e

Navegador HTTP funcional 100% :DDDDD

src/com/upc/pbe/upcnews/Directoris.java
@@ -15,6 +15,7 @@ import android.widget.ArrayAdapter; @@ -15,6 +15,7 @@ import android.widget.ArrayAdapter;
15 import android.widget.ListView; 15 import android.widget.ListView;
16 import android.widget.TextView; 16 import android.widget.TextView;
17 import android.widget.AdapterView.OnItemClickListener; 17 import android.widget.AdapterView.OnItemClickListener;
  18 +import android.widget.Toast;
18 19
19 public class Directoris extends Activity implements OnItemClickListener 20 public class Directoris extends Activity implements OnItemClickListener
20 { 21 {
@@ -77,60 +78,17 @@ public class Directoris extends Activity implements OnItemClickListener @@ -77,60 +78,17 @@ public class Directoris extends Activity implements OnItemClickListener
77 public void onItemClick(AdapterView<?> parent, View view, int position, long id) 78 public void onItemClick(AdapterView<?> parent, View view, int position, long id)
78 { 79 {
79 String path = ((TextView)view).getText().toString(); 80 String path = ((TextView)view).getText().toString();
80 - if(!path.startsWith("http://")) 81 + if(path.endsWith(".m3u8"))
81 { 82 {
82 - currentFolder += path;  
83 - }  
84 - else  
85 - {  
86 - currentFolder = path;  
87 - }  
88 - showResources();  
89 - }  
90 -  
91 - public void showResources()  
92 - {  
93 - ArrayList<String> entries = parser.parse(d.doInBackground(currentFolder));  
94 - this.createEntries(entries);  
95 - }  
96 -  
97 - /*public void buttonClicked(Button b)  
98 - {  
99 -  
100 - // Descarrega de la p�gina HTML del directori i busqueda d'un .m3u8 en  
101 - // ella  
102 - Log.d(TAG, "Click on " + b.getText());  
103 - String path = b.getText().toString();  
104 - if (path.equals("<Current Folder>"))  
105 - {  
106 - path = "";  
107 - }  
108 - path += "/";  
109 - d = new Descarrega();  
110 - String str = d.doInBackground(url + "/" + path);  
111 - HTMLParser pars = new HTMLParser();  
112 -  
113 - String urlvideo = pars.findvideo(str, url + "/" + path);  
114 - Log.d(TAG, urlvideo);  
115 -  
116 - // Descarrega de l'arxiu .m3u8 (si existeix) i parseig  
117 - if (urlvideo.equalsIgnoreCase("No s'ha trobat"))  
118 - {  
119 - Toast.makeText(this, "The directory " + b.getText()  
120 - + " does not contain any '.m3u8' file", Toast.LENGTH_LONG).show();  
121 - }  
122 - else  
123 - {  
124 - d = new Descarrega();  
125 - String m3u8 = d.doInBackground(urlvideo);  
126 - Log.d(TAG, m3u8);  
127 - Parser p = new Parser(urlvideo.substring(0, urlvideo.lastIndexOf("/") + 1), this); 83 + path = currentFolder + path;
  84 + String playlist = d.doInBackground(path);
  85 + Parser p = new Parser(path.substring(0, path.lastIndexOf("/") + 1), this);
128 try 86 try
129 { 87 {
130 - ArrayList<ParentList> m3u8parsed = p.parseFile(m3u8);  
131 - Log.d(TAG, "parsed completed");  
132 - HLS h = new HLS(m3u8parsed);  
133 - h.start(); 88 + ArrayList<ParentList> m3u8parsed = p.parseFile(playlist);
  89 + Log.d(TAG, "parsing completed");
  90 + //HLS h = new HLS(m3u8parsed);
  91 + //h.start();
134 92
135 } 93 }
136 catch (ErrorException e) 94 catch (ErrorException e)
@@ -149,14 +107,26 @@ public class Directoris extends Activity implements OnItemClickListener @@ -149,14 +107,26 @@ public class Directoris extends Activity implements OnItemClickListener
149 Log.d(TAG, e.getMessage()); 107 Log.d(TAG, e.getMessage());
150 } 108 }
151 109
152 - }*/  
153 -  
154 - /*  
155 - * String urlvid = null; ((UpcApp) getApplication()).setDesc(urlvid);  
156 - *  
157 - * startActivity(new Intent(this, VideoActivity.class));  
158 -  
159 - }*/ 110 + }
  111 + else //Se trata de una carpeta
  112 + {
  113 + if(!path.startsWith("http://"))
  114 + {
  115 + currentFolder += path;
  116 + }
  117 + else
  118 + {
  119 + currentFolder = path;
  120 + }
  121 + showResources();
  122 + }
  123 + }
  124 +
  125 + public void showResources()
  126 + {
  127 + ArrayList<String> entries = parser.parse(d.doInBackground(currentFolder));
  128 + this.createEntries(entries);
  129 + }
160 130
161 public boolean onKeyDown(int keyCode, KeyEvent event) { 131 public boolean onKeyDown(int keyCode, KeyEvent event) {
162 if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) 132 if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
src/com/upc/pbe/upcnews/HTMLParser.java
@@ -24,7 +24,7 @@ public class HTMLParser @@ -24,7 +24,7 @@ public class HTMLParser
24 resources.clear(); 24 resources.clear();
25 } 25 }
26 parseDirectories(resources,code); 26 parseDirectories(resources,code);
27 - //parseFiles(resources,code); 27 + parseFiles(resources,code);
28 return resources; 28 return resources;
29 } 29 }
30 30
@@ -69,13 +69,9 @@ public class HTMLParser @@ -69,13 +69,9 @@ public class HTMLParser
69 } 69 }
70 } 70 }
71 71
72 - /*public ArrayList<String> findvideo(String code, String direccio) 72 + public void parseFiles(ArrayList<String> resources, String code)
73 { 73 {
74 - // Donada la direcci� del directori i el html del mateix, troba l'arxiu  
75 - // .m3u8 i retorna  
76 - // la url directe.  
77 String[] split = code.split("\n"); 74 String[] split = code.split("\n");
78 -  
79 for (int i = 0; i < split.length; i++) 75 for (int i = 0; i < split.length; i++)
80 { 76 {
81 while (split[i].startsWith("<!--")) 77 while (split[i].startsWith("<!--"))
@@ -90,20 +86,18 @@ public class HTMLParser @@ -90,20 +86,18 @@ public class HTMLParser
90 { 86 {
91 if (split[i].contains("href=")) //Esto tiene buena pinta 87 if (split[i].contains("href=")) //Esto tiene buena pinta
92 { 88 {
93 - String dirpath = split[i].substring(split[i].indexOf("href=\"") + 6); //Eliminamos morralla del principio.  
94 - dirpath = dirpath.substring(0, dirpath.indexOf("\"")); //Quitamos la morralla del final, nos queda el valor de href sólo.  
95 - if(dirpath.lastIndexOf("/") != -1) //Mira que sea una carpeta y no un fichero suelto. 89 + String filepath = split[i].substring(split[i].indexOf("href=\"") + 6); //Eliminamos morralla del principio.
  90 + filepath = filepath.substring(0, filepath.indexOf("\"")); //Quitamos la morralla del final, nos queda el valor de href sólo.
  91 + if(filepath.endsWith(".m3u8")) //Mira que sea una lista.
96 { 92 {
97 - dirpath = dirpath.substring(0,dirpath.lastIndexOf("/")+1); //Elimina parte que no es carpeta  
98 - if(!directoris.contains(dirpath)) //No seamos repetitivos 93 + if(!resources.contains(filepath)) //No seamos repetitivos
99 { 94 {
100 - directoris.add(dirpath); 95 + resources.add(filepath);
101 } 96 }
102 - Log.d(TAG, "DIRECTORY FOUND: " + dirpath); 97 + Log.d(TAG, "PLAYLIST FOUND: " + filepath);
103 } 98 }
104 } 99 }
105 } 100 }
106 } 101 }
107 - return "No s'ha trobat";  
108 - }*/ 102 + }
109 } 103 }