implemented format inside objects instead of a separate table
This commit is contained in:
parent
ff58bd2dbf
commit
9e5f0e5fab
25 changed files with 186 additions and 261 deletions
|
|
@ -24,7 +24,7 @@ android {
|
|||
defaultConfig {
|
||||
applicationId "com.deniscerri.ytdl"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 29
|
||||
targetSdkVersion 33
|
||||
versionCode project.versionCode
|
||||
versionName project.versionName
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
|
@ -103,7 +103,7 @@ dependencies {
|
|||
implementation 'androidx.navigation:navigation-fragment:2.5.3'
|
||||
implementation 'androidx.navigation:navigation-ui:2.5.3'
|
||||
implementation 'androidx.core:core-ktx:1.9.0'
|
||||
implementation 'androidx.core:core-ktx:+'
|
||||
implementation 'androidx.core:core-ktx:1.9.0'
|
||||
testImplementation "junit:junit:$junitVer"
|
||||
androidTestImplementation "androidx.test.ext:junit:$androidJunitVer"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVer"
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 1,
|
||||
"identityHash": "db5c9df3e43ddd5a5131bbd372a7c92b",
|
||||
"identityHash": "eddd8d0408b9e321c902948a418e6c92",
|
||||
"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, `creationTime` INTEGER NOT NULL)",
|
||||
"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",
|
||||
|
|
@ -56,6 +56,12 @@
|
|||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "formats",
|
||||
"columnName": "formats",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "creationTime",
|
||||
"columnName": "creationTime",
|
||||
|
|
@ -72,59 +78,9 @@
|
|||
"indices": [],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "formats",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `itemId` INTEGER NOT NULL, `format_id` TEXT NOT NULL, `container` TEXT NOT NULL, `filesize` INTEGER NOT NULL, `format_note` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "itemId",
|
||||
"columnName": "itemId",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "format_id",
|
||||
"columnName": "format_id",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "container",
|
||||
"columnName": "container",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "filesize",
|
||||
"columnName": "filesize",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "format_note",
|
||||
"columnName": "format_note",
|
||||
"affinity": "TEXT",
|
||||
"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)",
|
||||
"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",
|
||||
|
|
@ -185,6 +141,12 @@
|
|||
"columnName": "website",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "format",
|
||||
"columnName": "format",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
|
|
@ -198,7 +160,7 @@
|
|||
},
|
||||
{
|
||||
"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, `audioFormatId` TEXT NOT NULL, `videoFormatId` TEXT NOT NULL, `customTemplateId` INTEGER NOT NULL, `formatDesc` TEXT NOT NULL, `removeAudio` INTEGER NOT NULL DEFAULT 0, `downloadPath` TEXT NOT NULL, `website` TEXT NOT NULL, `downloadSize` TEXT NOT NULL, `playlistTitle` TEXT NOT NULL, `embedSubs` INTEGER NOT NULL, `addChapters` INTEGER NOT NULL, `SaveThumb` INTEGER NOT NULL, `ext` TEXT NOT NULL, `filesize` TEXT NOT NULL, `status` TEXT NOT NULL DEFAULT 'Queued', `workID` INTEGER NOT NULL)",
|
||||
"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, `removeAudio` INTEGER NOT NULL DEFAULT 0, `downloadPath` TEXT NOT NULL, `website` TEXT NOT NULL, `downloadSize` TEXT NOT NULL, `playlistTitle` TEXT NOT NULL, `embedSubs` INTEGER NOT NULL, `addChapters` INTEGER NOT NULL, `SaveThumb` INTEGER NOT NULL, `ext` TEXT NOT NULL, `filesize` TEXT NOT NULL, `status` TEXT NOT NULL DEFAULT 'Queued', `workID` INTEGER NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
|
|
@ -243,26 +205,8 @@
|
|||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "audioFormatId",
|
||||
"columnName": "audioFormatId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "videoFormatId",
|
||||
"columnName": "videoFormatId",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "customTemplateId",
|
||||
"columnName": "customTemplateId",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "formatDesc",
|
||||
"columnName": "formatDesc",
|
||||
"fieldPath": "format",
|
||||
"columnName": "format",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
|
|
@ -386,7 +330,7 @@
|
|||
"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, 'db5c9df3e43ddd5a5131bbd372a7c92b')"
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'eddd8d0408b9e321c902948a418e6c92')"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,8 @@
|
|||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="androidd.permission.MANAGE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.ACTION_OPEN_DOCUMENT" />
|
||||
|
|
@ -21,7 +22,9 @@
|
|||
android:supportsRtl="true"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:targetApi="tiramisu">
|
||||
tools:targetApi="tiramisu"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
tools:ignore="DataExtractionRules">
|
||||
<activity android:name=".MainActivity"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:exported="true">
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import android.content.DialogInterface
|
|||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Build.VERSION_CODES
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
|
|
@ -272,12 +274,18 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun askPermissions() {
|
||||
if (!checkFilePermission()) {
|
||||
if (Build.VERSION.SDK_INT < VERSION_CODES.TIRAMISU && !checkFilePermission()) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
|
||||
1
|
||||
)
|
||||
}else{
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
|
||||
1
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package com.deniscerri.ytdlnis.database
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import java.lang.reflect.Type
|
||||
|
||||
|
||||
class Converters {
|
||||
@TypeConverter
|
||||
fun stringToListOfFormats(value: String?): ArrayList<Format> {
|
||||
val listType: Type = object : TypeToken<ArrayList<Format?>?>() {}.type
|
||||
return Gson().fromJson(value, listType)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun listOfFormatsToString(list: ArrayList<Format?>?): String {
|
||||
val gson = Gson()
|
||||
return gson.toJson(list)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun formatToString(format: Format): String = Gson().toJson(format)
|
||||
|
||||
@TypeConverter
|
||||
fun stringToFormat(string: String): Format = Gson().fromJson(string, Format::class.java)
|
||||
|
||||
}
|
||||
|
|
@ -4,18 +4,19 @@ import android.content.Context
|
|||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.deniscerri.ytdlnis.database.dao.*
|
||||
import com.deniscerri.ytdlnis.database.models.*
|
||||
|
||||
@TypeConverters(Converters::class)
|
||||
@Database(
|
||||
entities = [ResultItem::class, Format::class, HistoryItem::class, DownloadItem::class, CommandTemplate::class],
|
||||
entities = [ResultItem::class, HistoryItem::class, DownloadItem::class, CommandTemplate::class],
|
||||
version = 1,
|
||||
autoMigrations = []
|
||||
)
|
||||
abstract class DBManager : RoomDatabase(){
|
||||
abstract val resultDao : ResultDao
|
||||
abstract val historyDao : HistoryDao
|
||||
abstract val formatDao : FormatDao
|
||||
abstract val downloadDao : DownloadDao
|
||||
abstract val commandTemplateDao : CommandTemplateDao
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
package com.deniscerri.ytdlnis.database.dao
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.*
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
|
||||
@Dao
|
||||
interface FormatDao {
|
||||
@Query("SELECT * FROM formats WHERE itemId=:itemId")
|
||||
fun getFormatsByItemId(itemId: Long) : List<Format>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insert(item: Format)
|
||||
|
||||
@Update(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun update(item: Format)
|
||||
|
||||
@Query("DELETE FROM formats")
|
||||
suspend fun deleteAll()
|
||||
|
||||
@Query("DELETE FROM formats WHERE itemId=:itemId")
|
||||
suspend fun deleteFromatsByItemId(itemId: Long)
|
||||
|
||||
}
|
||||
|
|
@ -14,10 +14,7 @@ data class DownloadItem(
|
|||
val thumb: String,
|
||||
val duration: String,
|
||||
var type: String,
|
||||
var audioFormatId: String,
|
||||
var videoFormatId: String,
|
||||
var customTemplateId: Long,
|
||||
var formatDesc: String,
|
||||
var format: Format,
|
||||
@ColumnInfo(defaultValue = "0")
|
||||
val removeAudio: Boolean,
|
||||
var downloadPath: String,
|
||||
|
|
|
|||
|
|
@ -1,20 +1,14 @@
|
|||
package com.deniscerri.ytdlnis.database.models
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
@Entity(tableName = "formats")
|
||||
data class Format(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = -1,
|
||||
var itemId: Long = 0,
|
||||
@SerializedName(value = "format_id", alternate = ["itag"])
|
||||
val format_id: String = "",
|
||||
var format_id: String = "",
|
||||
@SerializedName(value = "ext", alternate = ["container"])
|
||||
val container: String = "",
|
||||
@SerializedName(value = "filesize", alternate = ["clen", "filesize_approx"])
|
||||
val filesize: Long = 0,
|
||||
@SerializedName(value = "format_note", alternate = ["resolution", "audioQuality"])
|
||||
val format_note: String = ""
|
||||
var format_note: String = ""
|
||||
)
|
||||
|
|
@ -15,5 +15,6 @@ data class HistoryItem(
|
|||
val type: String,
|
||||
val time: Long,
|
||||
val downloadPath: String,
|
||||
val website: String
|
||||
val website: String,
|
||||
val format: Format
|
||||
)
|
||||
|
|
@ -2,6 +2,8 @@ package com.deniscerri.ytdlnis.database.models
|
|||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.TypeConverters
|
||||
import com.deniscerri.ytdlnis.database.Converters
|
||||
import java.util.*
|
||||
|
||||
@Entity(tableName = "results")
|
||||
|
|
@ -15,5 +17,6 @@ data class ResultItem(
|
|||
val thumb: String,
|
||||
val website: String,
|
||||
var playlistTitle: String,
|
||||
val formats: ArrayList<Format>,
|
||||
var creationTime: Long = System.currentTimeMillis() / 1000,
|
||||
)
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
package com.deniscerri.ytdlnis.database.models
|
||||
|
||||
data class ResultItemWithFormats(
|
||||
val resultItem: ResultItem,
|
||||
var formats: ArrayList<Format>
|
||||
)
|
||||
|
|
@ -1,12 +1,8 @@
|
|||
package com.deniscerri.ytdlnis.database.repository
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.deniscerri.ytdlnis.database.dao.DownloadDao
|
||||
import com.deniscerri.ytdlnis.database.dao.FormatDao
|
||||
import com.deniscerri.ytdlnis.database.models.DownloadItem
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
|
||||
class DownloadRepository(private val downloadDao: DownloadDao) {
|
||||
val allDownloads : LiveData<List<DownloadItem>> = downloadDao.getAllDownloads()
|
||||
|
|
|
|||
|
|
@ -4,14 +4,13 @@ import android.content.Context
|
|||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.deniscerri.ytdlnis.database.dao.CommandTemplateDao
|
||||
import com.deniscerri.ytdlnis.database.dao.FormatDao
|
||||
import com.deniscerri.ytdlnis.database.dao.ResultDao
|
||||
import com.deniscerri.ytdlnis.database.models.CommandTemplate
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
import com.deniscerri.ytdlnis.util.InfoUtil
|
||||
|
||||
class ResultRepository(private val resultDao: ResultDao, private val formatDao: FormatDao, private val commandTemplateDao: CommandTemplateDao, private val context: Context) {
|
||||
class ResultRepository(private val resultDao: ResultDao, private val commandTemplateDao: CommandTemplateDao, private val context: Context) {
|
||||
private val tag: String = "ResultRepository"
|
||||
val allResults : LiveData<List<ResultItem>> = resultDao.getResults()
|
||||
|
||||
|
|
@ -28,8 +27,7 @@ class ResultRepository(private val resultDao: ResultDao, private val formatDao:
|
|||
val infoUtil = InfoUtil(context)
|
||||
val items = infoUtil.getTrending(context)
|
||||
for (i in items){
|
||||
val id = resultDao.insert(i!!.resultItem)
|
||||
addFormats(i.formats,id)
|
||||
resultDao.insert(i!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,8 +37,7 @@ class ResultRepository(private val resultDao: ResultDao, private val formatDao:
|
|||
if (resetResults) deleteAll()
|
||||
val res = infoUtil.search(inputQuery)
|
||||
res.forEach {
|
||||
val id = resultDao.insert(it!!.resultItem)
|
||||
addFormats(it.formats,id)
|
||||
resultDao.insert(it!!)
|
||||
}
|
||||
}catch (ignored: Exception){}
|
||||
}
|
||||
|
|
@ -63,8 +60,7 @@ class ResultRepository(private val resultDao: ResultDao, private val formatDao:
|
|||
try {
|
||||
val v = infoUtil.getVideo(query!!)
|
||||
if (resetResults) deleteAll()
|
||||
val id = resultDao.insert(v!!.resultItem)
|
||||
addFormats(v.formats,id)
|
||||
resultDao.insert(v!!)
|
||||
} catch (e: Exception) {
|
||||
Log.e(tag, e.toString())
|
||||
}
|
||||
|
|
@ -81,8 +77,7 @@ class ResultRepository(private val resultDao: ResultDao, private val formatDao:
|
|||
val tmpVids = tmp.videos
|
||||
val tmpToken = tmp.nextPageToken
|
||||
tmpVids.forEach {
|
||||
val id = resultDao.insert(it!!.resultItem)
|
||||
addFormats(it.formats,id)
|
||||
resultDao.insert(it!!)
|
||||
}
|
||||
if (tmpToken.isEmpty()) break
|
||||
if (tmpToken == nextPageToken) break
|
||||
|
|
@ -96,35 +91,22 @@ class ResultRepository(private val resultDao: ResultDao, private val formatDao:
|
|||
if (resetResults) deleteAll()
|
||||
val items = infoUtil.getFromYTDL(inputQuery)
|
||||
items.forEach {
|
||||
val id = resultDao.insert(it!!.resultItem)
|
||||
addFormats(it.formats,id)
|
||||
resultDao.insert(it!!)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(tag, e.toString())
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun addFormats(formats : ArrayList<Format>, id: Long){
|
||||
formats.forEach { f ->
|
||||
if (f.filesize == 0L) return@forEach
|
||||
f.itemId = id
|
||||
formatDao.insert(f)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteAll(){
|
||||
resultDao.deleteAll()
|
||||
formatDao.deleteAll()
|
||||
}
|
||||
|
||||
suspend fun update(item: ResultItem){
|
||||
resultDao.update(item)
|
||||
}
|
||||
|
||||
fun getFormats(item: ResultItem): List<Format> {
|
||||
return formatDao.getFormatsByItemId(item.id)
|
||||
}
|
||||
|
||||
fun getTemplates() : List<CommandTemplate> {
|
||||
return commandTemplateDao.getAllTemplates()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
|
|||
|
||||
init {
|
||||
val dao = DBManager.getInstance(application).downloadDao
|
||||
val formatDao = DBManager.getInstance(application).formatDao
|
||||
repository = DownloadRepository(dao)
|
||||
allDownloads = repository.allDownloads
|
||||
queuedDownloads = repository.queuedDownloads
|
||||
|
|
@ -74,7 +73,7 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
|
|||
resultItem.thumb,
|
||||
resultItem.duration,
|
||||
type,
|
||||
"", "", 0, "", false,
|
||||
Format(), false,
|
||||
"", resultItem.website, "", resultItem.playlistTitle, embedSubs, addChapters, saveThumb, "",
|
||||
"", DownloadRepository.status.Processing.toString(), 0
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,21 +1,16 @@
|
|||
package com.deniscerri.ytdlnis.database.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.*
|
||||
import com.deniscerri.ytdlnis.App
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.database.DBManager
|
||||
import com.deniscerri.ytdlnis.database.dao.FormatDao
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
import com.deniscerri.ytdlnis.database.repository.DownloadRepository
|
||||
import com.deniscerri.ytdlnis.database.repository.ResultRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
class ResultViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private val tag: String = "ResultViewModel"
|
||||
|
|
@ -25,9 +20,8 @@ class ResultViewModel(application: Application) : AndroidViewModel(application)
|
|||
|
||||
init {
|
||||
val dao = DBManager.getInstance(application).resultDao
|
||||
val formatDao = DBManager.getInstance(application).formatDao
|
||||
val commandDao = DBManager.getInstance(application).commandTemplateDao
|
||||
repository = ResultRepository(dao, formatDao, commandDao, getApplication<Application>().applicationContext)
|
||||
repository = ResultRepository(dao, commandDao, getApplication<Application>().applicationContext)
|
||||
items = repository.allResults
|
||||
loadingItems.postValue(false)
|
||||
}
|
||||
|
|
@ -99,32 +93,7 @@ class ResultViewModel(application: Application) : AndroidViewModel(application)
|
|||
repository.update(item);
|
||||
}
|
||||
|
||||
fun getFormats(item: ResultItem, type: String) : List<Format> {
|
||||
var list = repository.getFormats(item)
|
||||
val formats = mutableListOf<Format>()
|
||||
val audioFormats = getApplication<App>().resources.getStringArray(R.array.audio_formats)
|
||||
val videoFormats = getApplication<App>().resources.getStringArray(R.array.video_formats)
|
||||
|
||||
when(type){
|
||||
"audio" -> {
|
||||
return list.filter { it.format_note.contains("audio", ignoreCase = true) }
|
||||
}
|
||||
"video" -> {
|
||||
list = list.filter { !it.format_note.contains("audio", ignoreCase = true) }
|
||||
if (list.isEmpty()) {
|
||||
videoFormats.forEach { formats.add(Format(0, item.id, it, "", 0, it)) }
|
||||
return formats
|
||||
}
|
||||
return list
|
||||
}
|
||||
}
|
||||
|
||||
val templates = repository.getTemplates()
|
||||
templates.forEach {
|
||||
formats.add(Format(0, item.id, it.title, "", 0, it.content))
|
||||
}
|
||||
return formats
|
||||
}
|
||||
|
||||
fun getItemByURL(url: String) : ResultItem {
|
||||
return repository.getItemByURL(url)
|
||||
|
|
|
|||
|
|
@ -22,11 +22,8 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.deniscerri.ytdlnis.MainActivity
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.adapter.HomeAdapter
|
||||
import com.deniscerri.ytdlnis.database.models.DownloadItem
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItemWithFormats
|
||||
import com.deniscerri.ytdlnis.database.repository.DownloadRepository
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.ResultViewModel
|
||||
import com.deniscerri.ytdlnis.databinding.FragmentHomeBinding
|
||||
|
|
@ -42,7 +39,6 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
|
|||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.chip.ChipGroup
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
|
@ -147,7 +143,7 @@ class HomeFragment : Fragment(), HomeAdapter.OnItemClickListener, View.OnClickLi
|
|||
}else{
|
||||
downloadAllFabCoordinator!!.visibility = GONE
|
||||
}
|
||||
}else if(it.size == 1 && !firstBoot && parentFragmentManager.findFragmentByTag("bottomSheet") == null){
|
||||
}else if(it.size == 1 && !firstBoot && parentFragmentManager.findFragmentByTag("downloadSingleSheet") == null){
|
||||
showSingleDownloadSheet(it[0], "audio")
|
||||
}
|
||||
firstBoot = false
|
||||
|
|
@ -360,11 +356,7 @@ class HomeFragment : Fragment(), HomeAdapter.OnItemClickListener, View.OnClickLi
|
|||
}
|
||||
|
||||
private fun showSingleDownloadSheet(resultItem : ResultItem, type: String){
|
||||
val item = ResultItemWithFormats(
|
||||
resultItem,
|
||||
resultViewModel.getFormats(resultItem, "video") as ArrayList<Format>
|
||||
)
|
||||
val downloadItem = downloadViewModel.createDownloadItemFromResult(resultItem, "video")
|
||||
val downloadItem = downloadViewModel.createDownloadItemFromResult(resultItem, type)
|
||||
downloadViewModel.insertDownload(downloadItem).observe(viewLifecycleOwner) {
|
||||
downloadItem.id = it
|
||||
val bottomSheet = DownloadBottomSheetDialog(downloadItem)
|
||||
|
|
|
|||
|
|
@ -132,9 +132,7 @@ class DownloadAudioFragment(private val downloadItem: DownloadItem) : Fragment()
|
|||
audioPathResultLauncher.launch(intent)
|
||||
}
|
||||
|
||||
val formats = withContext(Dispatchers.IO){
|
||||
resultViewModel.getFormats(resultItem, type)
|
||||
}
|
||||
val formats = resultItem.formats.filter { it.format_note.contains("audio", ignoreCase = true) }
|
||||
val format = view.findViewById<TextInputLayout>(R.id.format)
|
||||
if (formats.isEmpty()) {
|
||||
format.visibility = View.GONE
|
||||
|
|
@ -166,8 +164,8 @@ class DownloadAudioFragment(private val downloadItem: DownloadItem) : Fragment()
|
|||
}
|
||||
(format!!.editText as AutoCompleteTextView?)!!.onItemClickListener =
|
||||
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, index: Int, _: Long ->
|
||||
downloadItem.formatDesc = formats[index].format_note
|
||||
downloadItem.audioFormatId = formats[index].format_id
|
||||
downloadItem.format.format_note = formats[index].format_note
|
||||
downloadItem.format.format_id = formats[index].format_id
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +182,7 @@ class DownloadAudioFragment(private val downloadItem: DownloadItem) : Fragment()
|
|||
containers
|
||||
)
|
||||
)
|
||||
val selectedContainer: String = formats.find { downloadItem.formatDesc == it.format_note }?.container
|
||||
val selectedContainer: String = formats.find { downloadItem.format.format_note == it.format_note }?.container
|
||||
?: sharedPreferences.getString("audio_format", "mp3")!!
|
||||
containerAutoCompleteTextView!!.setText(selectedContainer, false)
|
||||
(container!!.editText as AutoCompleteTextView?)!!.onItemClickListener =
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment
|
|||
import com.deniscerri.ytdlnis.MainActivity
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.database.models.DownloadItem
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.databinding.FragmentHomeBinding
|
||||
|
||||
class DownloadCommandFragment(item: DownloadItem) : Fragment() {
|
||||
|
|
@ -28,5 +29,12 @@ class DownloadCommandFragment(item: DownloadItem) : Fragment() {
|
|||
activity = getActivity()
|
||||
mainActivity = activity as MainActivity?
|
||||
return fragmentView
|
||||
|
||||
|
||||
//get formats
|
||||
// val templates = repository.getTemplates()
|
||||
// templates.forEach {
|
||||
// formats.add(Format(0, item.id, it.title, "", 0, it.content))
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
@ -13,9 +13,11 @@ import androidx.activity.result.contract.ActivityResultContracts
|
|||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.deniscerri.ytdlnis.App
|
||||
import com.deniscerri.ytdlnis.MainActivity
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.database.models.DownloadItem
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.DownloadViewModel
|
||||
import com.deniscerri.ytdlnis.database.viewmodel.ResultViewModel
|
||||
import com.deniscerri.ytdlnis.databinding.FragmentHomeBinding
|
||||
|
|
@ -132,8 +134,11 @@ class DownloadVideoFragment(private val downloadItem: DownloadItem) : Fragment()
|
|||
videoPathResultLauncher.launch(intent)
|
||||
}
|
||||
|
||||
val formats = withContext(Dispatchers.IO){
|
||||
resultViewModel.getFormats(resultItem, type)
|
||||
val formats = mutableListOf<Format>()
|
||||
formats.addAll(resultItem.formats.filter { !it.format_note.contains("audio", ignoreCase = true) })
|
||||
if (formats.isEmpty()) {
|
||||
val videoFormats = resources.getStringArray(R.array.video_formats)
|
||||
videoFormats.forEach { formats.add(Format(it, "", 0, it)) }
|
||||
}
|
||||
|
||||
val formatTitles = formats.map {
|
||||
|
|
@ -159,8 +164,8 @@ class DownloadVideoFragment(private val downloadItem: DownloadItem) : Fragment()
|
|||
}
|
||||
(format!!.editText as AutoCompleteTextView?)!!.onItemClickListener =
|
||||
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, index: Int, _: Long ->
|
||||
downloadItem.formatDesc = formats[index].format_note
|
||||
downloadItem.videoFormatId = formats[index].format_id
|
||||
downloadItem.format.format_note = formats[index].format_note
|
||||
downloadItem.format.format_id = formats[index].format_id
|
||||
}
|
||||
|
||||
val containers = requireContext().resources.getStringArray(R.array.video_containers)
|
||||
|
|
@ -177,7 +182,7 @@ class DownloadVideoFragment(private val downloadItem: DownloadItem) : Fragment()
|
|||
)
|
||||
)
|
||||
val selectedContainer: String =
|
||||
formats.find { downloadItem.formatDesc == it.format_note }?.container
|
||||
formats.find { downloadItem.format.format_note == it.format_note }?.container
|
||||
?: sharedPreferences.getString("video_format", "DEFAULT")!!
|
||||
containerAutoCompleteTextView!!.setText(selectedContainer, false)
|
||||
(container!!.editText as AutoCompleteTextView?)!!.onItemClickListener =
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import android.util.Log
|
|||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.database.models.Format
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItem
|
||||
import com.deniscerri.ytdlnis.database.models.ResultItemWithFormats
|
||||
import com.google.gson.Gson
|
||||
import com.yausername.youtubedl_android.YoutubeDL
|
||||
import com.yausername.youtubedl_android.YoutubeDLRequest
|
||||
|
|
@ -22,7 +21,7 @@ import java.util.*
|
|||
import kotlin.collections.ArrayList
|
||||
|
||||
class InfoUtil(context: Context) {
|
||||
private var items: ArrayList<ResultItemWithFormats?>
|
||||
private var items: ArrayList<ResultItem?>
|
||||
private var key: String? = null
|
||||
private var useInvidous = false
|
||||
|
||||
|
|
@ -53,7 +52,7 @@ class InfoUtil(context: Context) {
|
|||
}
|
||||
|
||||
@Throws(JSONException::class)
|
||||
fun search(query: String): ArrayList<ResultItemWithFormats?> {
|
||||
fun search(query: String): ArrayList<ResultItem?> {
|
||||
init()
|
||||
items = ArrayList()
|
||||
return if (key!!.isEmpty()) {
|
||||
|
|
@ -62,7 +61,7 @@ class InfoUtil(context: Context) {
|
|||
}
|
||||
|
||||
@Throws(JSONException::class)
|
||||
fun searchFromKey(query: String): ArrayList<ResultItemWithFormats?> {
|
||||
fun searchFromKey(query: String): ArrayList<ResultItem?> {
|
||||
//short data
|
||||
val res =
|
||||
genericRequest("https://youtube.googleapis.com/youtube/v3/search?part=snippet&q=$query&maxResults=25®ionCode=$countryCODE&key=$key")
|
||||
|
|
@ -101,7 +100,7 @@ class InfoUtil(context: Context) {
|
|||
snippet.put("duration", duration)
|
||||
fixThumbnail(snippet)
|
||||
val v = createVideofromJSON(snippet)
|
||||
if (v == null || v.resultItem.thumb.isEmpty()) {
|
||||
if (v == null || v.thumb.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
items.add(createVideofromJSON(snippet))
|
||||
|
|
@ -111,7 +110,7 @@ class InfoUtil(context: Context) {
|
|||
}
|
||||
|
||||
@Throws(JSONException::class)
|
||||
fun searchFromInvidous(query: String): ArrayList<ResultItemWithFormats?> {
|
||||
fun searchFromInvidous(query: String): ArrayList<ResultItem?> {
|
||||
val dataArray = genericArrayRequest(invidousURL + "search?q=" + query + "?type=video")
|
||||
if (dataArray.length() == 0) return getFromYTDL(query)
|
||||
for (i in 0 until dataArray.length()) {
|
||||
|
|
@ -127,7 +126,7 @@ class InfoUtil(context: Context) {
|
|||
element.getJSONArray("videoThumbnails").getJSONObject(0).getString("url")
|
||||
)
|
||||
val v = createVideofromInvidiousJSON(element)
|
||||
if (v == null || v.resultItem.thumb.isEmpty()) {
|
||||
if (v == null || v.thumb.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
items.add(v)
|
||||
|
|
@ -182,13 +181,13 @@ class InfoUtil(context: Context) {
|
|||
snippet.put("duration", duration)
|
||||
fixThumbnail(snippet)
|
||||
val v = createVideofromJSON(snippet)
|
||||
if (v == null || v.resultItem.thumb.isEmpty()) {
|
||||
if (v == null || v.thumb.isEmpty()) {
|
||||
i++
|
||||
continue
|
||||
} else {
|
||||
j++
|
||||
}
|
||||
v.resultItem.playlistTitle = "YTDLnis"
|
||||
v.playlistTitle = "YTDLnis"
|
||||
items.add(v)
|
||||
i++
|
||||
}
|
||||
|
|
@ -208,8 +207,8 @@ class InfoUtil(context: Context) {
|
|||
for (i in 0 until vids.length()) {
|
||||
val element = vids.getJSONObject(i)
|
||||
val v = createVideofromInvidiousJSON(element)
|
||||
if (v == null || v.resultItem.thumb.isEmpty()) continue
|
||||
v.resultItem.playlistTitle = res.getString("title")
|
||||
if (v == null || v.thumb.isEmpty()) continue
|
||||
v.playlistTitle = res.getString("title")
|
||||
items.add(v)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
|
@ -219,7 +218,7 @@ class InfoUtil(context: Context) {
|
|||
}
|
||||
|
||||
@Throws(JSONException::class)
|
||||
fun getVideo(id: String): ResultItemWithFormats? {
|
||||
fun getVideo(id: String): ResultItem? {
|
||||
init()
|
||||
if (key!!.isEmpty()) {
|
||||
return if (useInvidous) {
|
||||
|
|
@ -246,8 +245,8 @@ class InfoUtil(context: Context) {
|
|||
return createVideofromJSON(res)
|
||||
}
|
||||
|
||||
private fun createVideofromJSON(obj: JSONObject): ResultItemWithFormats? {
|
||||
var video: ResultItemWithFormats? = null
|
||||
private fun createVideofromJSON(obj: JSONObject): ResultItem? {
|
||||
var video: ResultItem? = null
|
||||
try {
|
||||
val id = obj.getString("videoID")
|
||||
val title = obj.getString("title").toString()
|
||||
|
|
@ -255,8 +254,7 @@ class InfoUtil(context: Context) {
|
|||
val duration = obj.getString("duration")
|
||||
val thumb = obj.getString("thumb")
|
||||
val url = "https://www.youtube.com/watch?v=$id"
|
||||
video = ResultItemWithFormats(
|
||||
ResultItem(0,
|
||||
video = ResultItem(0,
|
||||
url,
|
||||
title,
|
||||
author,
|
||||
|
|
@ -264,7 +262,6 @@ class InfoUtil(context: Context) {
|
|||
thumb,
|
||||
"youtube",
|
||||
"",
|
||||
),
|
||||
ArrayList()
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
|
|
@ -273,8 +270,8 @@ class InfoUtil(context: Context) {
|
|||
return video
|
||||
}
|
||||
|
||||
private fun createVideofromInvidiousJSON(obj: JSONObject): ResultItemWithFormats? {
|
||||
var video: ResultItemWithFormats? = null
|
||||
private fun createVideofromInvidiousJSON(obj: JSONObject): ResultItem? {
|
||||
var video: ResultItem? = null
|
||||
try {
|
||||
val id = obj.getString("videoId")
|
||||
val title = obj.getString("title").toString()
|
||||
|
|
@ -292,8 +289,7 @@ class InfoUtil(context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
video = ResultItemWithFormats(
|
||||
ResultItem(0,
|
||||
video = ResultItem(0,
|
||||
url,
|
||||
title,
|
||||
author,
|
||||
|
|
@ -301,9 +297,8 @@ class InfoUtil(context: Context) {
|
|||
thumb,
|
||||
"youtube",
|
||||
"",
|
||||
),
|
||||
formats
|
||||
)
|
||||
formats
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, e.toString())
|
||||
}
|
||||
|
|
@ -394,7 +389,7 @@ class InfoUtil(context: Context) {
|
|||
}
|
||||
|
||||
@Throws(JSONException::class)
|
||||
fun getTrending(context: Context): ArrayList<ResultItemWithFormats?> {
|
||||
fun getTrending(context: Context): ArrayList<ResultItem?> {
|
||||
init()
|
||||
items = ArrayList()
|
||||
return if (key!!.isEmpty()) {
|
||||
|
|
@ -403,7 +398,7 @@ class InfoUtil(context: Context) {
|
|||
}
|
||||
|
||||
@Throws(JSONException::class)
|
||||
fun getTrendingFromKey(context: Context): ArrayList<ResultItemWithFormats?> {
|
||||
fun getTrendingFromKey(context: Context): ArrayList<ResultItem?> {
|
||||
val url = "https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&videoCategoryId=10®ionCode=$countryCODE&maxResults=25&key=$key"
|
||||
//short data
|
||||
val res = genericRequest(url)
|
||||
|
|
@ -423,16 +418,16 @@ class InfoUtil(context: Context) {
|
|||
snippet.put("duration", duration)
|
||||
fixThumbnail(snippet)
|
||||
val v = createVideofromJSON(snippet)
|
||||
if (v == null || v.resultItem.thumb.isEmpty()) {
|
||||
if (v == null || v.thumb.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
v.resultItem.playlistTitle = context.getString(R.string.trendingPlaylist)
|
||||
v.playlistTitle = context.getString(R.string.trendingPlaylist)
|
||||
items.add(v)
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
private fun getTrendingFromInvidous(context: Context): ArrayList<ResultItemWithFormats?> {
|
||||
private fun getTrendingFromInvidous(context: Context): ArrayList<ResultItem?> {
|
||||
val url = invidousURL + "trending?type=music®ion=" + countryCODE
|
||||
val res = genericArrayRequest(url)
|
||||
try {
|
||||
|
|
@ -440,8 +435,8 @@ class InfoUtil(context: Context) {
|
|||
val element = res.getJSONObject(i)
|
||||
if (element.getString("type") != "video") continue
|
||||
val v = createVideofromInvidiousJSON(element)
|
||||
if (v == null || v.resultItem.thumb.isEmpty()) continue
|
||||
v.resultItem.playlistTitle = context.getString(R.string.trendingPlaylist)
|
||||
if (v == null || v.thumb.isEmpty()) continue
|
||||
v.playlistTitle = context.getString(R.string.trendingPlaylist)
|
||||
items.add(v)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
|
@ -450,7 +445,7 @@ class InfoUtil(context: Context) {
|
|||
return items
|
||||
}
|
||||
|
||||
fun getFromYTDL(query: String): ArrayList<ResultItemWithFormats?> {
|
||||
fun getFromYTDL(query: String): ArrayList<ResultItem?> {
|
||||
init()
|
||||
items = ArrayList()
|
||||
try {
|
||||
|
|
@ -506,16 +501,14 @@ class InfoUtil(context: Context) {
|
|||
}
|
||||
}
|
||||
Log.e(TAG, formats.toString())
|
||||
items.add(ResultItemWithFormats(
|
||||
ResultItem(0,
|
||||
items.add(ResultItem(0,
|
||||
url,
|
||||
title,
|
||||
author!!,
|
||||
duration,
|
||||
thumb!!,
|
||||
website,
|
||||
playlistTitle!!
|
||||
),
|
||||
playlistTitle!!,
|
||||
formats
|
||||
)
|
||||
)
|
||||
|
|
@ -603,7 +596,7 @@ class InfoUtil(context: Context) {
|
|||
|
||||
class PlaylistTuple internal constructor(
|
||||
var nextPageToken: String,
|
||||
var videos: ArrayList<ResultItemWithFormats?>
|
||||
var videos: ArrayList<ResultItem?>
|
||||
)
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -58,11 +58,7 @@ class DownloadWorker(
|
|||
val downloadLocation = downloadItem.downloadPath
|
||||
|
||||
val tempFolder = StringBuilder(context.cacheDir.absolutePath + """/${downloadItem.title}##${downloadItem.type}""")
|
||||
when(type){
|
||||
"audio" -> tempFolder.append("##${downloadItem.audioFormatId}")
|
||||
"video" -> tempFolder.append("##${downloadItem.videoFormatId}")
|
||||
"command" -> tempFolder.append("##${downloadItem.customTemplateId}")
|
||||
}
|
||||
tempFolder.append("##${downloadItem.format.format_id}")
|
||||
var tempFileDir = File(tempFolder.toString())
|
||||
tempFileDir.delete()
|
||||
tempFileDir.mkdir()
|
||||
|
|
@ -95,7 +91,7 @@ class DownloadWorker(
|
|||
when(type){
|
||||
"audio" -> {
|
||||
request.addOption("-x")
|
||||
var audioQualityId : String = downloadItem.audioFormatId
|
||||
var audioQualityId : String = downloadItem.format.format_id
|
||||
if (audioQualityId == "0") audioQualityId = "ba"
|
||||
var ext = downloadItem.ext
|
||||
request.addOption("-f", audioQualityId)
|
||||
|
|
@ -107,7 +103,7 @@ class DownloadWorker(
|
|||
request.addOption("--embed-thumbnail")
|
||||
request.addOption("--convert-thumbnails", "png")
|
||||
try {
|
||||
val config = File(context.cacheDir, "config" + downloadItem.title + "##" + downloadItem.audioFormatId + ".txt")
|
||||
val config = File(context.cacheDir, "config" + downloadItem.title + "##" + downloadItem.format.format_id + ".txt")
|
||||
val configData =
|
||||
"--ppa \"ffmpeg: -c:v png -vf crop=\\\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\\\"\""
|
||||
config.writeText(configData)
|
||||
|
|
@ -139,11 +135,10 @@ class DownloadWorker(
|
|||
if (embedSubs) {
|
||||
request.addOption("--embed-subs", "")
|
||||
}
|
||||
var videoFormatID = downloadItem.videoFormatId
|
||||
val audioFormatID = downloadItem.audioFormatId
|
||||
var videoFormatID = downloadItem.format.format_id
|
||||
if (videoFormatID.isEmpty()) videoFormatID = "bestvideo"
|
||||
val formatArgument = StringBuilder(videoFormatID)
|
||||
if (audioFormatID != "0") formatArgument.append("+", audioFormatID, "/best")
|
||||
formatArgument.append("+bestaudio/best")
|
||||
request.addOption("-f", formatArgument.toString())
|
||||
var format = downloadItem.ext
|
||||
if (format.isNotEmpty()) {
|
||||
|
|
@ -161,7 +156,7 @@ class DownloadWorker(
|
|||
}
|
||||
"command" -> {
|
||||
val commandRegex = "\"([^\"]*)\"|(\\S+)"
|
||||
val command = commandTemplateDao.getTemplate(downloadItem.customTemplateId)
|
||||
val command = commandTemplateDao.getTemplate(downloadItem.format.format_id.toLong())
|
||||
val m = Pattern.compile(commandRegex).matcher(command.content)
|
||||
while (m.find()) {
|
||||
if (m.group(1) != null) {
|
||||
|
|
@ -192,7 +187,7 @@ class DownloadWorker(
|
|||
val incognito = sharedPreferences.getBoolean("incognito", false)
|
||||
if (!incognito) {
|
||||
val unixtime = System.currentTimeMillis() / 1000
|
||||
val historyItem = HistoryItem(0, downloadItem.url, downloadItem.title, downloadItem.author, downloadItem.duration, downloadItem.thumb, downloadItem.type, unixtime, downloadItem.downloadPath, downloadItem.website)
|
||||
val historyItem = HistoryItem(0, downloadItem.url, downloadItem.title, downloadItem.author, downloadItem.duration, downloadItem.thumb, downloadItem.type, unixtime, downloadItem.downloadPath, downloadItem.website, downloadItem.format)
|
||||
runBlocking {
|
||||
historyDao.insert(historyItem)
|
||||
}
|
||||
|
|
|
|||
36
app/src/main/res/xml/data_extraction_rules.xml
Normal file
36
app/src/main/res/xml/data_extraction_rules.xml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Sample data extraction rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
|
||||
for details.
|
||||
-->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<!--
|
||||
TODO: Use <include> and <exclude> to control what is backed up.
|
||||
The domain can be file, database, sharedpref, external or root.
|
||||
Examples:
|
||||
|
||||
<include domain="file" path="file_to_include"/>
|
||||
<exclude domain="file" path="file_to_exclude"/>
|
||||
<include domain="file" path="include_folder"/>
|
||||
<exclude domain="file" path="include_folder/file_to_exclude"/>
|
||||
<exclude domain="file" path="exclude_folder"/>
|
||||
<include domain="file" path="exclude_folder/file_to_include"/>
|
||||
|
||||
<include domain="sharedpref" path="include_shared_pref1.xml"/>
|
||||
<include domain="database" path="db_name/file_to_include"/>
|
||||
<exclude domain="database" path="db_name/include_folder/file_to_exclude"/>
|
||||
<include domain="external" path="file_to_include"/>
|
||||
<exclude domain="external" path="file_to_exclude"/>
|
||||
<include domain="root" path="file_to_include"/>
|
||||
<exclude domain="root" path="file_to_exclude"/>
|
||||
-->
|
||||
</cloud-backup>
|
||||
<!--
|
||||
<device-transfer>
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
</device-transfer>
|
||||
-->
|
||||
</data-extraction-rules>
|
||||
|
|
@ -23,8 +23,8 @@ buildscript {
|
|||
commonsCompressVer = '1.12'
|
||||
youtubedlAndroidVer = "a3b971724d"
|
||||
workVer = "2.7.1"
|
||||
composeVer = "1.3.2"
|
||||
kotlinVer = "1.7.20"
|
||||
composeVer = "1.4.0-alpha02"
|
||||
kotlinVer = "1.7.21"
|
||||
coroutineVer = "1.6.4"
|
||||
retrofitVer = "2.9.0"
|
||||
kodeinVer = "7.16.0"
|
||||
|
|
@ -33,12 +33,13 @@ buildscript {
|
|||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.android.application' version '7.4.0' apply false
|
||||
id 'com.android.library' version '7.4.0' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.7.21' apply false
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ pluginManagement {
|
|||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven { url 'https://jitpack.io' }
|
||||
maven { url "https://dl.bintray.com/kodein-framework/Kodein-DI" }
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
|
|
|
|||
Loading…
Reference in a new issue