Skip to content

Commit

Permalink
Artists with href and v0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
Shabinder committed Jun 7, 2024
1 parent d5f5de7 commit 888bba9
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 33 deletions.
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ afterEvaluate {
if (signingKey.isNullOrBlank() || signingPwd.isNullOrBlank()) {
logger.info("Signing Disable as the PGP key was not found")
} else {
logger.info("Signing Enabled using PGP key")
//region Fix Gradle warning about signing tasks using publishing task outputs without explicit dependencies
// https://github.com/gradle/gradle/issues/26091
val signingTasks = tasks.withType<Sign>()
tasks.withType<AbstractPublishToMaven>().configureEach {
mustRunAfter(signingTasks)
}

signing {
useInMemoryPgpKeys(signingKey, signingPwd)
sign(publishing.publications)
Expand Down
12 changes: 6 additions & 6 deletions gradle/deps.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mviKotlin = "3.3.0"
accompanist = "0.34.0"
statelyVersion = "2.0.7"
statelyIsoVersion = "2.0.0-rc1"
androidxLifecycle = "2.8.0"
androidxLifecycle = "2.8.1"
androidxMedia3 = "1.3.1"
okio = "3.9.0"
arrow = "1.2.4"
Expand All @@ -32,7 +32,7 @@ nexusGradle = "2.0.0"
zipline = "1.10.0-LEGACY"

[libraries]
soundbound-extensions-lib = { group = "io.github.shabinder", name = "soundbound-extensions-lib", version = "0.14" }
soundbound-extensions-lib = { group = "io.github.shabinder", name = "soundbound-extensions-lib", version = "0.15" }
soundbound-compose = { group = "io.github.shabinder", name = "compose", version = "1.0.0" }

clarity = { group = "com.microsoft.clarity", name = "clarity", version = "1.3.3" }
Expand Down Expand Up @@ -169,10 +169,10 @@ junit = { group = "junit", name = "junit", version = "4.13.2" }
ktlint-gradle = { group = "org.jlleitschuh.gradle", name = "ktlint-gradle", version.ref = "ktLint" }
konnection = { group = "dev.tmapps", name = "konnection", version.ref = "konnection" }

zipline = { module = "app.cash.zipline:zipline", version.ref = "zipline" }
zipline-gradlePlugin = { module = "app.cash.zipline:zipline-gradle-plugin", version.ref = "zipline" }
zipline-loader = { module = "app.cash.zipline:zipline-loader", version.ref = "zipline" }
zipline-profiler = { module = "app.cash.zipline:zipline-profiler", version.ref = "zipline" }
zipline = { module = "io.github.shabinder:zipline", version.ref = "zipline" }
zipline-gradlePlugin = { module = "io.github.shabinder:zipline-gradle-plugin", version.ref = "zipline" }
zipline-loader = { module = "io.github.shabinder:zipline-loader", version.ref = "zipline" }
zipline-profiler = { module = "io.github.shabinder:zipline-profiler", version.ref = "zipline" }

publishing-nexus-gradle = { group = "io.github.gradle-nexus", name = "publish-plugin", version.ref = "nexusGradle" }

Expand Down
35 changes: 22 additions & 13 deletions src/commonMain/kotlin/in.shabinder.soundbound/matcher/Matching.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package `in`.shabinder.soundbound.matcher

import `in`.shabinder.soundbound.models.Artist
import `in`.shabinder.soundbound.zipline.FuzzySearch
import kotlin.math.absoluteValue
import kotlin.math.max
import kotlin.math.min

interface MatchProps {
val title: String
val artists: List<String>
val artists: List<Artist>
val albumName: String?
val durationSec: Long
val isrc: String?
Expand Down Expand Up @@ -160,23 +161,26 @@ fun getNameMatch(matchTitle: String, matchForTitle: String, searcher: FuzzySearc
}

fun getAllArtistsMatch(
matchArtists: List<String>,
matchForArtists: List<String>,
matchArtists: List<Artist>,
matchForArtists: List<Artist>,
searcher: FuzzySearch
): Float {
val matchArtistsName = matchArtists.map(Artist::name)
val matchForArtistsName = matchForArtists.map(Artist::name)

var artistMatch = 0.0f

if (matchForArtists.size == 1) return artistMatch
if (matchForArtistsName.size == 1) return artistMatch

var matchArtistsSlugged =
(matchArtists.takeIf { it.size > 1 } ?: matchArtists.first().split(",").map(String::trim))
(matchArtistsName.takeIf { it.size > 1 } ?: matchArtistsName.first().split(",").map(String::trim))
.asSequence()
.filter { it.isNotBlank() }.toSet().sorted()
.map(String::sluggify).filter { it.isNotBlank() }
.toList()

val matchForArtistsSlugged =
matchForArtists.asSequence()
matchForArtistsName.asSequence()
.filter { it.isNotBlank() }.toSet().sorted()
.map(String::sluggify).filter { it.isNotBlank() }
.toList()
Expand All @@ -198,20 +202,23 @@ fun getAllArtistsMatch(
}

fun getMainArtistMatch(
matchArtists: List<String>,
matchForArtists: List<String>,
matchArtists: List<Artist>,
matchForArtists: List<Artist>,
searcher: FuzzySearch
): Float {
val matchArtistsName = matchArtists.map(Artist::name)
val matchForArtistsName = matchForArtists.map(Artist::name)

var mainArtistMatch: Float = 0f

val matchArtistsSlugged =
matchArtists.asSequence()
matchArtistsName.asSequence()
.filter { it.isNotBlank() }.toSet()//.sorted()
.map(String::sluggify).filter { it.isNotBlank() }
.toList()

val matchForArtistsSlugged =
matchForArtists.asSequence()
matchForArtistsName.asSequence()
.filter { it.isNotBlank() }.toSet()//.sorted()
.map(String::sluggify).filter { it.isNotBlank() }
.toList()
Expand Down Expand Up @@ -277,7 +284,9 @@ fun checkCommonWord(string1: String, string2: String): Boolean {
}

private fun <T : MatchProps> T.sluggedArtists(): List<String> {
return artists.map(String::sluggify).takeIf { it.size > 1 }
?: artists.firstOrNull()?.split("-")?.map(String::sluggify)
?: artists
val artistsNames = artists.map(Artist::name)

return artistsNames.map(String::sluggify).takeIf { it.size > 1 }
?: artistsNames.firstOrNull()?.split("-")?.map(String::sluggify)
?: artistsNames
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package `in`.shabinder.soundbound.matcher

import `in`.shabinder.soundbound.models.Artist
import `in`.shabinder.soundbound.models.QueryParams
import `in`.shabinder.soundbound.zipline.FuzzySearch

Expand All @@ -20,7 +21,7 @@ fun QueryParams.asMatchProps(): MatchProps {
val queryParams = this
return object : MatchProps {
override val title: String = queryParams.trackName
override val artists: List<String> = queryParams.trackArtists
override val artists: List<Artist> = queryParams.trackArtists
override val albumName: String? = queryParams.albumName
override val durationSec: Long = queryParams.trackDurationSec
override val isrc: String? = queryParams.isrc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package `in`.shabinder.soundbound.matcher

import androidx.compose.runtime.Immutable
import `in`.shabinder.soundbound.models.Artist
import `in`.shabinder.soundbound.models.SongModel
import `in`.shabinder.soundbound.zipline.FuzzySearch

Expand All @@ -25,7 +26,7 @@ fun SongModel.asMatchProps(): MatchProps {
val song = this
return object : MatchProps {
override val title: String = song.title
override val artists: List<String> = song.artists
override val artists: List<Artist> = song.artists
override val albumName: String? = song.albumName
override val durationSec: Long = song.durationSec
override val isrc: String? = song.isrc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import `in`.shabinder.soundbound.utils.cleaned
import kotlinx.serialization.Serializable
import kotlin.jvm.JvmOverloads

typealias Creator = Artist

@Immutable
@Serializable
Expand All @@ -33,7 +34,7 @@ open class PlatformQueryResult(
open val trackList: List<SongModel>,
open val source: SourceModel,
open val description: String = "",
open val creators: List<String> = emptyList(),
open val creators: List<Creator> = emptyList(),
) {
@JvmOverloads
open fun copy(
Expand All @@ -43,7 +44,7 @@ open class PlatformQueryResult(
trackList: List<SongModel> = this.trackList,
source: SourceModel = this.source,
description: String = this.description,
creators: List<String> = this.creators,
creators: List<Creator> = this.creators,
): PlatformQueryResult {
return PlatformQueryResult(
title = title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ sealed class ProviderExceptions(
data class NoInternetException(
val extraInfo: String? = null,
) : ProviderExceptions("Check your Internet Connectivity.", extraInfo)

@Immutable
@Serializable
data class UnknownException(
val extraInfo: String? = null,
) : ProviderExceptions("Unknown Exception Occurred.", extraInfo)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import kotlinx.serialization.Serializable
@Serializable
open class QueryParams(
open val trackName: String,
open val trackArtists: List<String> = emptyList(),
open val trackArtists: List<Artist> = emptyList(),
open val trackDurationSec: Long,
open val genre: List<String> = emptyList(),
open val year: Int? = null,
open val albumName: String? = null,
open val albumArtists: List<String> = emptyList(),
open val albumArtists: List<Artist> = emptyList(),
open val trackLink: String? = null,
open val interestedEntityType: SearchItem.Type = SearchItem.Type.All,
open val isrc: String? = null,
Expand All @@ -26,12 +26,12 @@ open class QueryParams(
@kotlin.jvm.JvmOverloads
open fun copy(
trackName: String = this.trackName,
trackArtists: List<String> = this.trackArtists,
trackArtists: List<Artist> = this.trackArtists,
trackDurationSec: Long = this.trackDurationSec,
genre: List<String> = this.genre,
year: Int? = this.year,
albumName: String? = this.albumName,
albumArtists: List<String> = this.albumArtists,
albumArtists: List<Artist> = this.albumArtists,
trackLink: String? = this.trackLink,
interestedEntityType: SearchItem.Type = this.interestedEntityType,
isrc: String? = this.isrc,
Expand Down Expand Up @@ -90,7 +90,7 @@ open class QueryParams(

val simpleQuery: String
get() {
if (trackArtists.isEmpty() || trackArtists.all { it.isBlank() }) {
if (trackArtists.isEmpty() || trackArtists.all { it.name.isBlank() }) {
return trackName
}

Expand Down
22 changes: 17 additions & 5 deletions src/commonMain/kotlin/in.shabinder.soundbound/models/SongModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package `in`.shabinder.soundbound.models

import androidx.compose.runtime.Immutable
import `in`.shabinder.soundbound.matcher.sluggify
import `in`.shabinder.soundbound.utils.cleaned
import kotlinx.serialization.Serializable
import kotlin.jvm.JvmOverloads
Expand All @@ -29,12 +30,12 @@ open class SongModel(
open val title: String,
open val durationSec: Long,
open val year: Int,
open val artists: List<String>,
open val artists: List<Artist>,
open val genre: List<String>,
open val source: SourceModel,
open val videoID: String?,
open val albumName: String?,
open val albumArtists: List<String>,
open val albumArtists: List<Artist>,
open val trackNumber: Long?,
open val comment: String?,
open val trackURL: String,
Expand All @@ -55,12 +56,12 @@ open class SongModel(
title: String = this.title,
durationSec: Long = this.durationSec,
year: Int = this.year,
artists: List<String> = this.artists,
artists: List<Artist> = this.artists,
genre: List<String> = this.genre,
source: SourceModel = this.source,
videoID: String? = this.videoID,
albumName: String? = this.albumName,
albumArtists: List<String> = this.albumArtists,
albumArtists: List<Artist> = this.albumArtists,
trackNumber: Long? = this.trackNumber,
comment: String? = this.comment,
trackURL: String = this.trackURL,
Expand Down Expand Up @@ -173,4 +174,15 @@ open class SongModel(
override fun toString(): String {
return "SongModel(id=$id, title=$title, durationSec=$durationSec, year=$year, artists=$artists, genre=$genre, source=$source, videoID=$videoID, albumName=$albumName, albumArtists=$albumArtists, trackNumber=$trackNumber, comment=$comment, trackURL=$trackURL, albumArtURL=$albumArtURL, downloadLinks=$downloadLinks, audioQuality=$audioQuality, audioFormat=$audioFormat, downloaded=$downloaded, isFavourite=$isFavourite, isrc=$isrc, extraProps=$extraProps, lyrics=$lyrics)"
}
}
}

@Immutable
@Serializable
data class Artist(
val name: String,
val href: List<String>? = null
)

fun Artist.isNotBlank() = name.isNotBlank()
fun Artist.isEmpty() = name.isEmpty()
fun Artist.sluggify() = name.sluggify()
8 changes: 8 additions & 0 deletions src/commonMain/kotlin/in.shabinder.soundbound/utils/Ext.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package `in`.shabinder.soundbound.utils

import `in`.shabinder.soundbound.models.Artist
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlin.jvm.JvmName
import kotlin.math.min


Expand All @@ -10,6 +12,12 @@ internal inline fun List<String>.cleaned(): List<String> {
return this.filter { it.isNotBlank() && it != "null" }
}

@Suppress("NOTHING_TO_INLINE")
@JvmName("cleanedArtists")
internal inline fun List<Artist>.cleaned(): List<Artist> {
return filter { it.name.isNotBlank() && it.name != "null" }
}

fun <T> T.limitDecimals(maxDecimals: Int): String {
val result = toString()
val lastIndex = result.length - 1
Expand Down

0 comments on commit 888bba9

Please sign in to comment.