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