fix(all/googledrive): fix file sizes (#1829)
This commit is contained in:
@ -6,7 +6,7 @@ ext {
|
||||
extName = 'Google Drive'
|
||||
pkgNameSuffix = 'all.googledrive'
|
||||
extClass = '.GoogleDrive'
|
||||
extVersionCode = 5
|
||||
extVersionCode = 6
|
||||
libVersion = '13'
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ class GoogleDrive : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
if (parsed.items == null) throw Exception("Failed to load items, please log in through webview")
|
||||
parsed.items.forEachIndexed { index, it ->
|
||||
if (it.mimeType.startsWith("video")) {
|
||||
val size = formatBytes(it.fileSize?.toLongOrNull())
|
||||
val size = it.fileSize?.toLongOrNull()?.let { formatBytes(it) } ?: ""
|
||||
val itemNumberRegex = """ - (?:S\d+E)?(\d+)""".toRegex()
|
||||
val pathName = if (preferences.trimEpisodeInfo) path.trimInfo() else path
|
||||
|
||||
@ -492,7 +492,7 @@ class GoogleDrive : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
url = LinkData(
|
||||
"https://drive.google.com/uc?id=${it.id}",
|
||||
"single",
|
||||
LinkDataInfo(it.title, formatBytes(it.fileSize?.toLongOrNull()) ?: ""),
|
||||
LinkDataInfo(it.title, it.fileSize?.toLongOrNull()?.let { formatBytes(it) } ?: ""),
|
||||
).toJsonString()
|
||||
thumbnail_url = ""
|
||||
},
|
||||
@ -541,15 +541,15 @@ class GoogleDrive : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
return newString.trim()
|
||||
}
|
||||
|
||||
private fun formatBytes(bytes: Long?): String? {
|
||||
val units = arrayOf("B", "KB", "MB", "GB", "TB", "PB", "EB")
|
||||
var value = bytes?.toDouble() ?: return null
|
||||
var i = 0
|
||||
while (value >= 1024 && i < units.size - 1) {
|
||||
value /= 1024
|
||||
i++
|
||||
private fun formatBytes(bytes: Long): String {
|
||||
return when {
|
||||
bytes >= 1_000_000_000 -> "%.2f GB".format(bytes / 1_000_000_000.0)
|
||||
bytes >= 1_000_000 -> "%.2f MB".format(bytes / 1_000_000.0)
|
||||
bytes >= 1_000 -> "%.2f KB".format(bytes / 1_000.0)
|
||||
bytes > 1 -> "$bytes bytes"
|
||||
bytes == 1L -> "$bytes byte"
|
||||
else -> ""
|
||||
}
|
||||
return String.format("%.1f %s", value, units[i])
|
||||
}
|
||||
|
||||
private fun getCookie(url: String): String {
|
||||
|
Reference in New Issue
Block a user