added ability to change item title before download
changing author is possible but a limitation of youtubedl-android prevents doing both at the same time
This commit is contained in:
parent
ecf79fbff4
commit
b60d02adb0
4 changed files with 58 additions and 40 deletions
|
|
@ -25,7 +25,6 @@ import com.yausername.youtubedl_android.YoutubeDLRequest;
|
|||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
|
@ -313,7 +312,8 @@ public class DownloaderService extends Service {
|
|||
|
||||
if (type.equals("audio")) {
|
||||
request.addOption("-x");
|
||||
String format = sharedPreferences.getString("audio_format", "");
|
||||
String format = video.getAudioFormat();
|
||||
if (format == null) format = sharedPreferences.getString("audio_format", "");
|
||||
request.addOption("--audio-format", format);
|
||||
request.addOption("--embed-metadata");
|
||||
if(format.equals("mp3") || format.equals("m4a") || format.equals("flac")){
|
||||
|
|
@ -337,11 +337,12 @@ 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()+"\"");
|
||||
request.addOption("--replace-in-metadata", "title");
|
||||
request.addOption(".*.", video.getTitle());
|
||||
// request.addOption("--replace-in-metadata", "uploader");
|
||||
// request.addOption(".*.", video.getAuthor());
|
||||
|
||||
request.addOption("-o", youtubeDLDir.getAbsolutePath() + "/"+video.getTitle()+"."+format);
|
||||
} else if (type.equals("video")) {
|
||||
boolean addChapters = sharedPreferences.getBoolean("add_chapters", false);
|
||||
if(addChapters){
|
||||
|
|
@ -351,14 +352,15 @@ public class DownloaderService extends Service {
|
|||
if(embedSubs){
|
||||
request.addOption("--embed-subs", "");
|
||||
}
|
||||
String videoQuality = sharedPreferences.getString("video_quality", "");
|
||||
String videoQuality = video.getVideoQuality();
|
||||
if (videoQuality == null) 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", "");
|
||||
String format = video.getVideoFormat();
|
||||
if (format == null) format = sharedPreferences.getString("audio_format", "");
|
||||
request.addOption("--merge-output-format", format);
|
||||
|
||||
if(!format.equals("webm")){
|
||||
|
|
@ -367,20 +369,16 @@ 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() + "/"+video.getTitle()+"."+format);
|
||||
}
|
||||
|
||||
request.addOption("-o", youtubeDLDir.getAbsolutePath() + "/%(title)s.%(ext)s");
|
||||
|
||||
Disposable disposable = Observable.fromCallable(() -> YoutubeDL.getInstance().execute(request, downloadProcessID, callback))
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(youtubeDLResponse -> {
|
||||
downloadInfo.setDownloadPath(youtubeDLDir.getAbsolutePath());
|
||||
downloadInfo.setDownloadType(type);
|
||||
|
||||
try{
|
||||
for (Activity activity: activities.keySet()){
|
||||
activity.runOnUiThread(() -> {
|
||||
|
|
@ -393,6 +391,7 @@ public class DownloaderService extends Service {
|
|||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// SCAN NEXT IN QUEUE
|
||||
videos.remove();
|
||||
downloadInfo.setDownloadQueue(videos);
|
||||
|
|
|
|||
|
|
@ -4,13 +4,11 @@ import android.app.Activity;
|
|||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.os.Handler;
|
||||
|
|
@ -42,14 +40,12 @@ import com.google.android.material.chip.Chip;
|
|||
import com.google.android.material.chip.ChipGroup;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ import android.media.MediaScannerConnection;
|
|||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
|
|
@ -46,14 +48,17 @@ 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;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
@ -626,17 +631,37 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
|
||||
TextInputLayout title = bottomSheet.findViewById(R.id.title_textinput);
|
||||
title.getEditText().setText(vid.getTitle());
|
||||
title.getEditText().addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||
|
||||
TextInputLayout album = bottomSheet.findViewById(R.id.album_textinput);
|
||||
album.getEditText().setText(vid.getPlaylistTitle());
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
vid.setTitle(editable.toString());
|
||||
}
|
||||
});
|
||||
|
||||
TextInputLayout author = bottomSheet.findViewById(R.id.author_textinput);
|
||||
author.getEditText().setText(vid.getAuthor());
|
||||
author.getEditText().addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
vid.setAuthor(editable.toString());
|
||||
}
|
||||
});
|
||||
|
||||
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());
|
||||
|
|
@ -648,12 +673,24 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
|
||||
TextInputLayout title = bottomSheet.findViewById(R.id.title_textinput);
|
||||
title.getEditText().setText(vid.getTitle());
|
||||
title.getEditText().addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
vid.setTitle(editable.toString());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
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());
|
||||
|
|
@ -661,7 +698,6 @@ public class HomeFragment extends Fragment implements HomeRecyclerViewAdapter.On
|
|||
});
|
||||
|
||||
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());
|
||||
|
|
|
|||
|
|
@ -61,22 +61,6 @@
|
|||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/album_textinput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:errorEnabled="true"
|
||||
android:hint="@string/album"
|
||||
style="@style/Widget.Material3.TextInputLayout.FilledBox">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:inputType="text"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
@ -96,6 +80,9 @@
|
|||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:inputType="text"
|
||||
android:background="@color/grey"
|
||||
android:focusableInTouchMode="false"
|
||||
android:longClickable="false"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue