implemented download sections in audio/video tab

pull/72/head
deniscerri 3 years ago
parent 467c0bd16e
commit 55e878467c
No known key found for this signature in database
GPG Key ID: 95C43D517D830350

@ -171,6 +171,6 @@ dependencies {
implementation "com.squareup.okhttp3:logging-interceptor:4.7.2"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
implementation "com.google.android.exoplayer:exoplayer:2.18.5"
}

@ -0,0 +1,389 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "01fbf28d229b951415b597cf87ed52d0",
"entities": [
{
"tableName": "results",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL, `title` TEXT NOT NULL, `author` TEXT NOT NULL, `duration` TEXT NOT NULL, `thumb` TEXT NOT NULL, `website` TEXT NOT NULL, `playlistTitle` TEXT NOT NULL, `formats` TEXT NOT NULL, `creationTime` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "author",
"columnName": "author",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "duration",
"columnName": "duration",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "thumb",
"columnName": "thumb",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "website",
"columnName": "website",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "playlistTitle",
"columnName": "playlistTitle",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "formats",
"columnName": "formats",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "creationTime",
"columnName": "creationTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "history",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL, `title` TEXT NOT NULL, `author` TEXT NOT NULL, `duration` TEXT NOT NULL, `thumb` TEXT NOT NULL, `type` TEXT NOT NULL, `time` INTEGER NOT NULL, `downloadPath` TEXT NOT NULL, `website` TEXT NOT NULL, `format` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "author",
"columnName": "author",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "duration",
"columnName": "duration",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "thumb",
"columnName": "thumb",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "type",
"columnName": "type",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "time",
"columnName": "time",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "downloadPath",
"columnName": "downloadPath",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "website",
"columnName": "website",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "format",
"columnName": "format",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "downloads",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL, `title` TEXT NOT NULL, `author` TEXT NOT NULL, `thumb` TEXT NOT NULL, `duration` TEXT NOT NULL, `type` TEXT NOT NULL, `format` TEXT NOT NULL, `downloadSections` TEXT NOT NULL DEFAULT '', `allFormats` TEXT NOT NULL, `downloadPath` TEXT NOT NULL, `website` TEXT NOT NULL, `downloadSize` TEXT NOT NULL, `playlistTitle` TEXT NOT NULL, `audioPreferences` TEXT NOT NULL, `videoPreferences` TEXT NOT NULL, `customFileNameTemplate` TEXT NOT NULL, `SaveThumb` INTEGER NOT NULL, `status` TEXT NOT NULL DEFAULT 'Queued', `downloadStartTime` INTEGER NOT NULL DEFAULT 0)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "author",
"columnName": "author",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "thumb",
"columnName": "thumb",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "duration",
"columnName": "duration",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "type",
"columnName": "type",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "format",
"columnName": "format",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "downloadSections",
"columnName": "downloadSections",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "allFormats",
"columnName": "allFormats",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "downloadPath",
"columnName": "downloadPath",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "website",
"columnName": "website",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "downloadSize",
"columnName": "downloadSize",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "playlistTitle",
"columnName": "playlistTitle",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "audioPreferences",
"columnName": "audioPreferences",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "videoPreferences",
"columnName": "videoPreferences",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "customFileNameTemplate",
"columnName": "customFileNameTemplate",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "SaveThumb",
"columnName": "SaveThumb",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "status",
"columnName": "status",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "'Queued'"
},
{
"fieldPath": "downloadStartTime",
"columnName": "downloadStartTime",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "commandTemplates",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT NOT NULL, `content` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "content",
"columnName": "content",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "searchHistory",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `query` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "query",
"columnName": "query",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "templateShortcuts",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `content` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "content",
"columnName": "content",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '01fbf28d229b951415b597cf87ed52d0')"
]
}
}

@ -1,18 +1,18 @@
package com.deniscerri.ytdlnis.database
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.room.*
import androidx.room.migration.AutoMigrationSpec
import com.deniscerri.ytdlnis.database.dao.*
import com.deniscerri.ytdlnis.database.models.*
@TypeConverters(Converters::class)
@Database(
entities = [ResultItem::class, HistoryItem::class, DownloadItem::class, CommandTemplate::class, SearchHistoryItem::class, TemplateShortcut::class],
version = 1,
autoMigrations = []
version = 2,
autoMigrations = [
AutoMigration (from = 1, to = 2)
]
)
abstract class DBManager : RoomDatabase(){
abstract val resultDao : ResultDao
@ -39,5 +39,4 @@ abstract class DBManager : RoomDatabase(){
}
}
}
}

@ -16,6 +16,8 @@ data class DownloadItem(
val duration: String,
var type: DownloadViewModel.Type,
var format: Format,
@ColumnInfo(defaultValue = "")
var downloadSections: String,
val allFormats: ArrayList<Format>,
var downloadPath: String,
val website: String,

@ -131,6 +131,7 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
resultItem.duration,
type,
getFormat(resultItem.formats, type),
"",
resultItem.formats,
downloadPath!!, resultItem.website, "", resultItem.playlistTitle, audioPreferences, videoPreferences,customFileNameTemplate!!, saveThumb, DownloadRepository.Status.Processing.toString(), 0
)
@ -172,6 +173,7 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
historyItem.duration,
historyItem.type,
historyItem.format,
"",
ArrayList(),
downloadPath!!, historyItem.website, "", "", audioPreferences, videoPreferences,customFileNameTemplate!!, saveThumb, DownloadRepository.Status.Processing.toString(), 0
)

@ -0,0 +1,266 @@
package com.deniscerri.ytdlnis.ui.downloadcard
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.DialogInterface
import android.net.Uri
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.DisplayMetrics
import android.util.Log
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.widget.*
import androidx.lifecycle.lifecycleScope
import com.deniscerri.ytdlnis.R
import com.deniscerri.ytdlnis.database.models.DownloadItem
import com.deniscerri.ytdlnis.util.FileUtil
import com.deniscerri.ytdlnis.util.InfoUtil
import com.deniscerri.ytdlnis.util.UiUtil
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ui.PlayerView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.slider.RangeSlider
import com.google.android.material.textfield.TextInputLayout
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.*
class CutVideoBottomSheetDialog(private val item: DownloadItem, private val listener: VideoCutListener) : BottomSheetDialogFragment() {
private lateinit var behavior: BottomSheetBehavior<View>
private lateinit var fileUtil: FileUtil
private lateinit var infoUtil: InfoUtil
private lateinit var uiUtil: UiUtil
private lateinit var player: Player
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
fileUtil = FileUtil()
uiUtil = UiUtil(fileUtil)
infoUtil = InfoUtil(requireActivity().applicationContext)
}
@SuppressLint("RestrictedApi")
override fun setupDialog(dialog: Dialog, style: Int) {
super.setupDialog(dialog, style)
val view = LayoutInflater.from(context).inflate(R.layout.cut_video_sheet, null)
dialog.setContentView(view)
dialog.setOnShowListener {
behavior = BottomSheetBehavior.from(view.parent as View)
val displayMetrics = DisplayMetrics()
requireActivity().windowManager.defaultDisplay.getMetrics(displayMetrics)
behavior.peekHeight = displayMetrics.heightPixels / 2
}
player = ExoPlayer.Builder(requireContext()).build()
val videoView = view.findViewById<PlayerView>(R.id.video_view)
videoView.player = player
val progress = view.findViewById<ProgressBar>(R.id.progress)
val rangeSlider = view.findViewById<RangeSlider>(R.id.rangeSlider)
val fromTextInput = view.findViewById<TextInputLayout>(R.id.from_textinput)
val toTextInput = view.findViewById<TextInputLayout>(R.id.to_textinput)
val timeSeconds = convertStringToTimestamp(item.duration)
if (item.downloadSections.isEmpty()){
fromTextInput.editText!!.setText("00:00")
toTextInput.editText!!.setText(item.duration)
}else{
val stamps = item.downloadSections.split("-")
fromTextInput.editText!!.setText(stamps[0])
toTextInput.editText!!.setText(stamps[1])
val startSeconds = convertStringToTimestamp(stamps[0])
val endSeconds = convertStringToTimestamp(stamps[1])
val startValue = (startSeconds.toFloat() / timeSeconds) * 100
val endValue = (endSeconds.toFloat() / timeSeconds) * 100
rangeSlider.setValues(startValue, endValue)
}
lifecycleScope.launch {
try {
val url = withContext(Dispatchers.IO){
infoUtil.getStreamingUrl(item.url)
}
progress.visibility = View.GONE
player.addMediaItem(MediaItem.fromUri(Uri.parse(url)))
player.prepare()
player.seekTo((((rangeSlider.values[0].toInt() * timeSeconds) / 100) * 1000).toLong())
player.play()
}catch (e: Exception){
progress.visibility = View.GONE
videoView.visibility = View.GONE
e.printStackTrace()
}
}
//poll video progress
lifecycleScope.launch {
audioProgress(player).collect {
val startTimestamp = (rangeSlider.values[0].toInt() * timeSeconds) / 100
val endTimestamp = (rangeSlider.values[1].toInt() * timeSeconds) / 100
if (it >= endTimestamp){
player.seekTo((startTimestamp * 1000).toLong())
}
}
}
videoView.setOnClickListener {
if (player.isPlaying) player.stop()
else {
player.prepare()
player.play()
}
}
rangeSlider.addOnChangeListener { rangeSlider, value, fromUser ->
val values = rangeSlider.values
val startTimestamp = (values[0].toInt() * timeSeconds) / 100
val endTimestamp = (values[1].toInt() * timeSeconds) / 100
val startTimestampString = infoUtil.formatIntegerDuration(startTimestamp)
val endTimestampString = infoUtil.formatIntegerDuration(endTimestamp)
fromTextInput.editText!!.setText(startTimestampString)
toTextInput.editText!!.setText(endTimestampString)
try {
player.seekTo((startTimestamp * 1000).toLong())
}catch (ignored: Exception) {}
listener.onChangeCut(startTimestampString, endTimestampString)
}
fromTextInput.editText!!.setOnKeyListener(object : View.OnKeyListener {
override fun onKey(p0: View?, keyCode: Int, event: KeyEvent?): Boolean {
if ((event!!.action == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
val startTimestamp = (rangeSlider.values[0].toInt() * timeSeconds) / 100
val endTimestamp = (rangeSlider.values[1].toInt() * timeSeconds) / 100
fromTextInput.editText!!.clearFocus()
val seconds = convertStringToTimestamp(fromTextInput.editText!!.text.toString())
if (seconds == 0) {
fromTextInput.editText!!.setText(infoUtil.formatIntegerDuration(startTimestamp))
return true
}
val startValue = (seconds.toFloat() / endTimestamp) * 100
if (startValue > 100){
fromTextInput.editText!!.setText(infoUtil.formatIntegerDuration(startTimestamp))
return true
}
rangeSlider.setValues(startValue, rangeSlider.values[1])
val startValueTimeStampSeconds = (startValue.toInt() * timeSeconds) / 100
fromTextInput.editText!!.setText(infoUtil.formatIntegerDuration(startValueTimeStampSeconds))
return true;
}
return false;
}
})
toTextInput.editText!!.setOnKeyListener(object : View.OnKeyListener {
override fun onKey(p0: View?, keyCode: Int, event: KeyEvent?): Boolean {
if ((event!!.action == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
val endTimestamp = (rangeSlider.values[1].toInt() * timeSeconds) / 100
toTextInput.editText!!.clearFocus()
val seconds = convertStringToTimestamp(toTextInput.editText!!.text.toString())
if (seconds == 0) {
toTextInput.editText!!.setText(infoUtil.formatIntegerDuration(endTimestamp))
return true
}
val endValue = (seconds.toFloat() / endTimestamp) * 100
if (endValue > 100 || endValue <= rangeSlider.values[0].toInt()){
toTextInput.editText!!.setText(infoUtil.formatIntegerDuration(endTimestamp))
return true
}
rangeSlider.setValues(rangeSlider.values[0], endValue)
val endValueTimeStampSeconds = (endValue.toInt() * timeSeconds) / 100
toTextInput.editText!!.setText(infoUtil.formatIntegerDuration(endValueTimeStampSeconds))
return true;
}
return false;
}
})
val cancelBtn = view.findViewById<Button>(R.id.cancelButton)
cancelBtn.setOnClickListener {
listener.onCancelCut()
dismiss()
}
}
private fun audioProgress(player: Player?) = flow<Int> {
while (true) {
emit((player!!.currentPosition / 1000).toInt())
delay(1000)
}
}.flowOn(Dispatchers.Main)
private fun convertStringToTimestamp(duration: String): Int {
return try {
val timeArray = duration.split(":")
Log.e("aa", timeArray.toString())
var timeSeconds = timeArray[timeArray.lastIndex].toInt()
var times = 60
for (i in timeArray.lastIndex - 1 downTo 0) {
timeSeconds += timeArray[i].toInt() * times
times *= 60
}
timeSeconds
}catch (e: Exception){
e.printStackTrace()
0
}
}
override fun onCancel(dialog: DialogInterface) {
super.onCancel(dialog)
cleanUp()
}
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
cleanUp()
}
private fun cleanUp(){
player.stop()
parentFragmentManager.beginTransaction().remove(parentFragmentManager.findFragmentByTag("cutVideoSheet")!!).commit()
}
}
interface VideoCutListener{
fun onCancelCut()
fun onChangeCut(from: String, to: String)
}

@ -240,6 +240,25 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr
dialog.show()
}
val cut = view.findViewById<Chip>(R.id.cut)
cut.text = downloadItem.downloadSections
val cutVideoListener = object : VideoCutListener {
override fun onCancelCut() {
downloadItem.downloadSections = ""
cut.text = ""
}
override fun onChangeCut(from: String, to: String) {
val value = "${from}-${to}"
downloadItem.downloadSections = value
cut.text = value
}
}
cut.setOnClickListener {
val bottomSheet = CutVideoBottomSheetDialog(downloadItem, cutVideoListener)
bottomSheet.show(parentFragmentManager, "cutVideoSheet")
}
val copyURL = view.findViewById<Chip>(R.id.copy_url)
copyURL.setOnClickListener {
val clipboard: ClipboardManager =

@ -260,6 +260,25 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr
dialog.show()
}
val cut = view.findViewById<Chip>(R.id.cut)
cut.text = downloadItem.downloadSections
val cutVideoListener = object : VideoCutListener {
override fun onCancelCut() {
downloadItem.downloadSections = ""
cut.text = ""
}
override fun onChangeCut(from: String, to: String) {
val value = "${from}-${to}"
downloadItem.downloadSections = value
cut.text = value
}
}
cut.setOnClickListener {
val bottomSheet = CutVideoBottomSheetDialog(downloadItem, cutVideoListener)
bottomSheet.show(parentFragmentManager, "cutVideoSheet")
}
val copyURL = view.findViewById<Chip>(R.id.copy_url)
copyURL.setOnClickListener {
val clipboard: ClipboardManager =

@ -614,7 +614,7 @@ class InfoUtil(context: Context) {
return duration
}
private fun formatIntegerDuration(dur: Int): String {
fun formatIntegerDuration(dur: Int): String {
var format = String.format(
Locale.getDefault(),
"%02d:%02d:%02d",
@ -628,6 +628,28 @@ class InfoUtil(context: Context) {
return format
}
fun getStreamingUrl(url: String) : String {
try {
val request = YoutubeDLRequest(url)
request.addOption("-j")
request.addOption("--skip-download")
request.addOption("-R", "1")
request.addOption("--socket-timeout", "5")
val youtubeDLResponse = YoutubeDL.getInstance().execute(request)
val results: Array<String?> = try {
val lineSeparator = System.getProperty("line.separator")
youtubeDLResponse.out.split(lineSeparator!!).toTypedArray()
} catch (e: Exception) {
arrayOf(youtubeDLResponse.out)
}
val jsonObject = JSONObject(results[0]!!)
val streamURL = jsonObject.getString("urls")
return streamURL.split("\n")[0]
} catch (e: Exception) {
return ""
}
}
class PlaylistTuple internal constructor(
var nextPageToken: String,
var videos: ArrayList<ResultItem?>

@ -109,13 +109,17 @@ class DownloadWorker(
request.addOption("--sponsorblock-remove", filters)
}
if(downloadItem.title.isNotEmpty()){
if(downloadItem.title.isNotBlank()){
request.addCommands(listOf("--replace-in-metadata","title",".*.",downloadItem.title))
}
if (downloadItem.author.isNotEmpty()){
if (downloadItem.author.isNotBlank()){
request.addCommands(listOf("--replace-in-metadata","uploader",".*.",downloadItem.author))
}
if (downloadItem.customFileNameTemplate.isBlank()) downloadItem.customFileNameTemplate = "%(uploader)s - %(title)s"
if (downloadItem.downloadSections.isNotBlank()){
request.addOption("--download-sections", "*${downloadItem.downloadSections}")
}
}
if (sharedPreferences.getBoolean("restrict_filenames", true)) {
@ -221,11 +225,12 @@ class DownloadWorker(
}
}
val titleRegex = Regex("[^A-Za-z\\d ]")
val logDownloads = sharedPreferences.getBoolean("log_downloads", false) && !sharedPreferences.getBoolean("incognito", false)
val logFolder = File(context.filesDir.absolutePath + "/logs")
val logFile = File(context.filesDir.absolutePath + """/logs/${downloadItem.id} - ${titleRegex.replace(downloadItem.title, "")}##${downloadItem.type}##${downloadItem.format.format_id}.log""")
runCatching {
val titleRegex = Regex("[^A-Za-z\\d ]")
val logDownloads = sharedPreferences.getBoolean("log_downloads", false) && !sharedPreferences.getBoolean("incognito", false)
val logFolder = File(context.filesDir.absolutePath + "/logs")
val logFile = File(context.filesDir.absolutePath + """/logs/${downloadItem.id} - ${titleRegex.replace(downloadItem.title, "")}##${downloadItem.type}##${downloadItem.format.format_id}.log""")
if (logDownloads){
logFolder.mkdirs()
logFile.createNewFile()
@ -284,12 +289,8 @@ class DownloadWorker(
}
return Result.failure()
}else{
val logDownloads = sharedPreferences.getBoolean("log_downloads", false)
if (logDownloads){
val logFile = File(context.filesDir.absolutePath + """/logs/${downloadItem.id} - ${downloadItem.title}##${downloadItem.type}##${downloadItem.format.format_id}.log""")
if (logFile.exists()){
logFile.appendText("${it.message}\n")
}
if (logDownloads && logFile.exists()){
logFile.appendText("${it.message}\n")
}
tempFileDir.delete()
@ -314,20 +315,6 @@ class DownloadWorker(
return Result.success()
}
// private fun getDownloadLocation(type: String, context: Context): String? {
// val sharedPreferences = context.getSharedPreferences("root_preferences",
// Service.MODE_PRIVATE
// )
// val downloadsDir: String? = if (type == "audio") {
// sharedPreferences.getString("music_path", context.getString(R.string.music_path))
// } else {
// sharedPreferences.getString("video_path", context.getString(R.string.video_path))
// }
// return downloadsDir
// }
@Throws(Exception::class)
private fun moveFile(originDir: File, downLocation: String, progress: (progress: Int) -> Unit) : String{
val fileUtil = FileUtil()

@ -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="M9.64,7.64c0.23,-0.5 0.36,-1.05 0.36,-1.64 0,-2.21 -1.79,-4 -4,-4S2,3.79 2,6s1.79,4 4,4c0.59,0 1.14,-0.13 1.64,-0.36L10,12l-2.36,2.36C7.14,14.13 6.59,14 6,14c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4c0,-0.59 -0.13,-1.14 -0.36,-1.64L12,14l7,7h3v-1L9.64,7.64zM6,8c-1.1,0 -2,-0.89 -2,-2s0.9,-2 2,-2 2,0.89 2,2 -0.9,2 -2,2zM6,20c-1.1,0 -2,-0.89 -2,-2s0.9,-2 2,-2 2,0.89 2,2 -0.9,2 -2,2zM12,12.5c-0.28,0 -0.5,-0.22 -0.5,-0.5s0.22,-0.5 0.5,-0.5 0.5,0.22 0.5,0.5 -0.22,0.5 -0.5,0.5zM19,3l-6,6 2,2 7,-7L22,3z"/>
</vector>

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:paddingBottom="20dp"
android:layout_height="wrap_content">
<com.google.android.material.card.MaterialCardView
android:id="@+id/frame_layout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="H,16:9"
app:layout_constraintStart_toStartOf="parent"
android:layout_margin="10dp"
app:cardCornerRadius="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
app:resize_mode="fixed_height"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:use_controller="false"
app:layout_constraintTop_toTopOf="parent"
app:useDefaultControls="true" >
</com.google.android.exoplayer2.ui.PlayerView>
</com.google.android.material.card.MaterialCardView>
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:indeterminate="true"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/frame_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.slider.RangeSlider
android:id="@+id/rangeSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:valueFrom="00.0"
app:labelBehavior="gone"
android:valueTo="100.0"
app:layout_constraintTop_toBottomOf="@+id/frame_layout"
app:values="@array/initial_slider_values"
tools:layout_editor_absoluteX="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rangeSlider">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/from_textinput"
style="@style/Widget.Material3.TextInputLayout.FilledBox"
android:layout_width="wrap_content"
android:hint="@string/start"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/colon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingHorizontal="10dp"
android:text=":"
android:textSize="20sp"
android:textStyle="bold" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/to_textinput"
style="@style/Widget.Material3.TextInputLayout.FilledBox"
android:layout_width="wrap_content"
android:hint="@string/end"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/colon">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<Button
android:id="@+id/cancelButton"
style="@style/Widget.Material3.Button.ElevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginEnd="16dp"
android:text="@string/cancel"
app:icon="@drawable/ic_cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rangeSlider"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -15,56 +15,6 @@
android:padding="10dp"
android:orientation="vertical">
<!-- <androidx.constraintlayout.widget.ConstraintLayout-->
<!-- android:id="@+id/result_card_constraintLayout"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content">-->
<!-- <RelativeLayout-->
<!-- android:id="@+id/result_relative_layout"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="0dp"-->
<!-- app:layout_constraintDimensionRatio="H,16:9"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent">-->
<!-- <com.google.android.material.card.MaterialCardView-->
<!-- android:id="@+id/result_card_view"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- app:cardCornerRadius="10dp"-->
<!-- app:cardElevation="10dp"-->
<!-- app:cardMaxElevation="12dp"-->
<!-- app:cardBackgroundColor="@color/black"-->
<!-- app:cardPreventCornerOverlap="true"-->
<!-- android:checkable="true"-->
<!-- app:strokeWidth="0dp"-->
<!-- android:layout_margin="10dp">-->
<!-- <com.devbrackets.android.exomedia.ui.widget.VideoView-->
<!-- android:id="@+id/result_video_view"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- app:useDefaultControls="true"/>-->
<!-- </com.google.android.material.card.MaterialCardView>-->
<!-- </RelativeLayout>-->
<!-- </androidx.constraintlayout.widget.ConstraintLayout>-->
<!-- <com.google.android.material.slider.RangeSlider-->
<!-- android:id="@+id/range_slider"-->
<!-- android:layout_marginHorizontal="10dp"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:values="@array/initial_slider_values"-->
<!-- android:valueFrom="0.0"-->
<!-- android:valueTo="100.0" />-->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/title_textinput"
android:layout_width="match_parent"
@ -174,61 +124,100 @@
android:layout_height="wrap_content"
android:text="@string/adjust_audio" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
<HorizontalScrollView
android:scrollbars="none"
android:layout_width="wrap_content"
app:chipSpacingVertical="0dp"
app:singleLine="false"
android:layout_height="wrap_content">
android:layout_height="wrap_content" >
<com.google.android.material.chip.Chip
android:id="@+id/embed_thumb"
style="@style/Widget.Material3.Chip.Filter.Elevated"
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/embed_thumb"/>
app:chipSpacingVertical="0dp"
app:singleLine="true"
android:layout_height="wrap_content">
<com.google.android.material.chip.Chip
android:id="@+id/split_by_chapters"
style="@style/Widget.Material3.Chip.Filter.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/split_by_chapters"/>
<com.google.android.material.chip.Chip
android:id="@+id/embed_thumb"
style="@style/Widget.Material3.Chip.Filter.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/embed_thumb"/>
<com.google.android.material.chip.Chip
android:id="@+id/sponsorblock_filters"
style="@style/Widget.Material3.Chip.Assist.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SponsorBlock"
app:chipIconVisible="true"
app:chipIcon="@drawable/ic_money"
android:minWidth="30dp"
app:cornerRadius="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.chip.Chip
android:id="@+id/copy_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/copy_url"
app:chipIconVisible="true"
app:chipIcon="@drawable/ic_clipboard"
android:minWidth="30dp"
app:cornerRadius="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.chip.Chip
android:id="@+id/split_by_chapters"
style="@style/Widget.Material3.Chip.Filter.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/split_by_chapters"/>
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
<HorizontalScrollView
android:scrollbars="none"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</com.google.android.material.chip.ChipGroup>
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup2"
android:layout_width="wrap_content"
app:chipSpacingVertical="0dp"
app:singleLine="true"
android:layout_height="wrap_content">
<com.google.android.material.chip.Chip
android:id="@+id/sponsorblock_filters"
style="@style/Widget.Material3.Chip.Assist.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SponsorBlock"
app:chipIconVisible="true"
app:chipIcon="@drawable/ic_money"
android:minWidth="30dp"
app:cornerRadius="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.chip.Chip
android:id="@+id/cut"
style="@style/Widget.Material3.Chip.Assist.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
app:chipIconVisible="true"
app:chipIcon="@drawable/ic_cut"
android:minWidth="30dp"
app:cornerRadius="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
<com.google.android.material.chip.Chip
android:id="@+id/copy_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/copy_url"
app:chipIconVisible="true"
app:chipIcon="@drawable/ic_clipboard"
android:minWidth="30dp"
app:cornerRadius="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>

@ -13,55 +13,6 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">
<!-- <androidx.constraintlayout.widget.ConstraintLayout-->
<!-- android:id="@+id/result_card_constraintLayout"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content">-->
<!-- <RelativeLayout-->
<!-- android:id="@+id/result_relative_layout"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="0dp"-->
<!-- app:layout_constraintDimensionRatio="H,16:9"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent">-->
<!-- <com.google.android.material.card.MaterialCardView-->
<!-- android:id="@+id/result_card_view"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- app:cardCornerRadius="10dp"-->
<!-- app:cardElevation="10dp"-->
<!-- app:cardMaxElevation="12dp"-->
<!-- app:cardBackgroundColor="@color/black"-->
<!-- app:cardPreventCornerOverlap="true"-->
<!-- android:checkable="true"-->
<!-- app:strokeWidth="0dp"-->
<!-- android:layout_margin="10dp">-->
<!-- <com.devbrackets.android.exomedia.ui.widget.VideoView-->
<!-- android:id="@+id/result_video_view"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- app:useDefaultControls="true"/>-->
<!-- </com.google.android.material.card.MaterialCardView>-->
<!-- </RelativeLayout>-->
<!-- </androidx.constraintlayout.widget.ConstraintLayout>-->
<!-- <com.google.android.material.slider.RangeSlider-->
<!-- android:id="@+id/range_slider"-->
<!-- android:layout_marginHorizontal="10dp"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:values="@array/initial_slider_values"-->
<!-- android:valueFrom="0.0"-->
<!-- android:valueTo="100.0" />-->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/title_textinput"
style="@style/Widget.Material3.TextInputLayout.FilledBox"
@ -242,15 +193,14 @@
android:checked="false"
android:text="@string/split_by_chapters"/>
<com.google.android.material.chip.Chip
android:id="@+id/copy_url"
android:id="@+id/cut"
style="@style/Widget.Material3.Chip.Assist.Elevated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/copy_url"
app:chipIconVisible="true"
app:chipIcon="@drawable/ic_clipboard"
app:chipIcon="@drawable/ic_cut"
android:minWidth="30dp"
app:cornerRadius="10dp"
app:layout_constraintBottom_toBottomOf="parent"
@ -258,11 +208,27 @@
app:layout_constraintTop_toTopOf="parent" />
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
<com.google.android.material.chip.Chip
android:id="@+id/copy_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/copy_url"
app:chipIconVisible="true"
app:chipIcon="@drawable/ic_clipboard"
android:minWidth="30dp"
app:cornerRadius="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>

@ -34,7 +34,7 @@
android:id="@+id/bottom_sheet_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shortcuts_desc"
android:text="@string/select"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"

@ -65,15 +65,18 @@
<item>az</item>
<item>bn</item>
<item>de</item>
<item>es</item>
<item>fr</item>
<item>in</item>
<item>it</item>
<item>ja</item>
<item>lv</item>
<item>nb</item>
<item>pl</item>
<item>ru</item>
<item>sq</item>
<item>tr</item>
<item>uk</item>
<item>vi</item>
</string-array>
@ -89,4 +92,9 @@
<item>video</item>
<item>command</item>
</string-array>
<array name="initial_slider_values">
<item>0.0</item>
<item>100.0</item>
</array>
</resources>

@ -186,4 +186,6 @@
<string name="kill_app">Terminate App</string>
<string name="confirm_terminate"><![CDATA[All downloads will be stopped & the app will be force closed]]></string>
<string name="dont_ask_again">Don\'t ask again</string>
<string name="end">End</string>
<string name="start">Start</string>
</resources>

@ -5,14 +5,17 @@
<locale android:name="az"/>
<locale android:name="bn"/>
<locale android:name="de"/>
<locale android:name="es"/>
<locale android:name="fr"/>
<locale android:name="in"/>
<locale android:name="it"/>
<locale android:name="ja"/>
<locale android:name="lv"/>
<locale android:name="nb-NO"/>
<locale android:name="pl"/>
<locale android:name="ru"/>
<locale android:name="sq-AL"/>
<locale android:name="tr-TR"/>
<locale android:name="uk"/>
<locale android:name="vi"/>
</locale-config>

@ -29,6 +29,7 @@ buildscript {
retrofitVer = "2.9.0"
kodeinVer = "7.16.0"
navVer = "2.5.3"
media3_version = "1.0.0"
}
repositories {
mavenCentral()

Loading…
Cancel
Save