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 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 NotificationCompat.Builder builder;
@ -81,7 +81,8 @@ public class Downloader extends AsyncTask<Void, Integer, Void> {
String ret = "";
try {
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);
ret = dl(con);
}
@ -126,7 +127,8 @@ public class Downloader extends AsyncTask<Void, Integer, Void> {
try {
URL url = new URL(siteUrl);
HttpsURLConnection con = NetCipher.getHttpsURLConnection(url);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
//HttpsURLConnection con = NetCipher.getHttpsURLConnection(url);
ret = dl(con);
}
catch(Exception e) {
@ -204,18 +206,15 @@ public class Downloader extends AsyncTask<Void, Integer, Void> {
try {
if (outputStream != null) {
outputStream.close();
outputStream = null;
}
if (inputStream != null) {
inputStream.close();
inputStream = null;
}
} catch (IOException e) {
e.printStackTrace();
}
if (con != null) {
con.disconnect();
con = null;
}
}
return null;

View File

@ -134,7 +134,16 @@ public class VideoItemDetailFragment extends Fragment {
}
}
} catch (Exception e) {
progressBar.setVisibility(View.GONE);
h.post(new Runnable() {
@Override
public void run() {
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();
}
@ -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
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
actionBarHandler.setupMenu(menu, inflater);

View File

@ -64,12 +64,12 @@ public class YoutubeVideoExtractor extends VideoExtractor {
public YoutubeVideoExtractor(String pageUrl) {
super(pageUrl);//most common videoInfo fields are now set in our superclass, for all services
String pageContents = Downloader.download(cleanUrl(pageUrl));
doc = Jsoup.parse(pageContents, pageUrl);
String pageContent = Downloader.download(cleanUrl(pageUrl));
doc = Jsoup.parse(pageContent, pageUrl);
//attempt to load the youtube js player JSON arguments
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 !!!
if(jsonString.isEmpty()) {
errorCode = findErrorReason(doc);
@ -543,7 +543,10 @@ public class YoutubeVideoExtractor extends VideoExtractor {
info.title = li.select("span.title").first().text();
//this page causes the NullPointerException, after finding it by searching for "tjvg":
//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, "view count:"+views);
try {