made downloads write logs based on user preference
This commit is contained in:
parent
ee4d422bf0
commit
1328e77711
8 changed files with 44 additions and 10 deletions
|
|
@ -317,6 +317,7 @@ class HomeFragment : Fragment(), HomeAdapter.OnItemClickListener, View.OnClickLi
|
|||
} catch (ignored: Exception) {}
|
||||
} else if (itemId == R.id.delete_search){
|
||||
resultViewModel.deleteAllSearchQueryHistory()
|
||||
searchSuggestionsLinearLayout!!.removeAllViews()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
private var concurrentDownloads: SeekBarPreference? = null
|
||||
private var limitRate: EditTextPreference? = null
|
||||
private var aria2: SwitchPreferenceCompat? = null
|
||||
private var logDownloads: SwitchPreferenceCompat? = null
|
||||
private var sponsorblockFilters: MultiSelectListPreference? = null
|
||||
private var filenameTemplate: EditTextPreference? = null
|
||||
private var mtime: SwitchPreferenceCompat? = null
|
||||
|
|
@ -69,6 +70,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
concurrentDownloads = findPreference("concurrent_downloads")
|
||||
limitRate = findPreference("limit_rate")
|
||||
aria2 = findPreference("aria2")
|
||||
logDownloads = findPreference("log_downloads")
|
||||
sponsorblockFilters = findPreference("sponsorblock_filter")
|
||||
mtime = findPreference("mtime")
|
||||
embedSubtitles = findPreference("embed_subtitles")
|
||||
|
|
@ -115,6 +117,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
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("mtime", mtime!!.isChecked)
|
||||
|
|
@ -223,6 +226,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
editor.apply()
|
||||
true
|
||||
}
|
||||
logDownloads!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
val enable = newValue as Boolean
|
||||
editor.putBoolean("log_downloads", enable)
|
||||
editor.apply()
|
||||
true
|
||||
}
|
||||
sponsorblockFilters!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any? ->
|
||||
sponsorblockFilters!!.values = newValue as Set<String?>?
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import com.deniscerri.ytdlnis.database.models.Format
|
|||
|
||||
class UiUtil(private val fileUtil: FileUtil) {
|
||||
fun populateFormatCard(formatCard : ConstraintLayout, chosenFormat: Format){
|
||||
Log.e("aa", chosenFormat.toString())
|
||||
formatCard.findViewById<TextView>(R.id.container).text = chosenFormat.container.uppercase()
|
||||
formatCard.findViewById<TextView>(R.id.format_note).text = chosenFormat.format_note.uppercase()
|
||||
formatCard.findViewById<TextView>(R.id.format_id).text = "id: ${chosenFormat.format_id}"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import androidx.work.ForegroundInfo
|
|||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import androidx.work.workDataOf
|
||||
import com.deniscerri.ytdlnis.App
|
||||
import com.deniscerri.ytdlnis.MainActivity
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.database.DBManager
|
||||
|
|
@ -67,13 +66,13 @@ class DownloadWorker(
|
|||
|
||||
|
||||
val url = downloadItem.url
|
||||
var request = YoutubeDLRequest(url)
|
||||
val request = YoutubeDLRequest(url)
|
||||
val type = downloadItem.type
|
||||
val downloadLocation = downloadItem.downloadPath
|
||||
|
||||
var tempFolder = StringBuilder(context.cacheDir.absolutePath + """/${downloadItem.title}##${downloadItem.type}""")
|
||||
val tempFolder = StringBuilder(context.cacheDir.absolutePath + """/${downloadItem.title}##${downloadItem.type}""")
|
||||
tempFolder.append("##${downloadItem.format.format_id}")
|
||||
var tempFileDir = File(tempFolder.toString())
|
||||
val tempFileDir = File(tempFolder.toString())
|
||||
tempFileDir.delete()
|
||||
tempFileDir.mkdir()
|
||||
|
||||
|
|
@ -104,10 +103,10 @@ class DownloadWorker(
|
|||
}
|
||||
|
||||
if(downloadItem.title.isNotEmpty()){
|
||||
request.addCommands(listOf("--replace-in-metadata","title",".*.",downloadItem.title));
|
||||
request.addCommands(listOf("--replace-in-metadata","title",".*.",downloadItem.title))
|
||||
}
|
||||
if (downloadItem.author.isNotEmpty()){
|
||||
request.addCommands(listOf("--replace-in-metadata","uploader",".*.",downloadItem.author));
|
||||
request.addCommands(listOf("--replace-in-metadata","uploader",".*.",downloadItem.author))
|
||||
}
|
||||
if (downloadItem.customFileNameTemplate.isEmpty()) downloadItem.customFileNameTemplate = "%(uploader)s - %(title)s"
|
||||
|
||||
|
|
@ -166,7 +165,7 @@ class DownloadWorker(
|
|||
if (videoFormatID == "Best Quality") videoFormatID = "bestvideo"
|
||||
else if (videoFormatID == "Worst Quality") videoFormatID = "worst"
|
||||
else if (defaultFormats.contains(videoFormatID)) videoFormatID = "bestvideo[height<="+videoFormatID.substring(0, videoFormatID.length -1)+"]"
|
||||
formatArgument = videoFormatID + "+bestaudio/best/$videoFormatID"
|
||||
formatArgument = "$videoFormatID+bestaudio/best/$videoFormatID"
|
||||
}
|
||||
Log.e(TAG, formatArgument)
|
||||
request.addOption("-f", formatArgument)
|
||||
|
|
@ -198,6 +197,19 @@ class DownloadWorker(
|
|||
}
|
||||
|
||||
runCatching {
|
||||
val logDownloads = sharedPreferences.getBoolean("log_downloads", false)
|
||||
val logFolder = File(context.filesDir.absolutePath + "/logs")
|
||||
val logFile = File(context.filesDir.absolutePath + """/logs/${downloadItem.id} - ${downloadItem.title}##${downloadItem.type}##${downloadItem.format.format_id}.log""")
|
||||
if (logDownloads){
|
||||
logFolder.mkdir()
|
||||
logFile.createNewFile()
|
||||
logFile.writeText("Downloading:\n" +
|
||||
"URL: ${downloadItem.url}\n" +
|
||||
"Type: ${downloadItem.type}\n" +
|
||||
"Format: ${downloadItem.format}\n\n")
|
||||
}
|
||||
|
||||
|
||||
YoutubeDL.getInstance().execute(request, downloadItem.id.toString()){ progress, _, line ->
|
||||
setProgressAsync(workDataOf("progress" to progress.toInt()))
|
||||
setProgressAsync(workDataOf("output" to line))
|
||||
|
|
@ -207,6 +219,9 @@ class DownloadWorker(
|
|||
line, progress.toInt(), 0, title,
|
||||
NotificationUtil.DOWNLOAD_SERVICE_CHANNEL_ID
|
||||
)
|
||||
if (logDownloads){
|
||||
logFile.appendText("${line}\n")
|
||||
}
|
||||
}
|
||||
}.onSuccess {
|
||||
//move file from internal to set download directory
|
||||
|
|
|
|||
|
|
@ -1,5 +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:textColorPrimary" android:pathData="M11.8,10.9c-2.27,-0.59 -3,-1.2 -3,-2.15 0,-1.09 1.01,-1.85 2.7,-1.85 1.78,0 2.44,0.85 2.5,2.1h2.21c-0.07,-1.72 -1.12,-3.3 -3.21,-3.81V3h-3v2.16c-1.94,0.42 -3.5,1.68 -3.5,3.61 0,2.31 1.91,3.46 4.7,4.13 2.5,0.6 3,1.48 3,2.41 0,0.69 -0.49,1.79 -2.7,1.79 -2.06,0 -2.87,-0.92 -2.98,-2.1h-2.2c0.12,2.19 1.76,3.42 3.68,3.83V21h3v-2.15c1.95,-0.37 3.5,-1.5 3.5,-3.55 0,-2.84 -2.43,-3.81 -4.7,-4.4z"/>
|
||||
<path android:fillColor="?android:colorAccent" android:pathData="M11.8,10.9c-2.27,-0.59 -3,-1.2 -3,-2.15 0,-1.09 1.01,-1.85 2.7,-1.85 1.78,0 2.44,0.85 2.5,2.1h2.21c-0.07,-1.72 -1.12,-3.3 -3.21,-3.81V3h-3v2.16c-1.94,0.42 -3.5,1.68 -3.5,3.61 0,2.31 1.91,3.46 4.7,4.13 2.5,0.6 3,1.48 3,2.41 0,0.69 -0.49,1.79 -2.7,1.79 -2.06,0 -2.87,-0.92 -2.98,-2.1h-2.2c0.12,2.19 1.76,3.42 3.68,3.83V21h3v-2.15c1.95,-0.37 3.5,-1.5 3.5,-3.55 0,-2.84 -2.43,-3.81 -4.7,-4.4z"/>
|
||||
</vector>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
android:id="@+id/downloads_relative_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintDimensionRatio="H,8:1"
|
||||
app:layout_constraintDimensionRatio="H,6:1"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
|
|
|||
|
|
@ -178,4 +178,6 @@
|
|||
<string name="enable_mtime_summary">Set the HTTP Last-Modified header as last modified time</string>
|
||||
<string name="update_formats">Update Formats</string>
|
||||
<string name="error_updating_formats">Error updating formats!</string>
|
||||
<string name="log_downloads">Log Downloads</string>
|
||||
<string name="log_downloads_summary">Create a log file for each download</string>
|
||||
</resources>
|
||||
|
|
@ -88,6 +88,13 @@
|
|||
android:disableDependentsState="true"
|
||||
app:title="Aria2" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
android:icon="@drawable/ic_baseline_file_open_24"
|
||||
android:key="log_downloads"
|
||||
app:summary="@string/log_downloads_summary"
|
||||
app:title="@string/log_downloads" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue