From b0479d0bd96e894b52176c37428761779075aae4 Mon Sep 17 00:00:00 2001 From: Coffeemakr Date: Wed, 19 Jul 2017 16:27:40 +0200 Subject: [PATCH 1/8] Add renaming filename patterns --- .../newpipe/download/DownloadDialog.java | 23 ++--------- .../schabi/newpipe/util/FilenameUtils.java | 39 +++++++++++++++++++ app/src/main/res/values/settings_keys.xml | 18 +++++++++ app/src/main/res/values/strings.xml | 12 ++++++ app/src/main/res/xml/settings.xml | 26 +++++++++++-- 5 files changed, 95 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/util/FilenameUtils.java diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 08a3528d6..8de10a25d 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -27,6 +27,7 @@ import org.schabi.newpipe.extractor.stream_info.StreamInfo; import org.schabi.newpipe.extractor.stream_info.VideoStream; import org.schabi.newpipe.fragments.detail.SpinnerToolbarAdapter; import org.schabi.newpipe.settings.NewPipeSettings; +import org.schabi.newpipe.util.FilenameUtils; import org.schabi.newpipe.util.PermissionHelper; import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.Utils; @@ -107,7 +108,7 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); nameEditText = ((EditText) view.findViewById(R.id.file_name)); - nameEditText.setText(createFileName(currentInfo.title)); + nameEditText.setText(FilenameUtils.createFilename(getContext(), currentInfo.title)); selectedAudioIndex = Utils.getPreferredAudioFormat(getContext(), currentInfo.audio_streams); streamsSpinner = (Spinner) view.findViewById(R.id.quality_spinner); @@ -252,30 +253,12 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck } } - /** - * #143 #44 #42 #22: make sure that the filename does not contain illegal chars. - * This should fix some of the "cannot download" problems. - */ - private String createFileName(String fileName) { - // from http://eng-przemelek.blogspot.de/2009/07/how-to-create-valid-file-name.html - - List forbiddenCharsPatterns = new ArrayList<>(); - forbiddenCharsPatterns.add("[:]+"); // Mac OS, but it looks that also Windows XP - forbiddenCharsPatterns.add("[\\*\"/\\\\\\[\\]\\:\\;\\|\\=\\,]+"); // Windows - forbiddenCharsPatterns.add("[^\\w\\d\\.]+"); // last chance... only latin letters and digits - String nameToTest = fileName; - for (String pattern : forbiddenCharsPatterns) { - nameToTest = nameToTest.replaceAll(pattern, "_"); - } - return nameToTest; - } - private void downloadSelected() { String url, location; String fileName = nameEditText.getText().toString().trim(); - if (fileName.isEmpty()) fileName = createFileName(currentInfo.title); + if (fileName.isEmpty()) fileName = FilenameUtils.createFilename(getContext(), currentInfo.title); boolean isAudio = radioVideoAudioGroup.getCheckedRadioButtonId() == R.id.audio_button; url = isAudio ? currentInfo.audio_streams.get(selectedAudioIndex).url : sortedStreamVideosList.get(selectedVideoIndex).url; diff --git a/app/src/main/java/org/schabi/newpipe/util/FilenameUtils.java b/app/src/main/java/org/schabi/newpipe/util/FilenameUtils.java new file mode 100644 index 000000000..b874a9eca --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/util/FilenameUtils.java @@ -0,0 +1,39 @@ +package org.schabi.newpipe.util; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import org.schabi.newpipe.R; + +import java.util.regex.Pattern; + +public class FilenameUtils { + + /** + * #143 #44 #42 #22: make sure that the filename does not contain illegal chars. + * @param context the context to retrieve strings and preferences from + * @param title the title to create a filename from + * @return the filename + */ + public static String createFilename(Context context, String title) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + final String key = context.getString(R.string.settings_file_charset_key); + final String value = sharedPreferences.getString(key, context.getString(R.string.default_file_charset_value)); + Pattern pattern = Pattern.compile(value); + + final String replacementChar = sharedPreferences.getString(context.getString(R.string.settings_file_replacement_character_key), "_"); + return createFilename(title, pattern, replacementChar); + } + + /** + * Create a valid filename + * @param title the title to create a filename from + * @param invalidCharacters patter matching invalid characters + * @param replacementChar the replacement + * @return the filename + */ + private static String createFilename(String title, Pattern invalidCharacters, String replacementChar) { + return title.replaceAll(invalidCharacters.pattern(), replacementChar); + } +} \ No newline at end of file diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index fc3bb77bc..0de19c568 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -232,4 +232,22 @@ show_age_restricted_content use_tor + + file_rename + file_replacement_character + _ + + + @string/charset_letters_and_digits_value + @string/charset_most_special_characters_value + + + + @string/charset_letters_and_digits + @string/charset_most_special_characters + + + @string/charset_most_special_characters \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c2ad28f02..9634d221c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -190,6 +190,18 @@ + + settings_category_downloads + Download + Allowed characters in filenames + Invalid characters are replaced with this value + Replacement character + + [^\w\d]+ + [\n\r|\\?*<":>/']+ + Letters and digits + Most special characters + About NewPipe Settings diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index cf7e49163..282aba918 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -133,10 +133,10 @@ + + android:key="@string/settings_category_downloads" + android:title="@string/settings_category_downloads_title"> + + + + + + + Date: Tue, 1 Aug 2017 14:54:32 -0700 Subject: [PATCH 2/8] - Updated target, build tools and support libraries version to 26. - Added dependency repositories jcenter and maven.google.com. - Changed deprecated ActionBarActivity to AppCompatActivity. --- app/build.gradle | 21 ++++++++++++------- .../giga/ui/common/ToolbarActivity.java | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c09addebf..166fcc455 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,20 @@ apply plugin: 'com.android.application' +allprojects { + repositories { + jcenter() + maven { url 'https://maven.google.com' } + } +} + android { - compileSdkVersion 25 - buildToolsVersion '25.0.2' + compileSdkVersion 26 + buildToolsVersion '26.0.1' defaultConfig { applicationId "org.schabi.newpipe" minSdkVersion 15 - targetSdkVersion 25 + targetSdkVersion 26 versionCode 37 versionName "0.9.10" @@ -42,10 +49,10 @@ dependencies { testCompile 'org.mockito:mockito-core:1.10.19' testCompile 'org.json:json:20160810' - compile 'com.android.support:appcompat-v7:25.3.1' - compile 'com.android.support:support-v4:25.3.1' - compile 'com.android.support:design:25.3.1' - compile 'com.android.support:recyclerview-v7:25.3.1' + compile 'com.android.support:appcompat-v7:26.0.0' + compile 'com.android.support:support-v4:26.0.0' + compile 'com.android.support:design:26.0.0' + compile 'com.android.support:recyclerview-v7:26.0.0' compile 'com.google.code.gson:gson:2.7' compile 'org.jsoup:jsoup:1.8.3' diff --git a/app/src/main/java/us/shandian/giga/ui/common/ToolbarActivity.java b/app/src/main/java/us/shandian/giga/ui/common/ToolbarActivity.java index 7e732f6f9..1d2bf2e26 100644 --- a/app/src/main/java/us/shandian/giga/ui/common/ToolbarActivity.java +++ b/app/src/main/java/us/shandian/giga/ui/common/ToolbarActivity.java @@ -1,12 +1,12 @@ package us.shandian.giga.ui.common; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import org.schabi.newpipe.R; -public abstract class ToolbarActivity extends ActionBarActivity { +public abstract class ToolbarActivity extends AppCompatActivity { protected Toolbar mToolbar; @Override From 96d3841dbacc628cc4c024ef27acf9159fafe5a0 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Tue, 1 Aug 2017 21:56:51 -0300 Subject: [PATCH 3/8] Fix issues #636 --- app/src/main/res/values/settings_keys.xml | 2 +- app/src/main/res/values/strings.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 0de19c568..071592b73 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -249,5 +249,5 @@ @string/charset_most_special_characters - @string/charset_most_special_characters + @string/charset_most_special_characters_value \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9634d221c..f253167e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -197,8 +197,8 @@ Invalid characters are replaced with this value Replacement character - [^\w\d]+ - [\n\r|\\?*<":>/']+ + [^\\w\\d]+ + [\\n\\r|\\?*<":>/']+ Letters and digits Most special characters From f020b88db3185534cdcb88750e5db66c474ea243 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Tue, 1 Aug 2017 22:56:04 -0300 Subject: [PATCH 4/8] Move maven repository declaration - Remove redundant jcenter (already included in the "global application" build.gradle) --- app/build.gradle | 7 ------- build.gradle | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 166fcc455..7d0ce971c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,5 @@ apply plugin: 'com.android.application' -allprojects { - repositories { - jcenter() - maven { url 'https://maven.google.com' } - } -} - android { compileSdkVersion 26 buildToolsVersion '26.0.1' diff --git a/build.gradle b/build.gradle index 596601301..a0725be17 100644 --- a/build.gradle +++ b/build.gradle @@ -15,5 +15,6 @@ buildscript { allprojects { repositories { jcenter() + maven { url 'https://maven.google.com' } } } From 16ad13c96217385c97858f66d061d82673ef17be Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Tue, 1 Aug 2017 23:18:47 -0300 Subject: [PATCH 5/8] Update travis' android and build-tools version --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 57388d529..fad605996 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,10 @@ android: components: # The BuildTools version used by NewPipe - tools - - build-tools-25.0.2 + - build-tools-26.0.1 # The SDK version used to compile NewPipe - - android-25 + - android-26 # Additional components - extra-android-m2repository @@ -17,4 +17,3 @@ script: ./gradlew -Dorg.gradle.jvmargs=-Xmx1536m assembleDebug lintDebug testDeb licenses: - '.+' - From f7b322da49759d96d54ebfd38bd1b7a1672c6f78 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Wed, 2 Aug 2017 14:14:45 -0300 Subject: [PATCH 6/8] Fix audio focus bug --- app/src/main/java/org/schabi/newpipe/player/BasePlayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 31caddca5..10f4feb48 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -519,7 +519,7 @@ public abstract class BasePlayer implements ExoPlayer.EventListener, AudioManage } if (!isPlaying()) audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); - else audioManager.abandonAudioFocus(null); + else audioManager.abandonAudioFocus(this); simpleExoPlayer.setPlayWhenReady(!isPlaying()); } From 27e5ce7f9b40533081cb7a936b3a148c4de226c2 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Wed, 2 Aug 2017 23:19:34 +0200 Subject: [PATCH 7/8] update sentry linkg --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 6126197a0..511a89ead 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -15,7 +15,7 @@ Do not report crashes in the GitHub issue tracker. NewPipe has an automated cras * Use english ## Bugfixing -* If you want to help NewPipe getting bug free, you can send me a mail to tnp@newpipe.schabi.org to let me know that you intent to help, and than register at our [sentry](https://support.schabi.org) setup. +* If you want to help NewPipe getting bug free, you can send me a mail to tnp@newpipe.schabi.org to let me know that you intent to help, and than register at our [sentry](https://sentry.schabi.org) setup. ## Translation From 9e2ed101445d3fc754082ea24b650b094900d950 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Wed, 2 Aug 2017 23:34:46 +0200 Subject: [PATCH 8/8] Fix bugs in CONTRIBUTING.md Spelling and grammar bugs, a few additions here and there, make it sound like a team project instead of a one-man show. --- .github/CONTRIBUTING.md | 44 +++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 511a89ead..be8a0ca80 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,40 +1,42 @@ NewPipe contribution guidelines =============================== -READ THIS GUIDELINES CAREFULLY BEFORE CONTRIBUTING. +PLEASE READ THESE GUIDELINES CAREFULLY BEFORE ANY CONTRIBUTION! ## Crash reporting -Do not report crashes in the GitHub issue tracker. NewPipe has an automated crash report system that will ask you to send a report if a crash occurs. +Do not report crashes in the GitHub issue tracker. NewPipe has an automated crash report system that will ask you to send a report via e-mail when a crash occurs. This contains all the data we need for debugging, and allows you to even add a comment to it. You'll see exactly what is sent, the system is 100% transparent. -## Issue reporting/feature request +## Issue reporting/feature requests -* Search the [existing issues](https://github.com/theScrabi/NewPipe/issues) first to make sure your issue/feature hasn't been reported/requested before -* Check if this issue/feature is already fixed/implemented in the repository -* If you are an android/java developer you are always welcome to fix/implement an issue/a feature yourself -* Use english +* Search the [existing issues](https://github.com/TeamNewPipe/NewPipe/issues) first to make sure your issue/feature hasn't been reported/requested before +* Check whether your issue/feature is already fixed/implemented +* If you are an Android/Java developer, you are always welcome to fix/implement an issue/a feature yourself. PRs welcome! +* We use English for development. Issues in other languages will be closed and ignored. -## Bugfixing -* If you want to help NewPipe getting bug free, you can send me a mail to tnp@newpipe.schabi.org to let me know that you intent to help, and than register at our [sentry](https://sentry.schabi.org) setup. +## Bug Fixing +* If you want to help NewPipe to become free of bugs (this is our utopic goal for NewPipe), you can send us an email to tnp@newpipe.schabi.org to let me know that you intend to help. We'll send you further instructions. You may, on request, register at our [Sentry](https://sentry.schabi.org) instance (see section "Crash reporting" for more information. ## Translation -* NewPipe can be translated on [weblate](https://hosted.weblate.org/projects/newpipe/strings/) +* NewPipe can be translated via [Weblate](https://hosted.weblate.org/projects/newpipe/strings/). You can log in there with your GitHub account. ## Code contribution -* Stick to NewPipe style guidelines (just look the other code and than do it the same way :) ) -* Do not bring nonfree software/binary blobs into the project (keep it google free) -* Stick to [f-droid contribution guidelines](https://f-droid.org/wiki/page/Inclusion_Policy) -* Make changes on a separate branch, not on the master branch (Feature-branching) -* When submitting changes, you agree that your code will be licensed under GPLv3 -* Please test (compile and run) your code before you submit changes!!! -* Try to figure out you selves why CI fails, or why a merge request collides -* Please maintain your code after you contributed it. -* Respond yourselves if someone request changes or notifies issues +* Stick to NewPipe's style conventions (well, just look the other code and then do it the same way :)) +* Do not bring non-free software (e.g., binary blobs) into the project. Also, make sure you do not introduce Google libraries. +* Stick to [F-Droid contribution guidelines](https://f-droid.org/wiki/page/Inclusion_Policy) +* Make changes on a separate branch, not on the master branch. This is commonly known as *feature branch workflow*. You may then send your +* When submitting changes, you confirm that your code is licensed under the terms of the [GNU General Public License v3](https://www.gnu.org/licenses/gpl-3.0.html). +* Please test (compile and run) your code before you submit changes! Ideally, provide test feedback in the PR description. Untested code will **not** be merged! +* Try to figure out yourself why builds on our CI fail. +* Make sure your PR is up-to-date with the rest of the code. Often, a simple click on "Update branch" will do the job, but if not, you are asked to merge the master branch manually and resolve the problems on your own. That will make the maintainers' jobs way easier. +* Please show intention to maintain your features and code after you contributed it. Unmaintained code is a hassle for the core developers, and just adds work. If you do not intend to maintain features you contributed, please think again about sumission, or clearly state that in the description of your PR. +* Respond yourselves if someone requests changes or otherwise raises issues about your PRs. ## Communication * WE DO NOW HAVE A MAILING LIST: [newpipe@list.schabi.org](https://list.schabi.org/cgi-bin/mailman/listinfo/newpipe). -* If you want to get in contact with me or one of our other contributors you can send me an email at tnp(at)schabi.org -* Feel free to post suggestions, changes, ideas etc! +* There is an IRC channel on Freenode which is regularly visited by the core team and other developers: [#newpipe](irc:irc.freenode.net/newpipe). [Click here for Webchat](https://webchat.freenode.net/?channels=newpipe)! +* If you want to get in touch with the core team or one of our other contributors you can send an email to tnp(at)schabi.org. Please do not send issue reports, they will be ignored and remain unanswered! Use the GitHub issue tracker described above! +* Feel free to post suggestions, changes, ideas etc. on GitHub, IRC or the mailing list!