fixed some bugs

This commit is contained in:
Christian Schabesberger 2016-01-28 12:10:50 +01:00
parent 576786c751
commit f152d66cd8
3 changed files with 22 additions and 17 deletions

View File

@ -48,7 +48,7 @@ import info.guardianproject.netcipher.NetCipher;
public class Downloader extends AsyncTask<Void, Integer, Void> { public class Downloader extends AsyncTask<Void, Integer, Void> {
public static final String TAG = "Downloader"; public static final String TAG = "Downloader";
private static final String USER_AGENT = "Mozilla/5.0"; private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
private NotificationManager nm; private NotificationManager nm;
private NotificationCompat.Builder builder; private NotificationCompat.Builder builder;
@ -81,7 +81,8 @@ public class Downloader extends AsyncTask<Void, Integer, Void> {
String ret = ""; String ret = "";
try { try {
URL url = new URL(siteUrl); URL url = new URL(siteUrl);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); //HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
HttpsURLConnection con = NetCipher.getHttpsURLConnection(url);
con.setRequestProperty("Accept-Language", language); con.setRequestProperty("Accept-Language", language);
ret = dl(con); ret = dl(con);
} }
@ -126,7 +127,8 @@ public class Downloader extends AsyncTask<Void, Integer, Void> {
try { try {
URL url = new URL(siteUrl); URL url = new URL(siteUrl);
HttpsURLConnection con = NetCipher.getHttpsURLConnection(url); HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
//HttpsURLConnection con = NetCipher.getHttpsURLConnection(url);
ret = dl(con); ret = dl(con);
} }
catch(Exception e) { catch(Exception e) {
@ -204,18 +206,15 @@ public class Downloader extends AsyncTask<Void, Integer, Void> {
try { try {
if (outputStream != null) { if (outputStream != null) {
outputStream.close(); outputStream.close();
outputStream = null;
} }
if (inputStream != null) { if (inputStream != null) {
inputStream.close(); inputStream.close();
inputStream = null;
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (con != null) { if (con != null) {
con.disconnect(); con.disconnect();
con = null;
} }
} }
return null; return null;

View File

@ -134,7 +134,16 @@ public class VideoItemDetailFragment extends Fragment {
} }
} }
} catch (Exception e) { } catch (Exception e) {
h.post(new Runnable() {
@Override
public void run() {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
// This is poor style, but unless we have better error handling in the
// crawler, this may not be better.
Toast.makeText(VideoItemDetailFragment.this.getActivity(),
R.string.network_error, Toast.LENGTH_LONG).show();
}
});
e.printStackTrace(); e.printStackTrace();
} }
@ -443,12 +452,6 @@ public class VideoItemDetailFragment extends Fragment {
} }
} }
private boolean checkIfLandscape() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels < displayMetrics.widthPixels;
}
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
actionBarHandler.setupMenu(menu, inflater); actionBarHandler.setupMenu(menu, inflater);

View File

@ -64,12 +64,12 @@ public class YoutubeVideoExtractor extends VideoExtractor {
public YoutubeVideoExtractor(String pageUrl) { public YoutubeVideoExtractor(String pageUrl) {
super(pageUrl);//most common videoInfo fields are now set in our superclass, for all services super(pageUrl);//most common videoInfo fields are now set in our superclass, for all services
String pageContents = Downloader.download(cleanUrl(pageUrl)); String pageContent = Downloader.download(cleanUrl(pageUrl));
doc = Jsoup.parse(pageContents, pageUrl); doc = Jsoup.parse(pageContent, pageUrl);
//attempt to load the youtube js player JSON arguments //attempt to load the youtube js player JSON arguments
try { try {
String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", pageContents); String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", pageContent);
//todo: implement this by try and catch. TESTING THE STRING AGAINST EMPTY IS CONSIDERED POOR STYLE !!! //todo: implement this by try and catch. TESTING THE STRING AGAINST EMPTY IS CONSIDERED POOR STYLE !!!
if(jsonString.isEmpty()) { if(jsonString.isEmpty()) {
errorCode = findErrorReason(doc); errorCode = findErrorReason(doc);
@ -543,7 +543,10 @@ public class YoutubeVideoExtractor extends VideoExtractor {
info.title = li.select("span.title").first().text(); info.title = li.select("span.title").first().text();
//this page causes the NullPointerException, after finding it by searching for "tjvg": //this page causes the NullPointerException, after finding it by searching for "tjvg":
//https://www.youtube.com/watch?v=Uqg0aEhLFAg //https://www.youtube.com/watch?v=Uqg0aEhLFAg
String views = li.select("span.view-count").first().text();
//this line is unused
//String views = li.select("span.view-count").first().text();
//Log.i(TAG, "title:"+info.title); //Log.i(TAG, "title:"+info.title);
//Log.i(TAG, "view count:"+views); //Log.i(TAG, "view count:"+views);
try { try {