diff --git a/src/all/googledrive/build.gradle b/src/all/googledrive/build.gradle index d5df5f1ca..557592b61 100644 --- a/src/all/googledrive/build.gradle +++ b/src/all/googledrive/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Google Drive' pkgNameSuffix = 'all.googledrive' extClass = '.GoogleDrive' - extVersionCode = 5 + extVersionCode = 6 libVersion = '13' } diff --git a/src/all/googledrive/src/eu/kanade/tachiyomi/animeextension/all/googledrive/GoogleDrive.kt b/src/all/googledrive/src/eu/kanade/tachiyomi/animeextension/all/googledrive/GoogleDrive.kt index 16dcd8017..aae794b7f 100644 --- a/src/all/googledrive/src/eu/kanade/tachiyomi/animeextension/all/googledrive/GoogleDrive.kt +++ b/src/all/googledrive/src/eu/kanade/tachiyomi/animeextension/all/googledrive/GoogleDrive.kt @@ -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 {