From 869cb3854946f2d04062e28a7cc6910c265575f3 Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Thu, 13 Dec 2012 03:00:22 +0000 Subject: [PATCH] Descargas en segundo plano, falta control de buffer, arreglada interfaz lista con iconos, quitado recurso calidad default --- res/layout/rowlayout.xml | 56 ++++++++++++++++++++++++++++++++------------------------ res/values/strings.xml | 16 ++-------------- res/xml/prefs.xml | 1 - src/com/upc/pbe/upcnews/Descarrega.java | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------ src/com/upc/pbe/upcnews/Directoris.java | 224 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------- src/com/upc/pbe/upcnews/HLS.java | 21 +++++++++++++++------ src/com/upc/pbe/upcnews/MainActivity.java | 60 ++++++++++++++++++++++++------------------------------------ src/com/upc/pbe/upcnews/Parser.java | 451 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------ src/com/upc/pbe/upcnews/ResourceAdapter.java | 18 +++++++++++------- src/com/upc/pbe/upcnews/UpcApp.java | 9 +-------- src/com/upc/pbe/upcnews/VideoActivity.java | 2 +- 11 files changed, 578 insertions(+), 436 deletions(-) diff --git a/res/layout/rowlayout.xml b/res/layout/rowlayout.xml index e390b54..ed0361a 100644 --- a/res/layout/rowlayout.xml +++ b/res/layout/rowlayout.xml @@ -1,25 +1,33 @@ - - - - - - - + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index c52e8ac..534c40e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -6,7 +6,7 @@ Iniciar aplicació Toca per iniciar. URL del Servidor - Direcció URL del servidor a connectarse (sense http://) + Direcció URL del servidor a connectarse\n(sense http://) Preferencies Ajuda Reproduir @@ -26,20 +26,8 @@ siusplau dirigeixi\'s a la Universitat o escrigui un mail als desenvolupadors.\n\n Necessària la instal·lació de la llibreria Vitamio per reproduïr arxius .ts revistes.upc.es/~imanol/PBE - Qualitat de reproducció - Qualitat inicial de reproducció - - High Quality - Medium Quality - Low Quality - - - 0 - 1 - 2 - - 0 Alerta! Llibreries de Vitamio no instal·lades! Alerta! + Item type \ No newline at end of file diff --git a/res/xml/prefs.xml b/res/xml/prefs.xml index 512ee15..f931580 100644 --- a/res/xml/prefs.xml +++ b/res/xml/prefs.xml @@ -1,5 +1,4 @@ - \ No newline at end of file diff --git a/src/com/upc/pbe/upcnews/Descarrega.java b/src/com/upc/pbe/upcnews/Descarrega.java index b7971c0..999eab7 100644 --- a/src/com/upc/pbe/upcnews/Descarrega.java +++ b/src/com/upc/pbe/upcnews/Descarrega.java @@ -1,102 +1,54 @@ -package com.upc.pbe.upcnews; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.URL; -import java.net.URLConnection; - -import android.app.DownloadManager; -import android.app.DownloadManager.Request; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Environment; -import android.util.Log; - -//Descarrega un arxiu i el guarda o retorna en String -public class Descarrega extends AsyncTask -{ - final static String TAG = "Descarrega"; - private String html; - DownloadManager manager; - - public Descarrega() - { - html = ""; - } - - public Descarrega(DownloadManager man){ - manager = man; - } - - public void descarregarguardar(String url, String path) throws IOException - { - - // Descarrega un arxiu i el guarda - // Creem l'arxiu - File file = new File(path + url.substring(url.lastIndexOf("/")+1, url.length())); - // Iniciem la descarrega - URLConnection conn = new URL(url).openConnection(); - conn.connect(); - Log.d(TAG, "\nDescarregant: \n"); - Log.d(TAG, " >> URL: " + url + " >> Desti: " + path + " >> Tamany: " - + conn.getContentLength() + " bytes"); - // Llegeix cada byte i l'escriu en un arxiu fins que arriba a -1 - InputStream in = conn.getInputStream(); - OutputStream out = new FileOutputStream(file); - byte data[] = new byte[102400]; //Mejor throughput!! - int count; - while((count = in.read(data)) != -1) - { - out.write(data,0,count); - } - out.flush(); - out.close(); - in.close(); - - } - - public void descarrega(String url, String path, String name) throws IOException{ - - Request req = new Request(Uri.parse(url)); - - //req.setVisibleInDownloadsUi(false); - req.setDestinationInExternalPublicDir(path, name); - manager.enqueue(req); - Log.d(TAG, "\nDescarregant: \n"); - Log.d(TAG, " >> URL: " + url + " >> Desti: " + path); - - } - - protected String doInBackground(String url) throws IOException - { - // Descarrega un arxiu i el retorna en un String - html = ""; - // Iniciem la connexi� i creem els Streams - URLConnection conn = new URL(url).openConnection(); - BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); - // Iniciem la descarrega i anem guardant al String - Log.d(TAG, "\nDescarregant: \n"); - Log.d(TAG, ">> URL: " + url + " >> Tamany: " + conn.getContentLength() - + " bytes"); - String inputLine; - while ((inputLine = in.readLine()) != null) - { - html = html + "\n" + inputLine; - } - Log.d(TAG, "Descarrega finalitzada"); - in.close(); - return html; - } - - @Override - protected Object doInBackground(Object... arg0) - { - // Metode Overrided, no te utilitat - return null; - } -} +package com.upc.pbe.upcnews; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; + +import android.content.Context; +import android.os.AsyncTask; +import android.util.Log; +import android.widget.Toast; + +public class Descarrega extends AsyncTask +{ + final static String TAG = "Descarrega"; + private Context ctx; + + public Descarrega(Context c) + { + ctx = c; + } + + @Override + protected String doInBackground(URL... urls) + { + String html = ""; + // Iniciem la connexi� i creem els Streams + try + { + URLConnection conn = urls[0].openConnection(); + BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); + // Iniciem la descarrega i anem guardant al String + Log.d(TAG, "\nDescarregant: \n"); + Log.d(TAG, ">> URL: " + urls[0] + " >> Tamany: " + conn.getContentLength() + " bytes"); + String inputLine; + while ((inputLine = in.readLine()) != null) + { + html += inputLine + "\n"; + } + in.close(); + Log.d(TAG, "Descarrega finalitzada"); + } + catch(IOException e) + { + this.cancel(true); + Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show(); + return ""; + } + return html; + } + +} + diff --git a/src/com/upc/pbe/upcnews/Directoris.java b/src/com/upc/pbe/upcnews/Directoris.java index e037c49..301c3dc 100644 --- a/src/com/upc/pbe/upcnews/Directoris.java +++ b/src/com/upc/pbe/upcnews/Directoris.java @@ -1,7 +1,9 @@ package com.upc.pbe.upcnews; import java.io.IOException; +import java.net.URL; import java.util.ArrayList; +import java.util.concurrent.ExecutionException; import android.app.Activity; import android.app.DownloadManager; @@ -16,147 +18,195 @@ import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; +import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; //Segona Activity, mostra els directoris i arxius del servidor -public class Directoris extends Activity implements OnItemClickListener { - +public class Directoris extends Activity implements OnItemClickListener +{ + final static String TAG = "Directoris"; - private Descarrega d = new Descarrega(); private String URL, currentFolder; private HTMLParser parser; - public void onCreate(Bundle savedInstanceState){ - //Creem el layout + public void onCreate(Bundle savedInstanceState) + { + // Creem el layout Log.d(TAG, "onCreated"); super.onCreate(savedInstanceState); - //Passem del layout anterior al actual + // Passem del layout anterior al actual setContentView(R.layout.dirs); - //Canviem la direccio de la URL a la actual + // Canviem la direccio de la URL a la actual currentFolder = ((UpcApp) getApplication()).getUrl() + "/"; URL = currentFolder; - //Creem un HTMLParser + // Creem un HTMLParser parser = new HTMLParser(URL); - //Fem una llista ListView i la omplim amb la informacio trobada - ((ListView)findViewById(R.id.listView1)).setOnItemClickListener(this); + // Fem una llista ListView i la omplim amb la informacio trobada + ((ListView) findViewById(R.id.listView1)).setOnItemClickListener(this); this.showResources(); } - - public void showResources(){ - //Actualitza la informacio que mostra la ListView a mesura que ens desplacem pels directoris + + public void showResources() + { + // Actualitza la informacio que mostra la ListView a mesura que ens + // desplacem pels directoris ArrayList entries; - try{ - entries = parser.parse(d.doInBackground(currentFolder)); + Descarrega d = new Descarrega(this); + try + { + d.execute(new URL(currentFolder)); + entries = parser.parse(d.get()); this.createEntries(entries); } - catch (IOException e){ + catch (InterruptedException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (ExecutionException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (IOException e) + { // Nunca llegara aqui la cosa, y si lo hace ES CULPA DEL SERVIDOR!! } } - - public void createEntries(ArrayList directories){ - //Crea les entrades de la ListView + + public void createEntries(ArrayList directories) + { + // Crea les entrades de la ListView String[] entries = directories.toArray(new String[directories.size()]); ListView listView = (ListView) findViewById(R.id.listView1); listView.setAdapter(null); ResourceAdapter adapter = new ResourceAdapter(this, R.layout.rowlayout, entries); listView.setAdapter(adapter); } - + public void onItemClick(AdapterView parent, View view, int position, long id) { //Determina el funcionament al clickar en una de les entrades de al ListView - String path = ((TextView)view).getText().toString(); + String path = ((TextView)((RelativeLayout)view).findViewById(R.id.rowTextView)).getText().toString(); //Si es un m3u8, el descarrega, parseja i inicia la reproduccio - if(path.endsWith(".m3u8")){ + if(path.endsWith(".m3u8")) + { path = currentFolder + path; String playlist; - try{ - //Descarreguem m3u8 - playlist = d.doInBackground(path); - Parser p = new Parser(path.substring(0, path.lastIndexOf("/") + 1), this); - try{ - //Parsing m3u8 - ArrayList m3u8parsed = p.parseFile(playlist); - Log.d(TAG, "Parsing completat"); - //Creem un gestor HLS - DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); - HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath(), manager); - ((UpcApp)getApplication()).setHLS(h); - //Iniciem la reproduccio - Intent mIntent = new Intent(this, VideoActivity.class); - if(((UpcApp)getApplication()).getHLS() != null) { - startActivity(mIntent); + try + { + Descarrega d = new Descarrega(this); + //Descarreguem m3u8 + d.execute(new URL(path)); + playlist = d.get(); + Parser p = new Parser(path.substring(0, path.lastIndexOf("/") + 1), this); + try + { + //Parsing m3u8 + ArrayList m3u8parsed = p.parseFile(playlist); + Log.d(TAG, "Parsing completat"); + //Creem un gestor HLS + DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); + HLS h = new HLS(m3u8parsed,((UpcApp)getApplication()).getLocalPath(), manager); + ((UpcApp)getApplication()).setHLS(h); + //Iniciem la reproduccio + Intent mIntent = new Intent(this, VideoActivity.class); + if(((UpcApp)getApplication()).getHLS() != null) + { + startActivity(mIntent); + } + else + { + Toast.makeText(this, "Error en gestor HLS", Toast.LENGTH_LONG).show(); + } + } + catch (ErrorException e) + { + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); + Log.d(TAG, e.getMessage()); + } + catch (WarningException e) + { + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); + Log.d(TAG, e.getMessage()); } - else { - Toast.makeText(this, "Error en gestor HLS", Toast.LENGTH_LONG).show(); + catch (InfoException e) + { + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); + Log.d(TAG, e.getMessage()); } } - catch (ErrorException e){ - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); - Log.d(TAG, e.getMessage()); + catch (IOException e1) + { + // Nunca llegara aqui la cosa, y si lo hace ES CULPA DEL SERVIDOR!! } - catch (WarningException e){ - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); - Log.d(TAG, e.getMessage()); + catch (InterruptedException e1) + { + // TODO Auto-generated catch block + e1.printStackTrace(); } - catch (InfoException e){ - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); - Log.d(TAG, e.getMessage()); + catch (ExecutionException e1) + { + // TODO Auto-generated catch block + e1.printStackTrace(); } } - catch (IOException e1){ - // Nunca llegara aqui la cosa, y si lo hace ES CULPA DEL SERVIDOR!! - } - - } //Si es una carpeta, hi entra i mostra el seu contingut - else{ - if(!path.startsWith("http://")){ + else + { + if(!path.startsWith("http://")) + { currentFolder += path; } - else{ + else + { currentFolder = path; } showResources(); } } - - public boolean onKeyDown(int keyCode, KeyEvent event) { - //Determina el funcionament al apretar la tecla de tornar enrere - if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){ - if(currentFolder.equals(URL)){ - super.finish(); - return true; - } - currentFolder = currentFolder.substring(0, currentFolder.length()-1); - currentFolder = currentFolder.substring(0,currentFolder.lastIndexOf("/")+1); - showResources(); - return true; - } - return super.onKeyDown(keyCode, event); + + public boolean onKeyDown(int keyCode, KeyEvent event) + { + // Determina el funcionament al apretar la tecla de tornar enrere + if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) + { + if (currentFolder.equals(URL)) + { + super.finish(); + return true; + } + currentFolder = currentFolder.substring(0, currentFolder.length() - 1); + currentFolder = currentFolder.substring(0, currentFolder.lastIndexOf("/") + 1); + showResources(); + return true; + } + return super.onKeyDown(keyCode, event); } - - public boolean onCreateOptionsMenu(Menu menu) { - //Determina el funcionament al apretar la tecla d'opcions + + public boolean onCreateOptionsMenu(Menu menu) + { + // Determina el funcionament al apretar la tecla d'opcions getMenuInflater().inflate(R.menu.menu, menu); Log.d(TAG, "Menu"); return true; } - public boolean onOptionsItemSelected(MenuItem item) { - //Determina el funcionament al clickar en el menu d'opcions - switch (item.getItemId()) { - case R.id.itemprefs: - startActivity(new Intent(this, Prefs.class)); - Log.d(TAG, "Preferencies"); - return true; - case R.id.itemhelp: - startActivity(new Intent(this, Help.class)); - Log.d(TAG, "Help"); - return true; - default: - return false; + public boolean onOptionsItemSelected(MenuItem item) + { + // Determina el funcionament al clickar en el menu d'opcions + switch (item.getItemId()) + { + case R.id.itemprefs: + startActivity(new Intent(this, Prefs.class)); + Log.d(TAG, "Preferencies"); + return true; + case R.id.itemhelp: + startActivity(new Intent(this, Help.class)); + Log.d(TAG, "Help"); + return true; + default: + return false; } } } \ No newline at end of file diff --git a/src/com/upc/pbe/upcnews/HLS.java b/src/com/upc/pbe/upcnews/HLS.java index 9d3cda2..8c30f23 100644 --- a/src/com/upc/pbe/upcnews/HLS.java +++ b/src/com/upc/pbe/upcnews/HLS.java @@ -5,7 +5,10 @@ import java.io.IOException; import java.util.ArrayList; import android.app.DownloadManager; +import android.app.DownloadManager.Request; +import android.content.Context; import android.net.TrafficStats; +import android.net.Uri; import android.util.Log; //Gestor del protocol HTTP Live Streaming @@ -21,7 +24,7 @@ public class HLS private int currentSegment; private boolean endReached; private String localFolder; - private Descarrega d; + private DownloadManager dm; private BandwidthMeasurer bm; @@ -42,8 +45,6 @@ public class HLS endReached = false; this.localFolder = localFolder; bm = new BandwidthMeasurer(); - - d = new Descarrega(manager); } public void loadVideo() @@ -75,7 +76,7 @@ public class HLS Log.d(TAG, seg.getName() + " " + seg.getURL()); long startTime = System.currentTimeMillis(); long segmentBytes = TrafficStats.getTotalRxBytes(); - d.descarregarguardar(seg.getURL(), localFolder); + descarregarguardar(seg.getURL(), localFolder); double bps = bm.Measure(segmentBytes, startTime); Log.d(TAG, "Velocitat actual (KB/s): " + (bps / 8e3)); if ((bps <= qualities.get(currentQuality).getQuality()) && (bps != -1)) @@ -117,6 +118,14 @@ public class HLS return path; } + public void descarregarguardar(String url, String path) + { + Request req = new Request(Uri.parse(url)); + req.setVisibleInDownloadsUi(false); + req.setDestinationUri(Uri.parse("file://"+path + url.substring(url.lastIndexOf("/")+1, url.length()))); + dm.enqueue(req); + } + public String previous() throws IOException { Segment seg = null; @@ -128,8 +137,8 @@ public class HLS return localFolder + seg.getURL().substring(seg.getURL().lastIndexOf("/") + 1, seg.getURL().length()); } - public void setDefQuality(int q) + public void startDownloadManager(Context ctx) { - currentQuality = q; + dm = (DownloadManager) ctx.getSystemService("download"); } } \ No newline at end of file diff --git a/src/com/upc/pbe/upcnews/MainActivity.java b/src/com/upc/pbe/upcnews/MainActivity.java index d39db77..873d6c8 100644 --- a/src/com/upc/pbe/upcnews/MainActivity.java +++ b/src/com/upc/pbe/upcnews/MainActivity.java @@ -1,20 +1,16 @@ package com.upc.pbe.upcnews; import java.io.File; -import java.io.IOException; import java.net.MalformedURLException; +import java.net.URL; import java.util.List; +import java.util.concurrent.ExecutionException; import android.app.Activity; -import android.app.DownloadManager; -import android.app.DownloadManager.Request; -import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; -import android.net.Uri; import android.os.Bundle; -import android.os.Environment; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -48,19 +44,7 @@ public class MainActivity extends Activity implements OnClickListener { if(tempFolder.mkdirs()) { Log.d(TAG,"Directori " + tempFolder.toString() + " creat"); } - Log.d(TAG, Environment.getExternalStorageDirectory().toString()); - - DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); - Request req = new Request(Uri.parse("http://10.0.2.157/upload/segments/pbe1.ts")); - - //req.setVisibleInDownloadsUi(false); - req.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory().toString()+"/UPC NEWS", "b.ts"); - manager.enqueue(req); - - - - - + //Creem els botons i text URLText = (TextView) findViewById(R.id.textViewUrl); buttonDescarrega = (ImageButton) findViewById(R.id.button); @@ -87,26 +71,29 @@ public class MainActivity extends Activity implements OnClickListener { public void onClick(View v) { //Al polsar el boto s'inicia la descarrega Log.d(TAG, "onClicked"); - this.descarregar(); - if(!html.equals("EMPTY")) { - ((UpcApp) getApplication()).setDesc(html); - startActivity(new Intent(this, Directoris.class)); + Descarrega d = new Descarrega(this); + try + { + d.execute(new URL(((UpcApp)getApplication()).getUrl())); + html = d.get(); } - } - - public void descarregar() { - //Descarrega del document HTML de la URL especificada - //Si hi ha errors, els mostrem en Toasts - Descarrega d = new Descarrega(); - html="EMPTY"; - try { - html = (String) d.doInBackground(((UpcApp)getApplication()).getUrl()); + catch (InterruptedException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); } - catch(MalformedURLException e) { - Toast.makeText(this, "URL invalida", Toast.LENGTH_LONG).show(); + catch (ExecutionException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (MalformedURLException e) + { + Toast.makeText(this, "URL Malformada", Toast.LENGTH_LONG).show(); } - catch(IOException e) { - Toast.makeText(this, "No s'ha pogut trobar la URL", Toast.LENGTH_LONG).show(); + if(!html.equals("")) { + ((UpcApp) getApplication()).setDesc(html); + startActivity(new Intent(this, Directoris.class)); } } @@ -141,6 +128,7 @@ public class MainActivity extends Activity implements OnClickListener { return false; } } + /* * COSAS POR HACER * (NORMAL) Quitar la elección de calidad al inicio? Discutir diff --git a/src/com/upc/pbe/upcnews/Parser.java b/src/com/upc/pbe/upcnews/Parser.java index cb7ce87..0c9d63f 100644 --- a/src/com/upc/pbe/upcnews/Parser.java +++ b/src/com/upc/pbe/upcnews/Parser.java @@ -3,79 +3,91 @@ package com.upc.pbe.upcnews; import java.io.IOException; import java.net.MalformedURLException; import java.util.ArrayList; +import java.util.concurrent.ExecutionException; +import java.net.URL; -import android.app.Activity; +import android.content.Context; import android.widget.Toast; //Parser d'arxius m3u8 -public class Parser{ - +public class Parser +{ + private static final String STARTWORD = "#EXTM3U"; - private String path; //CWD, completes implicit paths such as "file.m3u8" appending the CWD in order to download the file - private int fileType; //Indica si es segment list o media list + private String path; // CWD, completes implicit paths such as "file.m3u8" + // appending the CWD in order to download the file + private int fileType; // Indica si es segment list o media list private int currentLine; - private int currentSegment; //Cada segment de cada qualitat distinta - private int currentList; //Index de cada recurso distint + private int currentSegment; // Cada segment de cada qualitat distinta + private int currentList; // Index de cada recurso distint private boolean expectSegment = false; private boolean expectList = false; - private Descarrega download; - private Activity caller; //On enviar les notificacions i warnings - private boolean validated; //Indica si la llista comen�a amb #EXTM3U o no + private Context ctx; // On enviar les notificacions i warnings + private boolean validated; // Indica si la llista comen�a amb #EXTM3U o no private String server; - public Parser(String p, Activity caller){ - this.caller = caller; + public Parser(String p, Context caller) + { + ctx = caller; path = p; String host = p.substring(7); - server = host.substring(0,host.indexOf("/")); + server = host.substring(0, host.indexOf("/")); currentLine = 0; currentSegment = 0; currentList = 0; - fileType = -1;//-1 indica UNDETERMINED, 0 indica SEGMENTS, 1 indica MEDIA - download = new Descarrega(); + fileType = -1;// -1 indica UNDETERMINED, 0 indica SEGMENTS, 1 indica + // MEDIA validated = false; } - public ArrayList parseFile(String file) throws ErrorException, WarningException, InfoException { - //Parseja un arxiu m3u8 + public ArrayList parseFile(String file) throws ErrorException, WarningException, InfoException + { + // Parseja un arxiu m3u8 ArrayList lists = new ArrayList(); lists.add(new ParentList("")); lists.get(0).getLists().add(new Video(-1)); String[] lines = file.split("\n"); - for (int i = 0; i < lines.length; i++){ - if (lines[i].endsWith("\\")){ - //Barreja les entrades multilinea, que son les que acaben en backslash + for (int i = 0; i < lines.length; i++) + { + if (lines[i].endsWith("\\")) + { + // Barreja les entrades multilinea, que son les que acaben en + // backslash lines[++i] = lines[i - 1].substring(0, lines[i - 1].indexOf("\\") - 1) + lines[i]; } - try{ + try + { parseLine(lines[i], lists); } - catch (InfoException iE){ - Toast.makeText(caller, iE.getMessage(), Toast.LENGTH_SHORT).show(); + catch (InfoException iE) + { + Toast.makeText(ctx, iE.getMessage(), Toast.LENGTH_SHORT).show(); } - catch (WarningException wE){ - Toast.makeText(caller, wE.getMessage(), Toast.LENGTH_SHORT).show(); + catch (WarningException wE) + { + Toast.makeText(ctx, wE.getMessage(), Toast.LENGTH_SHORT).show(); } } /* - * Esto contiene una lista de RECURSOS, - * que a su vez contiene una lista de CALIDADES. - * Si no te gusta mis VERSOS, - * te mando a la mierda sin SUTILIDADES. + * Esto contiene una lista de RECURSOS, que a su vez contiene una lista + * de CALIDADES. Si no te gusta mis VERSOS, te mando a la mierda sin + * SUTILIDADES. * * -- Imanol, hasta las cejas de cafeina. * * PD: En el ultimo nivel de profundidad hay una lista de segmentos * (debajo de calidades). Alli esta el autentico tesoro de Narnia. */ - for (int i = 0; i < lists.size(); i++){ + for (int i = 0; i < lists.size(); i++) + { sortQuality(lists.get(i)); } return lists; } - private int searchID(String ID, ArrayList lists){ + private int searchID(String ID, ArrayList lists) + { for (int i = 0; i < lists.size(); i++) { if (lists.get(i).getID().equals(ID)) @@ -86,110 +98,154 @@ public class Parser{ return -1; } - private void sortQuality(ParentList ppls){ + private void sortQuality(ParentList ppls) + { ArrayList