mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
refactor: Use Path extensions
This commit is contained in:
parent
9ea7ca3237
commit
c12482d000
@ -3,7 +3,7 @@ package com.github.libretube.api.obj
|
|||||||
import com.github.libretube.db.obj.DownloadItem
|
import com.github.libretube.db.obj.DownloadItem
|
||||||
import com.github.libretube.enums.FileType
|
import com.github.libretube.enums.FileType
|
||||||
import com.github.libretube.helpers.ProxyHelper
|
import com.github.libretube.helpers.ProxyHelper
|
||||||
import java.nio.file.Paths
|
import kotlin.io.path.Path
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -37,7 +37,7 @@ data class PipedStream(
|
|||||||
type = fileType,
|
type = fileType,
|
||||||
videoId = videoId,
|
videoId = videoId,
|
||||||
fileName = getQualityString(fileName),
|
fileName = getQualityString(fileName),
|
||||||
path = Paths.get(""),
|
path = Path(""),
|
||||||
url = url?.let { ProxyHelper.unwrapUrl(it) },
|
url = url?.let { ProxyHelper.unwrapUrl(it) },
|
||||||
format = format,
|
format = format,
|
||||||
quality = quality,
|
quality = quality,
|
||||||
|
@ -4,7 +4,7 @@ import com.github.libretube.db.obj.DownloadItem
|
|||||||
import com.github.libretube.enums.FileType
|
import com.github.libretube.enums.FileType
|
||||||
import com.github.libretube.helpers.ProxyHelper
|
import com.github.libretube.helpers.ProxyHelper
|
||||||
import com.github.libretube.parcelable.DownloadData
|
import com.github.libretube.parcelable.DownloadData
|
||||||
import java.nio.file.Paths
|
import kotlin.io.path.Path
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ data class Streams(
|
|||||||
type = FileType.SUBTITLE,
|
type = FileType.SUBTITLE,
|
||||||
videoId = id,
|
videoId = id,
|
||||||
fileName = "${name}_$subCode.srt",
|
fileName = "${name}_$subCode.srt",
|
||||||
path = Paths.get(""),
|
path = Path(""),
|
||||||
url = subtitles.find {
|
url = subtitles.find {
|
||||||
it.code == subCode
|
it.code == subCode
|
||||||
}?.url?.let { ProxyHelper.unwrapUrl(it) }
|
}?.url?.let { ProxyHelper.unwrapUrl(it) }
|
||||||
|
@ -3,7 +3,7 @@ package com.github.libretube.db
|
|||||||
import androidx.room.TypeConverter
|
import androidx.room.TypeConverter
|
||||||
import com.github.libretube.api.JsonHelper
|
import com.github.libretube.api.JsonHelper
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import kotlin.io.path.Path
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import kotlinx.datetime.toLocalDate
|
import kotlinx.datetime.toLocalDate
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
@ -19,7 +19,7 @@ object Converters {
|
|||||||
fun pathToString(path: Path?) = path?.toString()
|
fun pathToString(path: Path?) = path?.toString()
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun stringToPath(string: String?) = string?.let { Paths.get(it) }
|
fun stringToPath(string: String?) = string?.let { Path(it) }
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun stringListToJson(value: List<String>) = JsonHelper.json.encodeToString(value)
|
fun stringListToJson(value: List<String>) = JsonHelper.json.encodeToString(value)
|
||||||
|
@ -11,6 +11,7 @@ import com.github.libretube.parcelable.DownloadData
|
|||||||
import com.github.libretube.services.DownloadService
|
import com.github.libretube.services.DownloadService
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.createDirectories
|
import kotlin.io.path.createDirectories
|
||||||
|
import kotlin.io.path.div
|
||||||
|
|
||||||
object DownloadHelper {
|
object DownloadHelper {
|
||||||
const val VIDEO_DIR = "video"
|
const val VIDEO_DIR = "video"
|
||||||
@ -32,7 +33,7 @@ object DownloadHelper {
|
|||||||
context.filesDir
|
context.filesDir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return storageDir.toPath().resolve(path).createDirectories()
|
return (storageDir.toPath() / path).createDirectories()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMaxConcurrentDownloads(): Int {
|
fun getMaxConcurrentDownloads(): Int {
|
||||||
|
@ -50,6 +50,7 @@ import java.util.concurrent.Executors
|
|||||||
import kotlin.io.path.absolute
|
import kotlin.io.path.absolute
|
||||||
import kotlin.io.path.createFile
|
import kotlin.io.path.createFile
|
||||||
import kotlin.io.path.deleteIfExists
|
import kotlin.io.path.deleteIfExists
|
||||||
|
import kotlin.io.path.div
|
||||||
import kotlin.io.path.fileSize
|
import kotlin.io.path.fileSize
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
@ -501,7 +502,7 @@ class DownloadService : LifecycleService() {
|
|||||||
* Get a [File] from the corresponding download directory and the file name
|
* Get a [File] from the corresponding download directory and the file name
|
||||||
*/
|
*/
|
||||||
private fun getDownloadPath(directory: String, fileName: String): Path {
|
private fun getDownloadPath(directory: String, fileName: String): Path {
|
||||||
return DownloadHelper.getDownloadDir(this, directory).resolve(fileName).absolute()
|
return DownloadHelper.getDownloadDir(this, directory) / fileName
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user