From f152d66cd8217e8522aa4c38bc29b59a38a54116 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 28 Jan 2016 12:10:50 +0100 Subject: [PATCH] fixed some bugs --- .../java/org/schabi/newpipe/Downloader.java | 11 +++++------ .../schabi/newpipe/VideoItemDetailFragment.java | 17 ++++++++++------- .../services/youtube/YoutubeVideoExtractor.java | 11 +++++++---- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/Downloader.java b/app/src/main/java/org/schabi/newpipe/Downloader.java index e0a9bf5d4..6bd982575 100644 --- a/app/src/main/java/org/schabi/newpipe/Downloader.java +++ b/app/src/main/java/org/schabi/newpipe/Downloader.java @@ -48,7 +48,7 @@ import info.guardianproject.netcipher.NetCipher; public class Downloader extends AsyncTask { 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 { 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 { 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 { 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; diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index 77c1d5b78..e3a924c64 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -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); diff --git a/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java b/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java index 84548539a..6477305cf 100644 --- a/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/services/youtube/YoutubeVideoExtractor.java @@ -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 {