[beta] added functional download config cards

pull/1/head
Denis Çerri 4 years ago
parent c763d00f08
commit ecf79fbff4
No known key found for this signature in database
GPG Key ID: 3F50F14A8E7F7A13

@ -320,7 +320,7 @@
<PersistentState>
<option name="values">
<map>
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/bedtime/baseline_bedtime_24.xml" />
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/credit_card/baseline_credit_card_24.xml" />
</map>
</option>
</PersistentState>
@ -331,7 +331,7 @@
<option name="values">
<map>
<entry key="color" value="00a6ff" />
<entry key="outputName" value="ic_incognito" />
<entry key="outputName" value="ic_card" />
<entry key="sourceFile" value="C:\Users\denis\Desktop\adaptiveproduct_youtube_foreground_color_108 (1).svg" />
</map>
</option>

@ -41,6 +41,7 @@
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_back.xml" value="0.109" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_baseline_keyboard_arrow_right_24.xml" value="0.109" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_cancel.xml" value="0.2395" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_card.xml" value="0.2395" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_chapters.xml" value="0.109" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_check.xml" value="0.2395" />
<entry key="..\:/Users/denis/Documents/GitHub/ytdlnis/app/src/main/res/drawable/ic_cloud_download.xml" value="0.1275" />

@ -337,6 +337,11 @@ public class DownloaderService extends Service {
request.addOption("--sponsorblock-remove", "all");
}
request.addOption("--replace-in-metadata", "title \"[ ]\" \""+video.getTitle()+"\"");
request.addOption("--parse-metadata", "meta_title:%(title)s");
request.addOption("--parse-metadata", "title:%(title)s");
request.addOption("--parse-metadata", "meta_artist:\""+video.getAuthor()+"\"");
} else if (type.equals("video")) {
boolean addChapters = sharedPreferences.getBoolean("add_chapters", false);
if(addChapters){
@ -346,7 +351,13 @@ public class DownloaderService extends Service {
if(embedSubs){
request.addOption("--embed-subs", "");
}
request.addOption("-f", "bestvideo+bestaudio/best");
String videoQuality = sharedPreferences.getString("video_quality", "");
String formatArgument = "bestvideo+bestaudio/best";
if (!videoQuality.isEmpty() && !videoQuality.equals("Best Quality")) {
formatArgument = "bestvideo[height<="+videoQuality.substring(0, videoQuality.length()-1)+"]+bestaudio/best";
}
Toast.makeText(context, formatArgument, Toast.LENGTH_LONG).show();
request.addOption("-f", formatArgument);
String format = sharedPreferences.getString("video_format", "");
request.addOption("--merge-output-format", format);
@ -356,6 +367,10 @@ public class DownloaderService extends Service {
request.addOption("--embed-thumbnail");
}
}
request.addOption("--add-metadata");
request.addOption("--postprocessor-args", "-metadata title=\""+video.getTitle()+"\"");
}
request.addOption("-o", youtubeDLDir.getAbsolutePath() + "/%(title)s.%(ext)s");
@ -386,7 +401,7 @@ public class DownloaderService extends Service {
if (BuildConfig.DEBUG) Log.e(TAG, getString(R.string.failed_download), e);
notificationUtil.updateDownloadNotification(NotificationUtil.DOWNLOAD_NOTIFICATION_ID,
getString(R.string.failed_download), 0, 0, downloadQueue.peek().getTitle());
downloadInfo.setDownloadType(type);
try{
for (Activity activity: activities.keySet()){
activity.runOnUiThread(() -> {

@ -22,6 +22,9 @@ public class Video implements Parcelable, Cloneable {
private boolean downloadingVideo;
private boolean queuedDownload;
private String playlistTitle;
private String audioFormat;
private String videoFormat;
private String videoQuality;
// RESULTS OBJECT
public Video(String videoId, String url, String title, String author, String duration, String thumb,
@ -77,6 +80,9 @@ public class Video implements Parcelable, Cloneable {
downloadPath = in.readString();
website = in.readString();
playlistTitle = in.readString();
audioFormat = in.readString();
videoFormat = in.readString();
videoQuality = in.readString();
}
public static final Creator<Video> CREATOR = new Creator<Video>() {
@ -247,6 +253,30 @@ public class Video implements Parcelable, Cloneable {
this.queuedDownload = queuedDownload;
}
public String getAudioFormat() {
return audioFormat;
}
public void setAudioFormat(String audioFormat) {
this.audioFormat = audioFormat;
}
public String getVideoFormat() {
return videoFormat;
}
public void setVideoFormat(String videoFormat) {
this.videoFormat = videoFormat;
}
public String getVideoQuality() {
return videoQuality;
}
public void setVideoQuality(String videoQuality) {
this.videoQuality = videoQuality;
}
public Object clone() throws CloneNotSupportedException
{
return super.clone();
@ -273,6 +303,10 @@ public class Video implements Parcelable, Cloneable {
parcel.writeInt(isPlaylistItem);
parcel.writeString(downloadPath);
parcel.writeString(website);
parcel.writeString(playlistTitle);
parcel.writeString(audioFormat);
parcel.writeString(videoFormat);
parcel.writeString(videoQuality);
}
@Override
@ -294,6 +328,11 @@ public class Video implements Parcelable, Cloneable {
", website='" + website + '\'' +
", downloadingAudio=" + downloadingAudio +
", downloadingVideo=" + downloadingVideo +
", queuedDownload=" + queuedDownload +
", playlistTitle='" + playlistTitle + '\'' +
", audioFormat='" + audioFormat + '\'' +
", videoFormat='" + videoFormat + '\'' +
", videoQuality='" + videoQuality + '\'' +
'}';
}
}

@ -112,13 +112,23 @@ public class DownloadsFragment extends Fragment implements DownloadsRecyclerView
public void onDownloadError(DownloadInfo info){
try{
int position = downloadsObjects.indexOf(info.getVideo());
Video v = downloadsObjects.get(position);
Video item = info.getVideo();
Log.e(TAG, item.toString());
String url = item.getURL();
String type = info.getDownloadType();
Video v = findVideo(url, type);
Log.e(TAG, v.toString());
dbManager = new DBManager(context);
dbManager.clearHistoryItem(v, false);
int position = downloadsObjects.indexOf(v);
downloadsObjects.remove(v);
downloadsRecyclerViewAdapter.notifyItemRemoved(position);
if (downloadsObjects.isEmpty()) initCards();
downloading = false;
}catch(Exception ignored){}
}catch(Exception e){
e.printStackTrace();
}
}
public void onDownloadEnd(DownloadInfo downloadInfo) {

@ -1,9 +1,11 @@
package com.deniscerri.ytdlnis.page;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.media.MediaScannerConnection;
import android.os.Bundle;
@ -16,6 +18,9 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.widget.SearchView;
@ -37,6 +42,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.chip.Chip;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.progressindicator.LinearProgressIndicator;
@ -592,7 +598,7 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
return null;
}
@SuppressLint("ResourceType")
@Override
public void onButtonClick(int position, String type) {
Log.e(TAG, type);
@ -607,11 +613,120 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
}
}catch (Exception ignored){}
}
downloadQueue.add(vid);
updateDownloadingStatusOnResult(vid, type, true);
if (isStoragePermissionGranted()){
mainActivity.startDownloadService(downloadQueue, listener);
downloadQueue.clear();
SharedPreferences sharedPreferences = context.getSharedPreferences("root_preferences", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
if (sharedPreferences.getBoolean("download_card", true)){
bottomSheet = new BottomSheetDialog(fragmentContext);
bottomSheet.requestWindowFeature(Window.FEATURE_NO_TITLE);
if (type.equals("audio")){
bottomSheet.setContentView(R.layout.home_download_audio_bottom_sheet);
TextInputLayout title = bottomSheet.findViewById(R.id.title_textinput);
title.getEditText().setText(vid.getTitle());
TextInputLayout album = bottomSheet.findViewById(R.id.album_textinput);
album.getEditText().setText(vid.getPlaylistTitle());
TextInputLayout author = bottomSheet.findViewById(R.id.author_textinput);
author.getEditText().setText(vid.getAuthor());
String[] audioFormats = context.getResources().getStringArray(R.array.music_formats);
TextInputLayout audioFormat = bottomSheet.findViewById(R.id.audio_format);
audioFormat.getEditText().setText(sharedPreferences.getString("audio_format", ""));
((AutoCompleteTextView)audioFormat.getEditText()).setOnItemClickListener((adapterView, view, i, l) -> {
vid.setAudioFormat(audioFormats[i]);
editor.putString("audio_format", vid.getAudioFormat());
editor.apply();
});
}else {
bottomSheet.setContentView(R.layout.home_download_video_bottom_sheet);
TextInputLayout title = bottomSheet.findViewById(R.id.title_textinput);
title.getEditText().setText(vid.getTitle());
String[] videoFormats = context.getResources().getStringArray(R.array.video_formats);
String[] videoQualities = context.getResources().getStringArray(R.array.video_quality);
TextInputLayout videoFormat = bottomSheet.findViewById(R.id.video_format);
videoFormat.getEditText().setText(sharedPreferences.getString("video_format", ""));
((AutoCompleteTextView)videoFormat.getEditText()).setOnItemClickListener((adapterView, view, i, l) -> {
vid.setVideoFormat(videoFormats[i]);
editor.putString("video_format", vid.getVideoFormat());
editor.apply();
});
TextInputLayout videoQuality = bottomSheet.findViewById(R.id.video_quality);
videoQuality.getEditText().setText(sharedPreferences.getString("video_quality", ""));
((AutoCompleteTextView)videoQuality.getEditText()).setOnItemClickListener((adapterView, view, i, l) -> {
vid.setVideoQuality(videoQualities[i]);
editor.putString("video_quality", vid.getVideoQuality());
editor.apply();
});
Chip embedSubs = bottomSheet.findViewById(R.id.embed_subtitles);
embedSubs.setChecked(sharedPreferences.getBoolean("embed_subtitles", false));
embedSubs.setOnClickListener(view -> {
if (embedSubs.isChecked()){
editor.putBoolean("embed_subtitles", true);
}else{
editor.putBoolean("embed_subtitles", false);
}
editor.apply();
});
Chip addChapters = bottomSheet.findViewById(R.id.add_chapters);
addChapters.setChecked(sharedPreferences.getBoolean("add_chapters", false));
addChapters.setOnClickListener(view -> {
if (addChapters.isChecked()){
editor.putBoolean("add_chapters", true);
}else{
editor.putBoolean("add_chapters", false);
}
editor.apply();
});
Chip saveThumbnail = bottomSheet.findViewById(R.id.save_thumbnail);
saveThumbnail.setChecked(sharedPreferences.getBoolean("write_thumbnail", false));
saveThumbnail.setOnClickListener(view -> {
if (saveThumbnail.isChecked()){
editor.putBoolean("write_thumbnail", true);
}else{
editor.putBoolean("write_thumbnail", false);
}
editor.apply();
});
}
Button cancel = bottomSheet.findViewById(R.id.bottomsheet_cancel_button);
cancel.setOnClickListener(view -> {
bottomSheet.cancel();
});
Button download = bottomSheet.findViewById(R.id.bottomsheet_download_button);
download.setOnClickListener(view -> {
downloadQueue.add(vid);
updateDownloadingStatusOnResult(vid, type, true);
if (isStoragePermissionGranted()){
mainActivity.startDownloadService(downloadQueue, listener);
downloadQueue.clear();
}
bottomSheet.cancel();
});
bottomSheet.show();
bottomSheet.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
}else{
downloadQueue.add(vid);
updateDownloadingStatusOnResult(vid, type, true);
if (isStoragePermissionGranted()){
mainActivity.startDownloadService(downloadQueue, listener);
downloadQueue.clear();
}
}
}

@ -30,6 +30,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
Preference commandPath;
SwitchPreferenceCompat incognito;
SwitchPreferenceCompat downloadCard;
EditTextPreference apiKey;
SeekBarPreference concurrentFragments;
EditTextPreference limitRate;
@ -43,6 +44,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
ListPreference audioFormat;
ListPreference videoFormat;
SeekBarPreference audioQuality;
ListPreference videoQuality;
Preference updateYTDL;
SwitchPreferenceCompat updateApp;
@ -74,6 +76,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
commandPath = findPreference("command_path");
incognito = findPreference("incognito");
downloadCard = findPreference("download_card");
apiKey = findPreference("api_key");
concurrentFragments = findPreference("concurrent_fragments");
limitRate = findPreference("limit_rate");
@ -87,6 +90,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
audioFormat = findPreference("audio_format");
videoFormat = findPreference("video_format");
audioQuality = findPreference("audio_quality");
videoQuality = findPreference("video_quality");
updateYTDL = findPreference("update_ytdl");
updateApp = findPreference("update_app");
@ -104,6 +108,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
}
editor.putBoolean("incognito", incognito.isChecked());
editor.putBoolean("download_card", downloadCard.isChecked());
editor.putString("api_key", apiKey.getText());
editor.putInt("concurrent_fragments", concurrentFragments.getValue());
editor.putString("limit_rate", limitRate.getText());
@ -116,6 +121,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
editor.putString("audio_format", audioFormat.getValue());
editor.putString("video_format", videoFormat.getValue());
editor.putInt("audio_quality", audioQuality.getValue());
editor.putString("video_quality", videoQuality.getValue());
editor.putBoolean("update_app", updateApp.isChecked());
editor.apply();
@ -153,6 +159,13 @@ public class SettingsFragment extends PreferenceFragmentCompat {
return true;
});
downloadCard.setOnPreferenceChangeListener((preference, newValue) -> {
boolean enable = (Boolean) newValue;
editor.putBoolean("download_card", enable);
editor.apply();
return true;
});
apiKey.setOnPreferenceChangeListener((preference, newValue) -> {
editor.putString("api_key", String.valueOf(newValue));
editor.apply();
@ -236,6 +249,14 @@ public class SettingsFragment extends PreferenceFragmentCompat {
return true;
});
videoQuality.setSummary(preferences.getString("video_quality", ""));
videoQuality.setOnPreferenceChangeListener((preference, newValue) -> {
editor.putString("video_quality", String.valueOf(newValue));
videoQuality.setSummary(String.valueOf(newValue));
editor.apply();
return true;
});
updateYTDL.setOnPreferenceClickListener(preference -> {
updateUtil.updateYoutubeDL();
return true;

@ -0,0 +1,5 @@
<vector android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="?android:colorAccent" android:pathData="M20,4L4,4c-1.11,0 -1.99,0.89 -1.99,2L2,18c0,1.11 0.89,2 2,2h16c1.11,0 2,-0.89 2,-2L22,6c0,-1.11 -0.89,-2 -2,-2zM20,18L4,18v-6h16v6zM20,8L4,8L4,6h16v2z"/>
</vector>

@ -133,7 +133,7 @@
<Button
style="@style/Widget.Material3.Button.OutlinedButton.Icon"
android:id="@+id/bottomsheet_audio_button"
android:id="@+id/bottomsheet_cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
@ -142,7 +142,7 @@
<Button
style="@style/Widget.Material3.Button.ElevatedButton.Icon"
android:id="@+id/bottomsheet_video_button"
android:id="@+id/bottomsheet_download_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/download"

@ -86,7 +86,7 @@
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/menu"
android:id="@+id/video_quality"
style="@style/Widget.Material3.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="0dp"
android:paddingStart="10dp"
@ -131,7 +131,7 @@
<com.google.android.material.chip.Chip
android:id="@+id/add_chapters"
style="@style/Widget.Material3.Chip.Filter"
style="@style/Widget.Material3.Chip.Filter.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
@ -139,7 +139,7 @@
<com.google.android.material.chip.Chip
android:id="@+id/save_thumbnail"
style="@style/Widget.Material3.Chip.Filter"
style="@style/Widget.Material3.Chip.Filter.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
@ -162,7 +162,7 @@
<Button
style="@style/Widget.Material3.Button.OutlinedButton.Icon"
android:id="@+id/bottomsheet_audio_button"
android:id="@+id/bottomsheet_cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
@ -171,7 +171,7 @@
<Button
style="@style/Widget.Material3.Button.ElevatedButton.Icon"
android:id="@+id/bottomsheet_video_button"
android:id="@+id/bottomsheet_download_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/download"

@ -126,4 +126,6 @@
<string name="video_quality">Video Quality</string>
<string name="embed_subtitles">Embed Subtitles</string>
<string name="add_chapter">Add Chapters</string>
<string name="show_download_card">Show Download Card</string>
<string name="download_card_summary">Configure the item before downloading it</string>
</resources>

@ -30,6 +30,13 @@
app:summary="@string/incognito_summary"
app:title="Incognito" />
<SwitchPreferenceCompat
app:defaultValue="true"
android:icon="@drawable/ic_card"
android:key="download_card"
app:summary="@string/download_card_summary"
app:title="@string/show_download_card" />
<EditTextPreference
android:icon="@drawable/ic_key"
app:key="api_key"
@ -131,6 +138,15 @@
app:summary="@string/audio_quality_summary"
app:title="@string/audio_quality" />
<ListPreference
android:defaultValue="Best Quality"
android:entries="@array/video_quality"
android:entryValues="@array/video_quality"
android:icon="@drawable/ic_video"
app:key="video_quality"
app:summary="Best Quality"
app:title="@string/video_quality" />
</PreferenceCategory>

Loading…
Cancel
Save