1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-09-29 15:30:51 +00:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-01-04 00:11:51 +01:00
commit c2400aea4d
10 changed files with 104 additions and 37 deletions

View File

@ -36,6 +36,7 @@ NewPipe does not use any Google framework libraries, or the YouTube API. It only
* Open a video in Kodi * Open a video in Kodi
* Show Next/Related videos * Show Next/Related videos
* Search YouTube in a specific language * Search YouTube in a specific language
* Orbot/Tor support (no streaming yet)
### Coming Features ### Coming Features

View File

@ -8,8 +8,8 @@ android {
applicationId "org.schabi.newpipe" applicationId "org.schabi.newpipe"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 23 targetSdkVersion 23
versionCode 10 versionCode 11
versionName "0.7.1" versionName "0.7.2"
} }
buildTypes { buildTypes {
release { release {

View File

@ -15,10 +15,13 @@ public class App extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
// if Orbot is installed, then default to using Tor, the user can still override
if (OrbotHelper.requestStartTor(this)) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if(prefs.getBoolean(getString(R.string.useTorKey), false)) {
configureTor(prefs.getBoolean(getString(R.string.useTor), true)); OrbotHelper.requestStartTor(this);
configureTor(true);
} else {
configureTor(false);
} }
} }

View File

@ -1,23 +1,23 @@
package org.schabi.newpipe; package org.schabi.newpipe;
import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@ -47,7 +47,6 @@ import info.guardianproject.netcipher.NetCipher;
public class Downloader { public class Downloader {
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";
/**Download the text file at the supplied URL as in download(String), /**Download the text file at the supplied URL as in download(String),
@ -59,7 +58,7 @@ public class Downloader {
String ret = ""; String ret = "";
try { try {
URL url = new URL(siteUrl); URL url = new URL(siteUrl);
HttpsURLConnection con = NetCipher.getHttpsURLConnection(url); HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setRequestProperty("Accept-Language", language); con.setRequestProperty("Accept-Language", language);
ret = dl(con); ret = dl(con);
} }
@ -68,8 +67,9 @@ public class Downloader {
} }
return ret; return ret;
} }
/**Common functionality between download(String url) and download(String url, String language)*/ /**Common functionality between download(String url) and download(String url, String language)*/
private static String dl(HttpURLConnection con) throws IOException { private static String dl(HttpsURLConnection con) throws IOException {
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();
try { try {

View File

@ -1,6 +1,5 @@
package org.schabi.newpipe; package org.schabi.newpipe;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
@ -22,7 +21,8 @@ public class Localization {
public static Locale getPreferredLocale(Context context) { public static Locale getPreferredLocale(Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String languageCode = sp.getString(String.valueOf(R.string.searchLanguage), "en"); String languageCode = sp.getString(String.valueOf(R.string.searchLanguagePreference),
context.getString(R.string.defaultLanguageItem));
if(languageCode.length() == 2) { if(languageCode.length() == 2) {
return new Locale(languageCode); return new Locale(languageCode);

View File

@ -1,14 +1,19 @@
package org.schabi.newpipe; package org.schabi.newpipe;
import android.app.Activity; import android.app.Activity;
import android.app.SharedElementCallback;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
@ -40,7 +45,7 @@ import info.guardianproject.netcipher.proxy.OrbotHelper;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>. * along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/ */
public class SettingsActivity extends PreferenceActivity { public class SettingsActivity extends PreferenceActivity {
private static final int REQUEST_INSTALL_ORBOT = 0x1234; private static final int REQUEST_INSTALL_ORBOT = 0x1234;
private AppCompatDelegate mDelegate = null; private AppCompatDelegate mDelegate = null;
@ -59,37 +64,90 @@ public class SettingsActivity extends PreferenceActivity {
} }
public static class SettingsFragment extends PreferenceFragment { public static class SettingsFragment extends PreferenceFragment{
SharedPreferences.OnSharedPreferenceChangeListener prefListener;
// get keys
String DEFAULT_RESOLUTION_PREFERENCE;
String DEFAULT_AUDIO_FORMAT_PREFERENCE;
String SEARCH_LANGUAGE_PREFERENCE;
String DOWNLOAD_PATH_PREFERENCE;
String USE_TOR_KEY;
private ListPreference defaultResolutionPreference;
private ListPreference defaultAudioFormatPreference;
private ListPreference searchLanguagePreference;
private EditTextPreference downloadPathPreference;
private CheckBoxPreference useTorCheckBox; private CheckBoxPreference useTorCheckBox;
private SharedPreferences defaultPreferences;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings_screen); addPreferencesFromResource(R.xml.settings_screen);
// if Orbot is installed, then default to using Tor, the user can still override
useTorCheckBox = (CheckBoxPreference) findPreference(getString(R.string.useTor));
final Activity activity = getActivity(); final Activity activity = getActivity();
final boolean useTor = OrbotHelper.isOrbotInstalled(activity);
useTorCheckBox.setDefaultValue(useTor); defaultPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
useTorCheckBox.setChecked(useTor);
useTorCheckBox.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { // get keys
DEFAULT_RESOLUTION_PREFERENCE =getString(R.string.defaultResolutionPreference);
DEFAULT_AUDIO_FORMAT_PREFERENCE =getString(R.string.defaultAudioFormatPreference);
SEARCH_LANGUAGE_PREFERENCE =getString(R.string.searchLanguagePreference);
DOWNLOAD_PATH_PREFERENCE = getString(R.string.downloadPathPreference);
USE_TOR_KEY = getString(R.string.useTorKey);
// get pref objects
defaultResolutionPreference =
(ListPreference) findPreference(DEFAULT_RESOLUTION_PREFERENCE);
defaultAudioFormatPreference =
(ListPreference) findPreference(DEFAULT_AUDIO_FORMAT_PREFERENCE);
searchLanguagePreference =
(ListPreference) findPreference(SEARCH_LANGUAGE_PREFERENCE);
downloadPathPreference =
(EditTextPreference) findPreference(DOWNLOAD_PATH_PREFERENCE);
useTorCheckBox = (CheckBoxPreference) findPreference(USE_TOR_KEY);
prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object o) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
boolean useTor = (Boolean) o; String key) {
if (useTor) { Activity a = getActivity();
if (OrbotHelper.isOrbotInstalled(activity)) { updateSummary();
if (defaultPreferences.getBoolean(USE_TOR_KEY, false)) {
if (OrbotHelper.isOrbotInstalled(a)) {
App.configureTor(true); App.configureTor(true);
OrbotHelper.requestStartTor(a);
} else { } else {
Intent intent = OrbotHelper.getOrbotInstallIntent(activity); Intent intent = OrbotHelper.getOrbotInstallIntent(a);
activity.startActivityForResult(intent, REQUEST_INSTALL_ORBOT); a.startActivityForResult(intent, REQUEST_INSTALL_ORBOT);
} }
} else { } else {
App.configureTor(false); App.configureTor(false);
} }
return true;
} }
}); };
defaultPreferences.registerOnSharedPreferenceChangeListener(prefListener);
updateSummary();
}
// This is used to show the status of some preference in the description
private void updateSummary() {
defaultResolutionPreference.setSummary(
defaultPreferences.getString(DEFAULT_RESOLUTION_PREFERENCE,
getString(R.string.defaultResolutionListItem)));
defaultAudioFormatPreference.setSummary(
defaultPreferences.getString(DEFAULT_AUDIO_FORMAT_PREFERENCE,
getString(R.string.defaultAudioFormat)));
searchLanguagePreference.setSummary(
defaultPreferences.getString(SEARCH_LANGUAGE_PREFERENCE,
getString(R.string.defaultLanguageItem)));
downloadPathPreference.setSummary(
defaultPreferences.getString(DOWNLOAD_PATH_PREFERENCE,
getString(R.string.downloadLocationSummary)));
} }
} }

View File

@ -99,8 +99,9 @@ public class VideoItemListFragment extends ListFragment {
public void run() { public void run() {
try { try {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
String searchLanguageKey = getContext().getString(R.string.searchLanguage); String searchLanguageKey = getContext().getString(R.string.searchLanguagePreference);
String searchLanguage = sp.getString(searchLanguageKey, "en"); String searchLanguage = sp.getString(searchLanguageKey,
getString(R.string.defaultLanguageItem));
SearchEngine.Result result = engine.search(query, page, searchLanguage); SearchEngine.Result result = engine.search(query, page, searchLanguage);
Log.i(TAG, "language code passed:\""+searchLanguage+"\""); Log.i(TAG, "language code passed:\""+searchLanguage+"\"");
if(run) { if(run) {

View File

@ -107,6 +107,7 @@ public abstract class VideoExtractor {
} }
//todo: add licence field
protected abstract int getErrorCode(); protected abstract int getErrorCode();
protected abstract String getErrorMessage(); protected abstract String getErrorMessage();
protected abstract String getVideoUrl(String videoId); protected abstract String getVideoUrl(String videoId);

View File

@ -29,7 +29,8 @@
</string-array> </string-array>
<string name="defaultAudioFormat">m4a</string> <string name="defaultAudioFormat">m4a</string>
<string name="showNextVideo">show_next_video</string> <string name="showNextVideo">show_next_video</string>
<string name="searchLanguage">search_language</string> <string name="searchLanguagePreference">search_language</string>
<string name="useTorKey">use_tor</string>
<!-- TODO: scrape these programmatically, then store in a local cache --> <!-- TODO: scrape these programmatically, then store in a local cache -->
<!-- alternatively, load these from some local android data store --> <!-- alternatively, load these from some local android data store -->
<string-array name='languageCodes'> <string-array name='languageCodes'>
@ -111,6 +112,7 @@
<item>ja</item> <item>ja</item>
<item>ko</item> <item>ko</item>
</string-array> </string-array>
<string name="defaultLanguageItem">en</string>
<string-array name='languageNames'> <string-array name='languageNames'>
<item>Afrikaans</item> <item>Afrikaans</item>
<item>Azərbaycan</item> <item>Azərbaycan</item>

View File

@ -43,11 +43,11 @@
android:defaultValue="false" /> android:defaultValue="false" />
<ListPreference <ListPreference
android:key="@string/searchLanguage" android:key="@string/searchLanguagePreference"
android:title="@string/searchLanguageTitle" android:title="@string/searchLanguageTitle"
android:entries="@array/languageNames" android:entries="@array/languageNames"
android:entryValues="@array/languageCodes" android:entryValues="@array/languageCodes"
android:defaultValue="en" /> android:defaultValue="@string/defaultLanguageItem" />
<CheckBoxPreference <CheckBoxPreference
android:key="@string/showNextVideo" android:key="@string/showNextVideo"
@ -73,9 +73,10 @@
android:defaultValue="false" /> android:defaultValue="false" />
<CheckBoxPreference <CheckBoxPreference
android:key="@string/useTor" android:key="@string/useTorKey"
android:title="@string/useTor" android:title="@string/useTor"
android:summary="@string/useTorSummary" /> android:summary="@string/useTorSummary"
android:defaultValue="false"/>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>