added ability keep cached files when download is finished
This commit is contained in:
parent
e834b37362
commit
fa341a53f2
13 changed files with 494 additions and 93 deletions
428
app/schemas/com.deniscerri.ytdlnis.database.DBManager/5.json
Normal file
428
app/schemas/com.deniscerri.ytdlnis.database.DBManager/5.json
Normal file
|
|
@ -0,0 +1,428 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 5,
|
||||
"identityHash": "740a11120b61827e949e8cecb28b1d1d",
|
||||
"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, `downloadId` 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": "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
|
||||
},
|
||||
{
|
||||
"fieldPath": "downloadId",
|
||||
"columnName": "downloadId",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
}
|
||||
],
|
||||
"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": []
|
||||
},
|
||||
{
|
||||
"tableName": "cookies",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `url` TEXT NOT NULL, `content` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "url",
|
||||
"columnName": "url",
|
||||
"affinity": "TEXT",
|
||||
"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, '740a11120b61827e949e8cecb28b1d1d')"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -120,10 +120,10 @@ class ActiveDownloadAdapter(onItemClickListener: OnItemClickListener, activity:
|
|||
|
||||
if (fileSize.visibility == View.VISIBLE && codec.visibility == View.GONE){
|
||||
fileSize.shapeAppearanceModel = ShapeAppearanceModel.builder()
|
||||
.setTopRightCorner(CornerFamily.ROUNDED, 40F)
|
||||
.setBottomRightCorner(CornerFamily.ROUNDED, 40F)
|
||||
.setTopLeftCorner(CornerFamily.ROUNDED, 0F)
|
||||
.setBottomLeftCorner(CornerFamily.ROUNDED, 0F)
|
||||
.setTopRightCorner(CornerFamily.ROUNDED, 20F)
|
||||
.setBottomRightCorner(CornerFamily.ROUNDED, 20F)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@ import com.deniscerri.ytdlnis.database.models.*
|
|||
@TypeConverters(Converters::class)
|
||||
@Database(
|
||||
entities = [ResultItem::class, HistoryItem::class, DownloadItem::class, CommandTemplate::class, SearchHistoryItem::class, TemplateShortcut::class, CookieItem::class],
|
||||
version = 4,
|
||||
version = 5,
|
||||
autoMigrations = [
|
||||
AutoMigration (from = 1, to = 2),
|
||||
AutoMigration (from = 2, to = 3),
|
||||
AutoMigration (from = 3, to = 4)
|
||||
AutoMigration (from = 3, to = 4),
|
||||
AutoMigration (from = 4, to = 5)
|
||||
]
|
||||
)
|
||||
abstract class DBManager : RoomDatabase(){
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.deniscerri.ytdlnis.database.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel
|
||||
|
|
@ -17,5 +18,7 @@ data class HistoryItem(
|
|||
val time: Long,
|
||||
val downloadPath: String,
|
||||
val website: String,
|
||||
val format: Format
|
||||
val format: Format,
|
||||
@ColumnInfo(defaultValue = "0")
|
||||
val downloadId: Long
|
||||
)
|
||||
|
|
@ -218,7 +218,7 @@ class DownloadViewModel(private val application: Application) : AndroidViewModel
|
|||
val audioPreferences = AudioPreferences(embedThumb, false, ArrayList(sponsorblock!!))
|
||||
val videoPreferences = VideoPreferences(embedSubs, addChapters, false, ArrayList(sponsorblock), saveSubs)
|
||||
|
||||
return DownloadItem(0,
|
||||
return DownloadItem(historyItem.downloadId,
|
||||
historyItem.url,
|
||||
historyItem.title,
|
||||
historyItem.author,
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
private var commandPath: Preference? = null
|
||||
private var accessAllFiles : Preference? = null
|
||||
private var clearCache: Preference? = null
|
||||
private var keepCache: SwitchPreferenceCompat? = null
|
||||
private var incognito: SwitchPreferenceCompat? = null
|
||||
private var preferredDownloadType : ListPreference? = null
|
||||
private var searchEngine : ListPreference? = null
|
||||
|
|
@ -123,6 +124,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
commandPath = findPreference("command_path")
|
||||
accessAllFiles = findPreference("access_all_files")
|
||||
clearCache = findPreference("clear_cache")
|
||||
keepCache = findPreference("keep_cache")
|
||||
incognito = findPreference("incognito")
|
||||
preferredDownloadType = findPreference("preferred_download_type")
|
||||
searchEngine = findPreference("search_engine")
|
||||
|
|
@ -171,8 +173,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
entries.add(Locale(it).getDisplayName(Locale(it)))
|
||||
}
|
||||
language!!.entries = entries.toTypedArray()
|
||||
val lang = if (values.contains(Locale.getDefault().language)) Locale.getDefault().language else "en"
|
||||
editor.putString("app_language", lang)
|
||||
}else{
|
||||
language!!.isVisible = false
|
||||
}
|
||||
|
|
@ -183,9 +183,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
ignoreBatteryOptimization!!.isVisible = false
|
||||
}
|
||||
|
||||
editor.putString("ytdlnis_theme", theme!!.value)
|
||||
editor.putString("theme_accent", accent!!.value)
|
||||
editor.putBoolean("high_contrast", highContrast!!.isChecked)
|
||||
|
||||
if (preferences.getString("music_path", "")!!.isEmpty()) {
|
||||
editor.putString("music_path", getString(R.string.music_path))
|
||||
|
|
@ -197,44 +194,11 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
editor.putString("command_path", getString(R.string.command_path))
|
||||
}
|
||||
|
||||
if((Build.VERSION.SDK_INT >= 30 && Environment.isExternalStorageManager()) ||
|
||||
Build.VERSION.SDK_INT < 30) {
|
||||
if((VERSION.SDK_INT >= 30 && Environment.isExternalStorageManager()) ||
|
||||
VERSION.SDK_INT < 30) {
|
||||
accessAllFiles!!.isVisible = false
|
||||
}
|
||||
|
||||
editor.putBoolean("incognito", incognito!!.isChecked)
|
||||
editor.putString("preferred_download_type", preferredDownloadType!!.value)
|
||||
editor.putString("search_engine", searchEngine!!.value)
|
||||
editor.putString("start_destination", startDestination!!.value)
|
||||
editor.putBoolean("download_card", downloadCard!!.isChecked)
|
||||
editor.putBoolean("quick_download", quickDownload!!.isChecked)
|
||||
editor.putBoolean("metered_networks", meteredNetwork!!.isChecked)
|
||||
editor.putString("api_key", apiKey!!.text)
|
||||
editor.putBoolean("home_recommendations", homeRecommendations!!.isChecked)
|
||||
editor.putString("locale", locale!!.value)
|
||||
editor.putInt("concurrent_fragments", concurrentFragments!!.value)
|
||||
editor.putInt("concurrent_downloads", concurrentDownloads!!.value)
|
||||
editor.putString("limit_rate", limitRate!!.text)
|
||||
editor.putBoolean("aria2", aria2!!.isChecked)
|
||||
editor.putBoolean("log_downloads", logDownloads!!.isChecked)
|
||||
editor.putStringSet("sponsorblock_filters", sponsorblockFilters!!.values)
|
||||
editor.putString("file_name_template", filenameTemplate!!.text)
|
||||
editor.putBoolean("restrict_filenames", restrictFilenames!!.isChecked)
|
||||
editor.putBoolean("mtime", mtime!!.isChecked)
|
||||
editor.putBoolean("embed_subtitles", embedSubtitles!!.isChecked)
|
||||
editor.putBoolean("write_subtitles", writeSubtitles!!.isChecked)
|
||||
editor.putBoolean("embed_thumbnail", embedThumbnail!!.isChecked)
|
||||
editor.putBoolean("add_chapters", addChapters!!.isChecked)
|
||||
editor.putBoolean("write_thumbnail", writeThumbnail!!.isChecked)
|
||||
editor.putString("audio_format", audioFormat!!.value)
|
||||
editor.putString("video_format", videoFormat!!.value)
|
||||
editor.putInt("audio_quality", audioQuality!!.value)
|
||||
editor.putString("video_quality", videoQuality!!.value)
|
||||
editor.putString("format_id", formatID!!.text)
|
||||
editor.putBoolean("nightly_ytdl", updateNightlyYTDL!!.isChecked)
|
||||
editor.putBoolean("update_formats", updateFormats!!.isChecked)
|
||||
editor.putString("formats_source", formatSource!!.value)
|
||||
editor.putBoolean("update_app", updateApp!!.isChecked)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
|
|
@ -366,6 +330,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
}
|
||||
true
|
||||
}
|
||||
keepCache!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
val enable = newValue as Boolean
|
||||
editor.putBoolean("keep_cache", enable)
|
||||
editor.apply()
|
||||
true
|
||||
}
|
||||
incognito!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
val enable = newValue as Boolean
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.media.MediaScannerConnection
|
|||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.DocumentsContract
|
||||
import android.util.Log
|
||||
import android.webkit.MimeTypeMap
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.database.models.DownloadItem
|
||||
|
|
@ -77,19 +78,22 @@ class FileUtil() {
|
|||
return context.getString(R.string.unfound_file);
|
||||
}
|
||||
@Throws(Exception::class)
|
||||
fun moveFile(originDir: File, context: Context, destDir: String, progress: (p: Int) -> Unit) : String {
|
||||
fun moveFile(originDir: File, context: Context, destDir: String, keepCache: Boolean, progress: (p: Int) -> Unit) : String {
|
||||
val fileList = mutableListOf<File>()
|
||||
val dir = File(formatPath(destDir))
|
||||
if (!dir.exists()) dir.mkdirs()
|
||||
originDir.listFiles()?.forEach {
|
||||
Log.e("zz", it.name)
|
||||
val destFile = File(dir.absolutePath + "/${it.name}")
|
||||
|
||||
try {
|
||||
if (it.name.equals("rList")){
|
||||
if (it.name.matches("(^config.*.\\.txt\$)|(rList)|(part-Frag)".toRegex())){
|
||||
it.delete()
|
||||
return@forEach
|
||||
}
|
||||
|
||||
if(it.name.contains(".part-Frag")) return@forEach
|
||||
|
||||
val mimeType =
|
||||
MimeTypeMap.getSingleton().getMimeTypeFromExtension(it.extension) ?: "*/*"
|
||||
|
||||
|
|
@ -132,7 +136,9 @@ class FileUtil() {
|
|||
}
|
||||
|
||||
}
|
||||
originDir.deleteRecursively()
|
||||
if (!keepCache){
|
||||
originDir.deleteRecursively()
|
||||
}
|
||||
return scanMedia(fileList, context)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -148,11 +148,11 @@ class NotificationUtil(var context: Context) {
|
|||
|
||||
notificationBuilder
|
||||
.setContentTitle(context.getString(R.string.updating_download_data))
|
||||
.setSmallIcon(R.drawable.ic_launcher_foreground_large)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
.setLargeIcon(
|
||||
BitmapFactory.decodeResource(
|
||||
context.resources,
|
||||
R.drawable.ic_launcher_foreground_large
|
||||
android.R.drawable.stat_sys_download
|
||||
)
|
||||
)
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
|
|
|
|||
|
|
@ -170,6 +170,12 @@ class DownloadWorker(
|
|||
request.addOption("--cookies", cookiesFile.absolutePath)
|
||||
}
|
||||
|
||||
val keepCache = sharedPreferences.getBoolean("keep_cache", false)
|
||||
if(keepCache){
|
||||
request.addOption("--part")
|
||||
request.addOption("--keep-fragments")
|
||||
}
|
||||
|
||||
when(type){
|
||||
DownloadViewModel.Type.audio -> {
|
||||
var audioQualityId : String = downloadItem.format.format_id
|
||||
|
|
@ -177,33 +183,23 @@ class DownloadWorker(
|
|||
else if (audioQualityId == context.getString(R.string.worst_quality)) audioQualityId = "worstaudio"
|
||||
|
||||
val ext = downloadItem.format.container
|
||||
if (audioQualityId.isBlank()) request.addOption("-x")
|
||||
else request.addOption("-f", audioQualityId)
|
||||
if (audioQualityId.isNotBlank()) request.addOption("-f", audioQualityId)
|
||||
request.addOption("-x")
|
||||
|
||||
if(ext != "webm"){
|
||||
val codec = when(downloadItem.format.container){
|
||||
"aac" -> "aac"
|
||||
"mp3" -> "libmp3lame"
|
||||
"flac" -> "flac"
|
||||
"opus" -> "libopus"
|
||||
else -> ""
|
||||
}
|
||||
Log.e("aa", codec)
|
||||
if (codec.isEmpty()){
|
||||
request.addOption("-x")
|
||||
}else{
|
||||
request.addOption("--remux-video", ext)
|
||||
request.addOption("--ppa", "VideoRemuxer:-vn -c:a $codec")
|
||||
if(ext.isNotBlank()){
|
||||
if(!ext.matches("(webm)|(Default)|(${context.getString(R.string.defaultValue)})".toRegex())){
|
||||
request.addOption("--audio-format", downloadItem.format.container)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
request.addOption("--embed-metadata")
|
||||
|
||||
if (downloadItem.audioPreferences.embedThumb) {
|
||||
request.addOption("--embed-thumbnail")
|
||||
request.addOption("--convert-thumbnails", "jpg")
|
||||
try {
|
||||
val config = File(context.cacheDir.absolutePath + "/downloads/config" + downloadItem.title + "##" + downloadItem.format.format_id + ".txt")
|
||||
val config = File(context.cacheDir.absolutePath + "/downloads/${downloadItem.id}/config" + downloadItem.title + "##" + downloadItem.format.format_id + ".txt")
|
||||
val configData = "--ppa \"ffmpeg: -c:v mjpeg -vf crop=\\\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\\\"\""
|
||||
config.writeText(configData)
|
||||
request.addOption("--ppa", "ThumbnailsConvertor:-qmin 1 -q:v 1")
|
||||
|
|
@ -326,8 +322,8 @@ class DownloadWorker(
|
|||
setProgressAsync(workDataOf("progress" to 100, "output" to "Moving file to ${fileUtil.formatPath(downloadLocation)}", "id" to downloadItem.id, "log" to logDownloads))
|
||||
var finalPath : String?
|
||||
try {
|
||||
finalPath = moveFile(tempFileDir.absoluteFile, downloadLocation){ progress ->
|
||||
setProgressAsync(workDataOf("progress" to progress, "output" to "Moving file to ${fileUtil.formatPath(downloadLocation)}", "id" to downloadItem.id, "log" to logDownloads))
|
||||
finalPath = fileUtil.moveFile(tempFileDir.absoluteFile,context, downloadLocation, keepCache){ p ->
|
||||
setProgressAsync(workDataOf("progress" to p, "output" to "Moving file to ${fileUtil.formatPath(downloadLocation)}", "id" to downloadItem.id, "log" to logDownloads))
|
||||
}
|
||||
setProgressAsync(workDataOf("progress" to 100, "output" to "Moved file to $finalPath", "id" to downloadItem.id, "log" to logDownloads))
|
||||
}catch (e: Exception){
|
||||
|
|
@ -343,7 +339,7 @@ class DownloadWorker(
|
|||
val unixtime = System.currentTimeMillis() / 1000
|
||||
val file = File(finalPath!!)
|
||||
downloadItem.format.filesize = if (file.exists()) file.length() else 0L
|
||||
val historyItem = HistoryItem(0, downloadItem.url, downloadItem.title, downloadItem.author, downloadItem.duration, downloadItem.thumb, downloadItem.type, unixtime, finalPath, downloadItem.website, downloadItem.format)
|
||||
val historyItem = HistoryItem(0, downloadItem.url, downloadItem.title, downloadItem.author, downloadItem.duration, downloadItem.thumb, downloadItem.type, unixtime, finalPath, downloadItem.website, downloadItem.format, downloadItem.id)
|
||||
runBlocking {
|
||||
historyDao.insert(historyItem)
|
||||
}
|
||||
|
|
@ -418,14 +414,6 @@ class DownloadWorker(
|
|||
super.onStopped()
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
private fun moveFile(originDir: File, downLocation: String, progress: (progress: Int) -> Unit) : String{
|
||||
val fileUtil = FileUtil()
|
||||
val path = fileUtil.moveFile(originDir, context, downLocation){ p ->
|
||||
progress(p)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
companion object {
|
||||
var itemId: Long = 0
|
||||
|
|
|
|||
|
|
@ -93,20 +93,18 @@ class TerminalDownloadWorker(
|
|||
}
|
||||
}.onSuccess {
|
||||
//move file from internal to set download directory
|
||||
var finalPath : String?
|
||||
try {
|
||||
finalPath = moveFile(tempFileDir.absoluteFile, downloadLocation!!){ progress ->
|
||||
setProgressAsync(workDataOf("progress" to progress))
|
||||
fileUtil.moveFile(tempFileDir.absoluteFile,context, downloadLocation!!, false){ p ->
|
||||
setProgressAsync(workDataOf("progress" to p))
|
||||
}
|
||||
}catch (e: Exception){
|
||||
finalPath = context.getString(R.string.unfound_file)
|
||||
e.printStackTrace()
|
||||
handler.postDelayed({
|
||||
Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show()
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
if (it.out.length > 500){
|
||||
if (it.out.length > 200){
|
||||
outputFile.appendText("${it.out}\n")
|
||||
if (logDownloads && logFile.exists()){
|
||||
logFile.appendText("${it.out}\n")
|
||||
|
|
@ -138,15 +136,6 @@ class TerminalDownloadWorker(
|
|||
super.onStopped()
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
private fun moveFile(originDir: File, downLocation: String, progress: (progress: Int) -> Unit) : String{
|
||||
val fileUtil = FileUtil()
|
||||
val path = fileUtil.moveFile(originDir, context, downLocation){ p ->
|
||||
progress(p)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "DownloadWorker"
|
||||
}
|
||||
|
|
|
|||
5
app/src/main/res/drawable/baseline_save_24.xml
Normal file
5
app/src/main/res/drawable/baseline_save_24.xml
Normal file
|
|
@ -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="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z"/>
|
||||
</vector>
|
||||
|
|
@ -251,4 +251,6 @@
|
|||
<string name="pause">Pause\n</string>
|
||||
<string name="resume">Resume</string>
|
||||
<string name="updating_download_data">Updating Download Item Data</string>
|
||||
<string name="keep_cache">Keep Cache</string>
|
||||
<string name="keep_cache_summary">Don\'t delete temporary files after the download is finished</string>
|
||||
</resources>
|
||||
|
|
@ -72,6 +72,14 @@
|
|||
android:summary="@string/clear_temporary_files_summary"
|
||||
app:title="@string/clear_temporary_files" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:widgetLayout="@layout/preferece_material_switch"
|
||||
app:defaultValue="false"
|
||||
android:icon="@drawable/baseline_save_24"
|
||||
android:key="keep_cache"
|
||||
app:summary="@string/keep_cache_summary"
|
||||
app:title="@string/keep_cache" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/downloading">
|
||||
|
|
|
|||
Loading…
Reference in a new issue