LANraragi: Safer tag parsing. (#5490)

It was possible to get a null into the function and the following split() did not like it.
This commit is contained in:
RePod 2021-01-19 17:42:23 -05:00 committed by GitHub
parent bb884dfee1
commit 19adc29d1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'LANraragi' extName = 'LANraragi'
pkgNameSuffix = 'all.lanraragi' pkgNameSuffix = 'all.lanraragi'
extClass = '.LANraragi' extClass = '.LANraragi'
extVersionCode = 3 extVersionCode = 4
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -430,26 +430,29 @@ open class LANraragi : ConfigurableSource, HttpSource() {
return getTopResponse(response).request().url().queryParameter("start")!!.toInt() return getTopResponse(response).request().url().queryParameter("start")!!.toInt()
} }
private fun getArtist(tags: String): String { private fun getNSTag(tags: String?, tag: String): List<String>? {
tags.split(',').forEach { tags?.split(',')?.forEach {
if (it.contains(':')) { if (it.contains(':')) {
val temp = it.trim().split(':') val temp = it.trim().split(":", limit = 2)
if (temp[0].equals(tag, true)) return temp
if (temp[0].equals("artist", true)) return temp[1]
} }
} }
return null
}
private fun getArtist(tags: String?): String {
getNSTag(tags, "artist")?.let {
return it[1]
}
return "N/A" return "N/A"
} }
private fun getDateAdded(tags: String): String { private fun getDateAdded(tags: String?): String {
tags.split(',').forEach { getNSTag(tags, "date_added")?.let {
if (it.contains(':')) { // Pad Date Added NS to milliseconds
val temp = it.trim().split(':') return it[1].padEnd(13, '0')
// Pad Date Added LRR plugin (or user specified namespace) to milliseconds
if (temp[0].equals(latestNamespacePref, true)) return temp[1].padEnd(13, '0')
}
} }
return "" return ""