fixed audio downloads
This commit is contained in:
parent
544a8eab14
commit
c653edb387
7 changed files with 22 additions and 33 deletions
|
|
@ -112,7 +112,6 @@ class HistoryAdapter(onItemClickListener: OnItemClickListener, activity: Activit
|
|||
//IS IN THE FILE SYSTEM?
|
||||
val path = item.downloadPath
|
||||
val file = File(path)
|
||||
Log.e("aa", file.absolutePath + " " + file.isFile)
|
||||
if (!file.exists() && path.isNotEmpty()) {
|
||||
filePresent = false
|
||||
thumbnail.colorFilter = ColorMatrixColorFilter(object : ColorMatrix() {
|
||||
|
|
|
|||
|
|
@ -72,17 +72,18 @@ class ResultRepository(private val resultDao: ResultDao, private val commandTemp
|
|||
var nextPageToken = ""
|
||||
if (resetResults) deleteAll()
|
||||
val infoUtil = InfoUtil(context)
|
||||
val items : ArrayList<ResultItem?> = arrayListOf()
|
||||
do {
|
||||
val tmp = infoUtil.getPlaylist(query, nextPageToken)
|
||||
val tmpVids = tmp.videos
|
||||
items.addAll(tmp.videos)
|
||||
val tmpToken = tmp.nextPageToken
|
||||
tmpVids.forEach {
|
||||
resultDao.insert(it!!)
|
||||
}
|
||||
if (tmpToken.isEmpty()) break
|
||||
if (tmpToken == nextPageToken) break
|
||||
nextPageToken = tmpToken
|
||||
} while (true)
|
||||
items.forEach {
|
||||
resultDao.insert(it!!)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getDefault(inputQuery: String, resetResults: Boolean){
|
||||
|
|
@ -114,5 +115,4 @@ class ResultRepository(private val resultDao: ResultDao, private val commandTemp
|
|||
fun getItemByURL(url: String): ResultItem {
|
||||
return resultDao.getResultByURL(url)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -61,16 +61,17 @@ class ResultViewModel(application: Application) : AndroidViewModel(application)
|
|||
try {
|
||||
when (type) {
|
||||
"Search" -> {
|
||||
repository.search(inputQuery, resetResults);
|
||||
repository.search(inputQuery, resetResults)
|
||||
}
|
||||
"Video" -> {
|
||||
repository.getOne(inputQuery, resetResults);
|
||||
repository.getOne(inputQuery, resetResults)
|
||||
}
|
||||
"Playlist" -> {
|
||||
repository.getPlaylist(inputQuery, resetResults);
|
||||
repository.getPlaylist(inputQuery, resetResults)
|
||||
|
||||
}
|
||||
"Default" -> {
|
||||
repository.getDefault(inputQuery, resetResults);
|
||||
repository.getDefault(inputQuery, resetResults)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
|
@ -93,8 +94,6 @@ class ResultViewModel(application: Application) : AndroidViewModel(application)
|
|||
repository.update(item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun getItemByURL(url: String) : ResultItem {
|
||||
return repository.getItemByURL(url)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,9 +96,6 @@ class DownloadAudioFragment(private val downloadItem: DownloadItem) : Fragment()
|
|||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
|
||||
override fun afterTextChanged(p0: Editable?) {
|
||||
downloadItem.title = p0.toString()
|
||||
resultItem.title = p0.toString()
|
||||
//resultViewModel.update(resultItem)
|
||||
//downloadViewModel.updateDownload(downloadItem)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -109,9 +106,6 @@ class DownloadAudioFragment(private val downloadItem: DownloadItem) : Fragment()
|
|||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
|
||||
override fun afterTextChanged(p0: Editable?) {
|
||||
downloadItem.author = p0.toString()
|
||||
resultItem.author = p0.toString()
|
||||
//resultViewModel.update(resultItem)
|
||||
//downloadViewModel.updateDownload(downloadItem)
|
||||
}
|
||||
})
|
||||
saveDir = view.findViewById(R.id.outputPath)
|
||||
|
|
@ -169,7 +163,6 @@ class DownloadAudioFragment(private val downloadItem: DownloadItem) : Fragment()
|
|||
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, index: Int, _: Long ->
|
||||
downloadItem.format.format_note = formats[index].format_note
|
||||
downloadItem.format.format_id = formats[index].format_id
|
||||
//downloadViewModel.updateDownload(downloadItem)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -188,14 +181,13 @@ class DownloadAudioFragment(private val downloadItem: DownloadItem) : Fragment()
|
|||
)
|
||||
val selectedContainer: String = formats.find { downloadItem.format.format_note == it.format_note }?.container
|
||||
?: sharedPreferences.getString("audio_format", "mp3")!!
|
||||
downloadItem.format.container = selectedContainer
|
||||
containerAutoCompleteTextView!!.setText(selectedContainer, false)
|
||||
(container!!.editText as AutoCompleteTextView?)!!.onItemClickListener =
|
||||
AdapterView.OnItemClickListener { _: AdapterView<*>?, _: View?, index: Int, _: Long ->
|
||||
downloadItem.format.container = containers[index]
|
||||
//downloadViewModel.updateDownload(downloadItem)
|
||||
}
|
||||
|
||||
//downloadViewModel.updateDownload(downloadItem)
|
||||
}catch (e : Exception){
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class FileUtil() {
|
|||
return formattedPath.toString()
|
||||
}
|
||||
|
||||
fun scanMedia(destDir: String, context: Context) : String {
|
||||
private fun scanMedia(destDir: String, context: Context) : String {
|
||||
val files = ArrayList<File>()
|
||||
val path = File(formatPath(destDir))
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ class FileUtil() {
|
|||
|
||||
return context.getString(R.string.unfound_file);
|
||||
}
|
||||
fun moveFile(originDir: File, context: Context, destDir: String, progress: (p: Int) -> Unit){
|
||||
fun moveFile(originDir: File, context: Context, destDir: String, progress: (p: Int) -> Unit) : String {
|
||||
originDir.listFiles()?.forEach {
|
||||
if (it.name.equals("rList")){
|
||||
it.delete()
|
||||
|
|
@ -131,7 +131,7 @@ class FileUtil() {
|
|||
}
|
||||
}
|
||||
originDir.delete()
|
||||
scanMedia(destDir, context)
|
||||
return scanMedia(destDir, context)
|
||||
}
|
||||
|
||||
fun convertFileSize(s: Long): String{
|
||||
|
|
|
|||
|
|
@ -45,8 +45,9 @@ class InfoUtil(context: Context) {
|
|||
"US"
|
||||
}
|
||||
}
|
||||
if (useInvidous == false){
|
||||
if (!useInvidous){
|
||||
val res = genericRequest(invidousURL + "stats")
|
||||
Log.e("Assa", res.toString())
|
||||
useInvidous = res.length() != 0
|
||||
}
|
||||
}
|
||||
|
|
@ -524,7 +525,6 @@ class InfoUtil(context: Context) {
|
|||
}
|
||||
|
||||
fun getSearchSuggestions(query: String): ArrayList<String> {
|
||||
if (!useInvidous) return ArrayList()
|
||||
val url = invidousURL + "search/suggestions?q=" + query
|
||||
val res = genericRequest(url)
|
||||
if (res.length() == 0) return ArrayList()
|
||||
|
|
|
|||
|
|
@ -94,8 +94,8 @@ class DownloadWorker(
|
|||
"audio" -> {
|
||||
request.addOption("-x")
|
||||
var audioQualityId : String = downloadItem.format.format_id
|
||||
if (audioQualityId == "0") audioQualityId = "ba"
|
||||
var ext = downloadItem.format.container
|
||||
if (audioQualityId == "0" || audioQualityId.isEmpty()) audioQualityId = "ba"
|
||||
val ext = downloadItem.format.container
|
||||
request.addOption("-f", audioQualityId)
|
||||
request.addOption("--audio-format", ext)
|
||||
request.addOption("--embed-metadata")
|
||||
|
|
@ -181,15 +181,13 @@ class DownloadWorker(
|
|||
}.onSuccess {
|
||||
//move file from internal to set download directory
|
||||
|
||||
moveFile(tempFileDir.absoluteFile, downloadLocation){ progress ->
|
||||
val finalPath = moveFile(tempFileDir.absoluteFile, downloadLocation){ progress ->
|
||||
setProgressAsync(workDataOf("progress" to progress))
|
||||
}
|
||||
//put download in history
|
||||
val incognito = sharedPreferences.getBoolean("incognito", false)
|
||||
if (!incognito) {
|
||||
val unixtime = System.currentTimeMillis() / 1000
|
||||
val fileUtil = FileUtil()
|
||||
val finalPath = fileUtil.formatPath(downloadItem.downloadPath) + downloadItem.author + " - " + downloadItem.title + "." + downloadItem.format.container
|
||||
val historyItem = HistoryItem(0, downloadItem.url, downloadItem.title, downloadItem.author, downloadItem.duration, downloadItem.thumb, downloadItem.type, unixtime, finalPath, downloadItem.website, downloadItem.format)
|
||||
runBlocking {
|
||||
historyDao.insert(historyItem)
|
||||
|
|
@ -232,14 +230,15 @@ class DownloadWorker(
|
|||
}
|
||||
|
||||
|
||||
private fun moveFile(originDir: File, downLocation: String, progress: (progress: Int) -> Unit){
|
||||
private fun moveFile(originDir: File, downLocation: String, progress: (progress: Int) -> Unit) : String{
|
||||
val destDir = Uri.parse(downLocation).run {
|
||||
DocumentsContract.buildChildDocumentsUriUsingTree(this, DocumentsContract.getTreeDocumentId(this))
|
||||
}
|
||||
val fileUtil = FileUtil()
|
||||
fileUtil.moveFile(originDir, context, downLocation){ p ->
|
||||
val path = fileUtil.moveFile(originDir, context, downLocation){ p ->
|
||||
progress(p)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
Loading…
Reference in a new issue