fixed opus not saving with thumbnail & added share intent for custom command
This commit is contained in:
parent
f4d3ff5c25
commit
427b96957c
7 changed files with 60 additions and 34 deletions
|
|
@ -91,9 +91,9 @@ dependencies {
|
||||||
// implementation project(":library")
|
// implementation project(":library")
|
||||||
// implementation project(":ffmpeg")
|
// implementation project(":ffmpeg")
|
||||||
|
|
||||||
implementation "com.github.yausername.youtubedl-android:library:$youtubedlAndroidVer"
|
implementation "com.github.JunkFood02.youtubedl-android:library:$youtubedlAndroidVer"
|
||||||
implementation "com.github.yausername.youtubedl-android:ffmpeg:$youtubedlAndroidVer"
|
implementation "com.github.JunkFood02.youtubedl-android:ffmpeg:$youtubedlAndroidVer"
|
||||||
implementation "com.github.yausername.youtubedl-android:aria2c:$youtubedlAndroidVer"
|
implementation "com.github.JunkFood02.youtubedl-android:aria2c:$youtubedlAndroidVer"
|
||||||
|
|
||||||
implementation "androidx.appcompat:appcompat:$appCompatVer"
|
implementation "androidx.appcompat:appcompat:$appCompatVer"
|
||||||
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
|
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
android:theme="@style/AppTheme" >
|
android:theme="@style/AppTheme" >
|
||||||
<activity android:name=".MainActivity"
|
<activity android:name=".MainActivity"
|
||||||
android:windowSoftInputMode="adjustResize"
|
android:windowSoftInputMode="adjustResize"
|
||||||
|
android:label="@string/download"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
@ -51,11 +52,17 @@
|
||||||
android:name=".page.CustomCommandActivity"
|
android:name=".page.CustomCommandActivity"
|
||||||
android:theme="@style/AppDefaultTheme"
|
android:theme="@style/AppDefaultTheme"
|
||||||
android:parentActivityName=".MainActivity"
|
android:parentActivityName=".MainActivity"
|
||||||
|
android:label="@string/run_command"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="ytdlnis.page.CustomCommandActivity" />
|
<action android:name="ytdlnis.page.CustomCommandActivity" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<service
|
<service
|
||||||
android:name=".DownloaderService"
|
android:name=".DownloaderService"
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,10 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
import android.os.Environment
|
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.webkit.MimeTypeMap
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.content.FileProvider
|
|
||||||
import androidx.core.net.toUri
|
|
||||||
import com.deniscerri.ytdlnis.database.Video
|
import com.deniscerri.ytdlnis.database.Video
|
||||||
import com.deniscerri.ytdlnis.page.CustomCommandActivity
|
import com.deniscerri.ytdlnis.page.CustomCommandActivity
|
||||||
import com.deniscerri.ytdlnis.service.DownloadInfo
|
import com.deniscerri.ytdlnis.service.DownloadInfo
|
||||||
|
|
@ -31,12 +27,12 @@ import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.InputStream
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
import kotlin.jvm.functions.Function3
|
||||||
|
|
||||||
|
|
||||||
class DownloaderService : Service() {
|
class DownloaderService : Service() {
|
||||||
private val binder = LocalBinder()
|
private val binder = LocalBinder()
|
||||||
|
|
@ -50,8 +46,9 @@ class DownloaderService : Service() {
|
||||||
private var context: Context? = null
|
private var context: Context? = null
|
||||||
var downloadProcessID = "processID"
|
var downloadProcessID = "processID"
|
||||||
private var downloadNotificationID = 0
|
private var downloadNotificationID = 0
|
||||||
private val callback =
|
|
||||||
DownloadProgressCallback { progress: Float, etaInSeconds: Long, line: String? ->
|
private val callback: (Float, Long?, String?) -> Unit =
|
||||||
|
{ progress: Float, _: Long?, line: String? ->
|
||||||
downloadInfo.progress = progress.toInt()
|
downloadInfo.progress = progress.toInt()
|
||||||
downloadInfo.outputLine = line
|
downloadInfo.outputLine = line
|
||||||
downloadInfo.downloadQueue = downloadQueue
|
downloadInfo.downloadQueue = downloadQueue
|
||||||
|
|
@ -77,6 +74,13 @@ class DownloaderService : Service() {
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// private val callback = object : DownloadProgressCallback {
|
||||||
|
// override fun onProgressUpdate(progress: Float, etaInSeconds: Long, line: String?) {
|
||||||
|
// override fun onProgressUpdate(progress: Float, etaInSeconds: Long, line: String?) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
@ -318,23 +322,23 @@ class DownloaderService : Service() {
|
||||||
if (format == null) format = sharedPreferences.getString("audio_format", "")
|
if (format == null) format = sharedPreferences.getString("audio_format", "")
|
||||||
request.addOption("--audio-format", format!!)
|
request.addOption("--audio-format", format!!)
|
||||||
request.addOption("--embed-metadata")
|
request.addOption("--embed-metadata")
|
||||||
if (format == "mp3" || format == "m4a" || format == "flac") {
|
|
||||||
val embedThumb = sharedPreferences.getBoolean("embed_thumbnail", false)
|
val embedThumb = sharedPreferences.getBoolean("embed_thumbnail", false)
|
||||||
if (embedThumb) {
|
if (embedThumb) {
|
||||||
request.addOption("--embed-thumbnail")
|
request.addOption("--embed-thumbnail")
|
||||||
request.addOption("--convert-thumbnails", "png")
|
request.addOption("--convert-thumbnails", "png")
|
||||||
try {
|
try {
|
||||||
val config = File(cacheDir, "config.txt")
|
val config = File(cacheDir, "config.txt")
|
||||||
val config_data =
|
val config_data =
|
||||||
"--ppa \"ffmpeg: -c:v png -vf crop=\\\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\\\"\""
|
"--ppa \"ffmpeg: -c:v png -vf crop=\\\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\\\"\""
|
||||||
val stream = FileOutputStream(config)
|
val stream = FileOutputStream(config)
|
||||||
stream.write(config_data.toByteArray())
|
stream.write(config_data.toByteArray())
|
||||||
stream.close()
|
stream.close()
|
||||||
request.addOption("--config", config.absolutePath)
|
request.addOption("--config", config.absolutePath)
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
request.addCommands(Arrays.asList("--replace-in-metadata", "title", ".*.", video.title))
|
request.addCommands(Arrays.asList("--replace-in-metadata", "title", ".*.", video.title))
|
||||||
request.addCommands(
|
request.addCommands(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
|
|
@ -441,12 +445,9 @@ class DownloaderService : Service() {
|
||||||
|
|
||||||
private fun startCommandDownload(text: String?) {
|
private fun startCommandDownload(text: String?) {
|
||||||
var text = text
|
var text = text
|
||||||
if (!text!!.startsWith("yt-dlp ")) {
|
if (text!!.startsWith("yt-dlp")) {
|
||||||
Toast.makeText(context, "Wrong input! Try Again!", Toast.LENGTH_SHORT).show()
|
text = text.substring(5).trim { it <= ' ' }
|
||||||
finishService()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
text = text.substring(6).trim { it <= ' ' }
|
|
||||||
val request = YoutubeDLRequest(emptyList())
|
val request = YoutubeDLRequest(emptyList())
|
||||||
val commandRegex = "\"([^\"]*)\"|(\\S+)"
|
val commandRegex = "\"([^\"]*)\"|(\\S+)"
|
||||||
val m = Pattern.compile(commandRegex).matcher(text)
|
val m = Pattern.compile(commandRegex).matcher(text)
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,25 @@ public class CustomCommandActivity extends AppCompatActivity {
|
||||||
swapFabs();
|
swapFabs();
|
||||||
input.setEnabled(true);
|
input.setEnabled(true);
|
||||||
});
|
});
|
||||||
|
handleIntent(getIntent());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
handleIntent(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleIntent(Intent intent){
|
||||||
|
String action = intent.getAction();
|
||||||
|
String type = intent.getType();
|
||||||
|
Log.e(TAG, action + " " + type);
|
||||||
|
if (action.equals(Intent.ACTION_SEND) && type != null) {
|
||||||
|
Log.e(TAG, action);
|
||||||
|
String txt = "yt-dlp " + intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||||
|
input.setText(txt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void swapFabs(){
|
private void swapFabs(){
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ class UpdateUtil(var context: Context) {
|
||||||
else -> Toast.makeText(context, status.toString(), Toast.LENGTH_LONG).show()
|
else -> Toast.makeText(context, status.toString(), Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
updatingYTDL = false
|
updatingYTDL = false
|
||||||
}) { e: Throwable? ->
|
} as ((UpdateStatus?) -> Unit)?) { e: Throwable? ->
|
||||||
if (BuildConfig.DEBUG) Log.e(tag, context.getString(R.string.ytdl_update_failed), e)
|
if (BuildConfig.DEBUG) Log.e(tag, context.getString(R.string.ytdl_update_failed), e)
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
context,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
<item>alac</item>
|
<item>alac</item>
|
||||||
<item>flac</item>
|
<item>flac</item>
|
||||||
<item>opus</item>
|
<item>opus</item>
|
||||||
<item>vorbis</item>
|
|
||||||
<item>wav</item>
|
<item>wav</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ buildscript {
|
||||||
commonsIoVer = '2.5'
|
commonsIoVer = '2.5'
|
||||||
// supports java 1.6
|
// supports java 1.6
|
||||||
commonsCompressVer = '1.12'
|
commonsCompressVer = '1.12'
|
||||||
youtubedlAndroidVer = "master-SNAPSHOT"
|
youtubedlAndroidVer = "a3b971724d"
|
||||||
workVer = "2.7.1"
|
workVer = "2.7.1"
|
||||||
composeVer = "1.3.2"
|
composeVer = "1.3.2"
|
||||||
kotlinVer = "1.7.20"
|
kotlinVer = "1.7.20"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue