From 4f4a6a46607a4e67cf1ff8e145a0872d0b3d0f9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Denis=20=C3=87erri?=
<64997243+deniscerri@users.noreply.github.com>
Date: Sun, 18 Sep 2022 13:49:22 +0200
Subject: [PATCH] 1.2.0
added some final touches
made the download cancellable
fixed button visibility issues
updated to latest version of youtubedl-android
---
.idea/assetWizardSettings.xml | 4 +-
.idea/misc.xml | 3 +
app/build.gradle | 5 +-
.../deniscerri/ytdl/page/HomeFragment.java | 65 ++++++++++---
.../ytdl/page/settings/SettingsFragment.java | 10 ++
.../main/res/drawable/ic_music_stopped.xml | 5 +
app/src/main/res/drawable/ic_speed.xml | 5 +
.../main/res/drawable/ic_video_stopped.xml | 5 +
app/src/main/res/layout/fragment_home.xml | 94 ++++++++++---------
app/src/main/res/menu/main_menu.xml | 11 +--
app/src/main/res/values/strings.xml | 22 +++++
app/src/main/res/xml/root_preferences.xml | 52 ++++++----
build.gradle | 1 +
13 files changed, 195 insertions(+), 87 deletions(-)
create mode 100644 app/src/main/res/drawable/ic_music_stopped.xml
create mode 100644 app/src/main/res/drawable/ic_speed.xml
create mode 100644 app/src/main/res/drawable/ic_video_stopped.xml
diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml
index 0f95f84e..bab6aec8 100644
--- a/.idea/assetWizardSettings.xml
+++ b/.idea/assetWizardSettings.xml
@@ -23,7 +23,7 @@
@@ -34,7 +34,7 @@
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 6d71d433..917ec63c 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -52,15 +52,18 @@
+
+
+
diff --git a/app/build.gradle b/app/build.gradle
index 9c6a117e..7cea4b05 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -57,8 +57,9 @@ dependencies {
// implementation project(":library")
// implementation project(":ffmpeg")
- implementation 'com.github.yausername.youtubedl-android:library:0.13.3'
- implementation 'com.github.yausername.youtubedl-android:ffmpeg:0.13.3'
+ implementation "com.github.yausername.youtubedl-android:library:$youtubedlAndroidVer"
+ implementation "com.github.yausername.youtubedl-android:ffmpeg:$youtubedlAndroidVer"
+ implementation "com.github.yausername.youtubedl-android:aria2c:$youtubedlAndroidVer"
implementation "androidx.appcompat:appcompat:$appCompatVer"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
diff --git a/app/src/main/java/com/deniscerri/ytdl/page/HomeFragment.java b/app/src/main/java/com/deniscerri/ytdl/page/HomeFragment.java
index e0a64d99..eca1d793 100644
--- a/app/src/main/java/com/deniscerri/ytdl/page/HomeFragment.java
+++ b/app/src/main/java/com/deniscerri/ytdl/page/HomeFragment.java
@@ -43,6 +43,7 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.button.MaterialButton;
+import com.google.android.material.card.MaterialCardView;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.textfield.TextInputLayout;
@@ -78,6 +79,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
private ShimmerFrameLayout shimmerCards;
private CoordinatorLayout downloadFabs;
private CoordinatorLayout downloadAllFab;
+ private CoordinatorLayout homeFabs;
private BottomSheetDialog bottomSheet;
Context context;
@@ -140,8 +142,6 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
shimmerCards = fragmentView.findViewById(R.id.shimmer_results_framelayout);
topAppBar = fragmentView.findViewById(R.id.home_toolbar);
recyclerView = fragmentView.findViewById(R.id.recycler_view_home);
- downloadFabs = fragmentView.findViewById(R.id.download_selected_coordinator);
- downloadAllFab = fragmentView.findViewById(R.id.download_all_coordinator);
homeRecyclerViewAdapter = new HomeRecyclerViewAdapter(resultObjects, this, activity);
recyclerView.setAdapter(homeRecyclerViewAdapter);
@@ -156,6 +156,10 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
initCards();
}
+ homeFabs = fragmentView.findViewById(R.id.home_fabs);
+ downloadFabs = homeFabs.findViewById(R.id.download_selected_coordinator);
+ downloadAllFab = homeFabs.findViewById(R.id.download_all_coordinator);
+
FloatingActionButton music_fab = downloadFabs.findViewById(R.id.audio_fab);
FloatingActionButton video_fab = downloadFabs.findViewById(R.id.video_fab);
music_fab.setTag("SELECT##mp3");
@@ -216,12 +220,14 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
MenuItem.OnActionExpandListener onActionExpandListener = new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
+ homeFabs.setVisibility(View.GONE);
recyclerView.setVisibility(View.GONE);
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
+ homeFabs.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.VISIBLE);
return true;
}
@@ -236,6 +242,9 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
@Override
public boolean onQueryTextSubmit(String query) {
topAppBar.getMenu().findItem(R.id.search).collapseActionView();
+ downloadAllFab.setVisibility(View.GONE);
+ downloadFabs.setVisibility(View.GONE);
+ selectedObjects = new ArrayList<>();
inputQuery = query.trim();
parseQuery();
return true;
@@ -251,17 +260,28 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
int itemId = m.getItemId();
if(itemId == R.id.delete_results){
dbManager.clearResults();
- recyclerView.removeAllViews();
- downloadAllFab.setVisibility(View.GONE);
- initCards();
- }else if(itemId == R.id.refresh_results){
recyclerView.removeAllViews();
selectedObjects = new ArrayList<>();
- downloadFabs.setVisibility(View.GONE);
+ downloadAllFab.setVisibility(View.GONE);
initCards();
- }else if(itemId == R.id.open_settings){
- Intent intent = new Intent(context, SettingsActivity.class);
- startActivity(intent);
+ }else if(itemId == R.id.cancel_download){
+ compositeDisposable.clear();
+ mainActivity.stopDownloadService();
+ topAppBar.getMenu().findItem(itemId).setVisible(false);
+ downloadQueue = new LinkedList<>();
+ downloading = false;
+
+ String id = progressBar.getTag().toString().split("##progress")[0];
+ String type = findVideo(id).getDownloadedType();
+ MaterialButton theClickedButton = recyclerView.findViewWithTag(id + "##"+type);
+
+ if (theClickedButton != null) {
+ if (type.equals("mp3")) {
+ theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music_stopped));
+ } else {
+ theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video_stopped));
+ }
+ }
}
return true;
});
@@ -464,8 +484,17 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
SharedPreferences sharedPreferences = context.getSharedPreferences("root_preferences", Activity.MODE_PRIVATE);
- int concurrentFragments = sharedPreferences.getInt("concurrent_fragments", 1);
- request.addOption("-N", concurrentFragments);
+
+ boolean aria2 = sharedPreferences.getBoolean("aria2", false);
+ if(aria2){
+ request.addOption("--downloader", "libaria2c.so");
+ request.addOption("--external-downloader-args", "aria2c:\"--summary-interval=1\"");
+ }else{
+ int concurrentFragments = sharedPreferences.getInt("concurrent_fragments", 1);
+ request.addOption("-N", concurrentFragments);
+ }
+
+
String limitRate = sharedPreferences.getString("limit_rate", "");
if(!limitRate.equals("")){
@@ -529,9 +558,19 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
recyclerView.scrollToPosition(resultObjects.indexOf(findVideo(id)));
progressBar.setProgress(0);
downloading = true;
+ topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(true);
Video theVideo = video;
MaterialButton theClickedButton = clickedButton;
+
+ if (theClickedButton != null) {
+ if (type.equals("mp3")) {
+ theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_music));
+ } else {
+ theClickedButton.setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_video));
+ }
+ }
+
Disposable disposable = Observable.fromCallable(() -> YoutubeDL.getInstance().execute(request, callback))
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
@@ -551,6 +590,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
addToHistory(theVideo, new Date());
updateDownloadStatusOnResult(theVideo, type);
downloading = false;
+ topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(false);
// MEDIA SCAN
@@ -565,6 +605,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
progressBar.setProgress(0);
progressBar.setVisibility(View.GONE);
downloading = false;
+ topAppBar.getMenu().findItem(R.id.cancel_download).setVisible(false);
// SCAN NEXT IN QUEUE
videos.remove();
diff --git a/app/src/main/java/com/deniscerri/ytdl/page/settings/SettingsFragment.java b/app/src/main/java/com/deniscerri/ytdl/page/settings/SettingsFragment.java
index fcbcab4a..da2c3522 100644
--- a/app/src/main/java/com/deniscerri/ytdl/page/settings/SettingsFragment.java
+++ b/app/src/main/java/com/deniscerri/ytdl/page/settings/SettingsFragment.java
@@ -42,6 +42,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
SeekBarPreference concurrentFragments;
EditTextPreference limitRate;
+ SwitchPreferenceCompat aria2;
SwitchPreferenceCompat removeNonMusic;
SwitchPreferenceCompat embedSubtitles;
@@ -82,6 +83,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
concurrentFragments = findPreference("concurrent_fragments");
limitRate = findPreference("limit_rate");
+ aria2 = findPreference("aria2");
removeNonMusic = findPreference("remove_non_music");
embedSubtitles = findPreference("embed_subtitles");
@@ -107,6 +109,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
editor.putInt("concurrent_fragments", concurrentFragments.getValue());
editor.putString("limit_rate", limitRate.getText());
+ editor.putBoolean("aria2", aria2.isChecked());
editor.putBoolean("remove_non_music", removeNonMusic.isChecked());
editor.putBoolean("embed_subtitles", embedSubtitles.isChecked());
editor.putBoolean("embed_thumbnail", embedThumbnail.isChecked());
@@ -157,6 +160,13 @@ public class SettingsFragment extends PreferenceFragmentCompat {
return true;
});
+ aria2.setOnPreferenceChangeListener((preference, newValue) -> {
+ boolean enable = (Boolean) newValue;
+ editor.putBoolean("aria2", enable);
+ editor.apply();
+ return true;
+ });
+
removeNonMusic.setOnPreferenceChangeListener((preference, newValue) -> {
boolean remove = (Boolean) newValue;
editor.putBoolean("remove_non_music", remove);
diff --git a/app/src/main/res/drawable/ic_music_stopped.xml b/app/src/main/res/drawable/ic_music_stopped.xml
new file mode 100644
index 00000000..8f9f7609
--- /dev/null
+++ b/app/src/main/res/drawable/ic_music_stopped.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_speed.xml b/app/src/main/res/drawable/ic_speed.xml
new file mode 100644
index 00000000..cbb6bafe
--- /dev/null
+++ b/app/src/main/res/drawable/ic_speed.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/drawable/ic_video_stopped.xml b/app/src/main/res/drawable/ic_video_stopped.xml
new file mode 100644
index 00000000..0bc8e8df
--- /dev/null
+++ b/app/src/main/res/drawable/ic_video_stopped.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml
index 03bca40e..28c77845 100644
--- a/app/src/main/res/layout/fragment_home.xml
+++ b/app/src/main/res/layout/fragment_home.xml
@@ -73,64 +73,72 @@
+ android:layout_height="match_parent" >
-
+
-
+
-
+
-
+
-
+ android:layout_gravity="bottom|end"
+ app:cardCornerRadius="20dp"
+ android:layout_margin="16dp"
+ >
-
+ android:background="?attr/colorPrimaryContainer"
+ android:orientation="horizontal">
+
+
+
+
+
+
-
-
+
-
+
diff --git a/app/src/main/res/menu/main_menu.xml b/app/src/main/res/menu/main_menu.xml
index 00455c66..e46a2e7a 100644
--- a/app/src/main/res/menu/main_menu.xml
+++ b/app/src/main/res/menu/main_menu.xml
@@ -10,20 +10,15 @@
app:showAsAction="always|collapseActionView"
app:actionViewClass="androidx.appcompat.widget.SearchView"/>
-
-
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7b9844f4..43d596d3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -67,4 +67,26 @@
/storage/emulated/0/Download
/storage/emulated/0/Download
/storage/emulated/0/Download
+ Number of fragments of a dash/hlsnative video that should be downloaded concurrently
+ Concurrent Fragments
+ Downloading
+ Limit Rate
+ Maximum download rate in bytes per second, e.g. 50K or 4.2M
+ Use Aria2c as a downloader instead of the default one
+ Remove non music parts
+ Remove SponsorBlock segments that contain non music parts for audio files
+ Processing
+ Embed Subtitles on Videos
+ Embed subtitles in the video (only for mp4,webm and mkv videos)
+ Embed Thumbnail
+ Embed thumbnail as cover art
+ Add Chapters on Videos
+ Mark Youtube / Sponsorblock segments as chapters for the video
+ Save Thumbnail
+ Write Video Thumbnail as a file on the Download Directory
+ Audio Format
+ Video Format
+ Audio Quality
+ 0 (Best) 10 (Worst)
+ Cancel Download
diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml
index 790d44ff..3dcff4f3 100644
--- a/app/src/main/res/xml/root_preferences.xml
+++ b/app/src/main/res/xml/root_preferences.xml
@@ -22,59 +22,71 @@
-
+
+ android:dependency="aria2"
+ app:summary="@string/concurrent_fragments_summary"
+ app:title="@string/concurrent_fragments" />
+ app:summary="@string/limit_rate_summary"
+ app:title="@string/limit_rate" />
+
+
-
+
+ app:summary="@string/remove_non_music_summary"
+ app:title="@string/remove_non_music" />
+ app:summary="@string/embed_subs_summary"
+ app:title="@string/embed_subs" />
+ app:summary="@string/embed_thumb_summary"
+ app:title="@string/embed_thumb" />
+ app:summary="@string/add_chapters_summary"
+ app:title="@string/add_chapters" />
+ app:summary="@string/save_thumb_summary"
+ app:title="@string/save_thumb" />
+ app:title="@string/audio_format" />
+ app:summary="mkv"
+ app:title="@string/video_format" />
+ app:summary="@string/audio_quality_summary"
+ app:title="@string/audio_quality" />
diff --git a/build.gradle b/build.gradle
index fe735f89..8e06590f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -33,6 +33,7 @@ ext {
commonsIoVer = '2.5'
// supports java 1.6
commonsCompressVer = '1.12'
+ youtubedlAndroidVer = "0.14.+"
}